Getting ethernet dest hw_addr

2005-03-17 Thread Weber Matthias
Hi,

i want to write a packet handler for redirecting ethernet packets from an input 
device to an output device. actually my problem is to get the dest hw addr from 
the computer physically connected to mine.
the only way seems to restrict on ip packets since it seems that routing and 
arp needs to be used. so i tried to use ip_route_output_key which fills 
skb->dst. Unfortunately i don't have any idea how to get the needed addr from 
there. Below is a piece of code showing what i want to do.

Can anyone help me, please?
The favorite way would be to get the addr without limiting to ip...

Thanks and bye
Matthias

static int ip_rcv(struct sk_buff *skb, struct net_device *dev, struct 
packet_type *pt) {
struct sk_buff *o_skb = skb_clone(skb, GFP_ATOMIC);
struct iphdr *iph = o_skb->nh.iph;
struct tcphdr *th = (struct tcphdr *) ((char *) o_skb->h.th + (iph->ihl << 
2));

//prevent OS for handling packet
skb->pkt_type = PACKET_OTHERHOST;

if (iph->saddr == ext_addr) { //out->in
//modify header
iph->saddr = gw_int_addr;
iph->daddr = int_addr;
o_skb->dev = devs[2];
} else if (iph->saddr == int_addr) { //in->out
//modify header
iph->saddr = gw_ext_addr;
iph->daddr = ext_addr;
o_skb->dev = devs[1];
} else {
return 0;
}

//route packet
struct flowi flow = { 
.nl_u = { 
.ip4_u = {
.saddr = iph->saddr,
.daddr = iph->daddr,
.tos = RT_TOS(iph->tos) 
} 
},
.proto = iph->protocol
};
struct rtable *rt;
ip_route_output_key(, );
o_skb->dst = &(rt->u.dst);

//ip checksum
...works

//broadcast paket to dev -> no dest ethernet addr needed
o_skb->dev->hard_header(
o_skb,
o_skb->dev,
ntohs(o_skb->protocol),
o_skb->dst->neighbour->ha,  //destination hw addr needed - seems to be 
wrong!
o_skb->dev->dev_addr,
o_skb->len
);

//send packet
o_skb->pkt_type = PACKET_OUTGOING;
dev_queue_xmit(o_skb);

kfree_skb(o_skb);

return 0;
}
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Getting ethernet dest hw_addr

2005-03-17 Thread Weber Matthias
Hi,

i want to write a packet handler for redirecting ethernet packets from an input 
device to an output device. actually my problem is to get the dest hw addr from 
the computer physically connected to mine.
the only way seems to restrict on ip packets since it seems that routing and 
arp needs to be used. so i tried to use ip_route_output_key which fills 
skb-dst. Unfortunately i don't have any idea how to get the needed addr from 
there. Below is a piece of code showing what i want to do.

Can anyone help me, please?
The favorite way would be to get the addr without limiting to ip...

Thanks and bye
Matthias

static int ip_rcv(struct sk_buff *skb, struct net_device *dev, struct 
packet_type *pt) {
struct sk_buff *o_skb = skb_clone(skb, GFP_ATOMIC);
struct iphdr *iph = o_skb-nh.iph;
struct tcphdr *th = (struct tcphdr *) ((char *) o_skb-h.th + (iph-ihl  
2));

//prevent OS for handling packet
skb-pkt_type = PACKET_OTHERHOST;

if (iph-saddr == ext_addr) { //out-in
//modify header
iph-saddr = gw_int_addr;
iph-daddr = int_addr;
o_skb-dev = devs[2];
} else if (iph-saddr == int_addr) { //in-out
//modify header
iph-saddr = gw_ext_addr;
iph-daddr = ext_addr;
o_skb-dev = devs[1];
} else {
return 0;
}

//route packet
struct flowi flow = { 
.nl_u = { 
.ip4_u = {
.saddr = iph-saddr,
.daddr = iph-daddr,
.tos = RT_TOS(iph-tos) 
} 
},
.proto = iph-protocol
};
struct rtable *rt;
ip_route_output_key(rt, flow);
o_skb-dst = (rt-u.dst);

//ip checksum
...works

//broadcast paket to dev - no dest ethernet addr needed
o_skb-dev-hard_header(
o_skb,
o_skb-dev,
ntohs(o_skb-protocol),
o_skb-dst-neighbour-ha,  //destination hw addr needed - seems to be 
wrong!
o_skb-dev-dev_addr,
o_skb-len
);

//send packet
o_skb-pkt_type = PACKET_OUTGOING;
dev_queue_xmit(o_skb);

kfree_skb(o_skb);

return 0;
}
-
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Resending ethernet packets to direct neighbours

