2003-01-10 01:06:16

by Joshua Stewart

[permalink] [raw]
Subject: Pushing a stray sk_buff to the NIC

I'm trying to take "hand-built" sk_buffs with little more than some data
and a dev member and push them to the NIC for transmission. I would
like to simply give them to dev_queue_xmit. Does anybody know what
state I should have them in before handing them to dev_queue_xmit?
Should skb->data point to the start of a MAC header or an IP header?

Also, given an IP address in skb->nh.iph->daddr, what's the easiest way
to get the appropriate MAC address?

J




2003-01-10 14:25:52

by Rui Sousa

[permalink] [raw]
Subject: Re: Pushing a stray sk_buff to the NIC

On Thu, 9 Jan 2003, Joshua Stewart wrote:

Hi,

> I'm trying to take "hand-built" sk_buffs with little more than some data
> and a dev member and push them to the NIC for transmission. I would
> like to simply give them to dev_queue_xmit. Does anybody know what
> state I should have them in before handing them to dev_queue_xmit?

In a driver I wrote I setup (for a newly allocated skb and a 2.4 kernel):

some_header = (struct some_header *) skb_push(skb, sizeof(struct some_header));

skb->nh.raw = (unsigned char *) some_header;

this_eth_hdr = (struct ethhdr *) skb_push(skb, ETH_HLEN);

this_eth_hdr->h_proto = __constant_htons(ETH_P_SOME_HEADER);
memcpy(this_eth_hdr->h_source, dev->dev_addr, ETH_ALEN);

skb->dev = dev;
skb->protocol = __constant_htons(ETH_P_CSM_ENCAPS);

dev_queue_xmit(skb);

where some_header for you is probably an IP header and dev is the "struct
net_device" of the device you are using to send the packet out on the
wire.

> Should skb->data point to the start of a MAC header or an IP header?

MAC

> Also, given an IP address in skb->nh.iph->daddr, what's the easiest way
> to get the appropriate MAC address?

First you need to get the device, then the MAC address is easy. This
should be what normal IP routing code does...

> J
>
>

Rui

> -
> 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/
>