From: Amin Azez <azez@ufomechanic.net>
To: Henrik Nordstrom <hno@marasystems.com>
Cc: netfilter-devel@lists.netfilter.org
Subject: wow, why does everything presume ethernet? Re: skb->mac.raw, when is does it point to ethhdr
Date: Fri, 29 Apr 2005 16:54:39 +0100 [thread overview]
Message-ID: <427258BF.7080405@ufomechanic.net> (raw)
In-Reply-To: <Pine.LNX.4.61.0504290113360.26003@filer.marasystems.com>
Henrik Nordstrom wrote:
> On Thu, 28 Apr 2005, Amin Azez wrote:
>
>> So the question comes up, how do we tell when skb->mac.raw is
>> pointing to an ethernet frame header and when it is pointing to
>> something else?
>
> IIRC You need to look at the link type of the device the packet came
> from.
I was trying to do that but when I looked again after your hint I found
it, thanks.
I notice most netfilter stuff that uses mac.raw seems to presume an
ethernet link layer.
e.g.
net/ipv4/netfilter/ipt_mac.c - although it takes "in" and "out" devices
as parameters it presumes ethernet:
static int
match(const struct sk_buff *skb,
const struct net_device *in,
const struct net_device *out,
const void *matchinfo,
int offset,
int *hotdrop)
{
const struct ipt_mac_info *info = matchinfo;
/* Is mac pointer valid? */
return (skb->mac.raw >= skb->head
&& (skb->mac.raw + ETH_HLEN) <= skb->data
/* If so, compare... */
&& ((memcmp(eth_hdr(skb)->h_source, info->srcaddr, ETH_ALEN)
== 0) ^ info->invert));
}
in net/bridge/br_stp_bpdu.c, br_send_bpdu has:
memcpy(skb->mac.raw, bridge_ula, ETH_ALEN);
memcpy(skb->mac.raw+ETH_ALEN, dev->dev_addr, ETH_ALEN);
are only ethernet bridges supported? I guess so... even the bluetooth
stuff presumes ETH_ALEN
All I can say is "wow"
I was planning to do things "properly" and use skb->input_dev (or do I
need skb->dev or skb->realdev?)
skb->input_dev->type
will refer (strangely to) one of the ARP types in linux/if_arp.h with me
being interested in ARPHRD_ETHER among others.
Mac address length will be
skb->input_dev->addr_len
However, to get at a source mac address is still uncertain, maybe I need
to dispatch to a different routine or different offsets based on
input_dev->type ?
There doesn't seem to be a standard way to access mac addresses from
link layer packets (arp stuff must know how to) which perhaps is why I
can't find one, and everyone is doing what I did at first and presuming
ethernet.
For ethernet, skb->mac.raw points to:
struct ethhdr {
unsigned char h_dest[ETH_ALEN]; /* destination eth addr */
unsigned char h_source[ETH_ALEN]; /* source ether addr */
unsigned short h_proto; /* packet type ID field */
} __attribute__((packed));
and the source address is had from
(skb->mac.raw)+(skb->input_dev->addr_len), but does it follow that the
same rules work for token ring or other network types. For ethernet it
comes straight from the headers.
Does anyone know without looking how "ifconfig" works out how to format
the mac address? (Not that it will help me work out what the source mac
address is for a given skb, but I'm looking for how to generate a
standard textual representation based on dev->addr_len and skb->mac.raw).
Amin
next prev parent reply other threads:[~2005-04-29 15:54 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-04-28 16:29 skb->mac.raw, when is does it point to ethhdr Amin Azez
2005-04-28 17:24 ` YOSHIFUJI Hideaki / 吉藤英明
2005-04-29 10:01 ` Amin Azez
2005-04-29 14:52 ` Henrik Nordstrom
2005-04-29 15:54 ` Amin Azez [this message]
2005-05-01 20:54 ` wow, why does everything presume ethernet? " Henrik Nordstrom
2005-05-03 8:23 ` Amin Azez
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=427258BF.7080405@ufomechanic.net \
--to=azez@ufomechanic.net \
--cc=hno@marasystems.com \
--cc=netfilter-devel@lists.netfilter.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.