2005-03-14 Thread Weber Matthias
Hi,

i have a pc with five ethernet devices onto and want to resend ethernet packets 
coming in from one device to four direct neighbours (distance 1). Therefore i 
have installed a packet handler receiving skbs.
Now i have the following questions:
1) is it enough to change the skb->dev to the output device, rebuild the 
ethernet header and call dev_queue_xmit()?
2) how to i get the destination ethernet address of the physically direct 
neighbour within the packet handler? I believe, that i have to use the neighour 
caches but have not idea how...

Any help would be appreciated!


Bye
Matthias

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Resending ethernet packets to direct neighbours

2005-03-14 Thread Weber Matthias
Hi,

i have a pc with five ethernet devices onto and want to resend ethernet packets 
coming in from one device to four direct neighbours (distance 1). Therefore i 
have installed a packet handler receiving skbs.
Now i have the following questions:
1) is it enough to change the skb-dev to the output device, rebuild the 
ethernet header and call dev_queue_xmit()?
2) how to i get the destination ethernet address of the physically direct 
neighbour within the packet handler? I believe, that i have to use the neighour 
caches but have not idea how...

Any help would be appreciated!


Bye
Matthias

-
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


RE: Writing data > PAGESIZE into kernel with proc fs

2005-03-09 Thread Weber Matthias
On Tue, Mar 08, 2005 at 20:05:42 +0100, Weber Matthias wrote:
>> is there any chance to signal an EOF when writing data to kernel via proc 
>> fs? >> Actually if the length of data is N*PAGE_SIZE it seems not to be 
>> detectable. 
>> I followed up the "struct file" but haven't found anything that helped...

> End-of-file is signified by closing the file. As usual.

Having only this struct describing an proc entry, i have no idea on how to 
detect when the file is closed. For this i expect to register a callback 
function but where and how?

struct proc_dir_entry {
unsigned int low_ino;
unsigned short namelen;
const char *name;
mode_t mode;
nlink_t nlink;
uid_t uid;
gid_t gid;
unsigned long size;
struct inode_operations * proc_iops;
struct file_operations * proc_fops;
get_info_t *get_info;
struct module *owner;
struct proc_dir_entry *next, *parent, *subdir;
void *data;
read_proc_t *read_proc;
write_proc_t *write_proc;
atomic_t count; /* use count */
int deleted;/* delete flag */
};

Thanks,
Matthias
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


RE: Writing data PAGESIZE into kernel with proc fs

2005-03-09 Thread Weber Matthias
On Tue, Mar 08, 2005 at 20:05:42 +0100, Weber Matthias wrote:
 is there any chance to signal an EOF when writing data to kernel via proc 
 fs?  Actually if the length of data is N*PAGE_SIZE it seems not to be 
 detectable. 
 I followed up the struct file but haven't found anything that helped...

 End-of-file is signified by closing the file. As usual.

Having only this struct describing an proc entry, i have no idea on how to 
detect when the file is closed. For this i expect to register a callback 
function but where and how?

struct proc_dir_entry {
unsigned int low_ino;
unsigned short namelen;
const char *name;
mode_t mode;
nlink_t nlink;
uid_t uid;
gid_t gid;
unsigned long size;
struct inode_operations * proc_iops;
struct file_operations * proc_fops;
get_info_t *get_info;
struct module *owner;
struct proc_dir_entry *next, *parent, *subdir;
void *data;
read_proc_t *read_proc;
write_proc_t *write_proc;
atomic_t count; /* use count */
int deleted;/* delete flag */
};

Thanks,
Matthias
-
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Writing data > PAGESIZE into kernel with proc fs

2005-03-08 Thread Weber Matthias
Hi,

is there any chance to signal an EOF when writing data to kernel via proc fs? 
Actually if the length of data is N*PAGE_SIZE it seems not to be detectable. I 
followed up the "struct file" but haven't found anything that helped...

Any help would be appreciated!

Bye
Matthias

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Writing data PAGESIZE into kernel with proc fs

2005-03-08 Thread Weber Matthias
Hi,

is there any chance to signal an EOF when writing data to kernel via proc fs? 
Actually if the length of data is N*PAGE_SIZE it seems not to be detectable. I 
followed up the struct file but haven't found anything that helped...

Any help would be appreciated!

Bye
Matthias

-
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/