Skip to content

Commit

Permalink
net: add ETH_P_802_3_MIN
Browse files Browse the repository at this point in the history
Add a new constant ETH_P_802_3_MIN, the minimum ethernet type for
an 802.3 frame. Frames with a lower value in the ethernet type field
are Ethernet II.

Also update all the users of this value that David Miller and
I could find to use the new constant.

Also correct a bug in util.c. The comparison with ETH_P_802_3_MIN
should be >= not >.

As suggested by Jesse Gross.

Compile tested only.

Cc: David Miller <[email protected]>
Cc: Jesse Gross <[email protected]>
Cc: Karsten Keil <[email protected]>
Cc: John W. Linville <[email protected]>
Cc: Johannes Berg <[email protected]>
Cc: Bart De Schuymer <[email protected]>
Cc: Stephen Hemminger <[email protected]>
Cc: Patrick McHardy <[email protected]>
Cc: Marcel Holtmann <[email protected]>
Cc: Gustavo Padovan <[email protected]>
Cc: Johan Hedberg <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Acked-by: Mauro Carvalho Chehab <[email protected]>
Acked-by: Stefan Richter <[email protected]>
Signed-off-by: Simon Horman <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
horms authored and davem330 committed Mar 28, 2013
1 parent 8b49a4c commit e5c5d22
Show file tree
Hide file tree
Showing 16 changed files with 24 additions and 21 deletions.
2 changes: 1 addition & 1 deletion drivers/firewire/net.c
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ static int fwnet_finish_incoming_packet(struct net_device *net,
if (memcmp(eth->h_dest, net->dev_addr, net->addr_len))
skb->pkt_type = PACKET_OTHERHOST;
}
if (ntohs(eth->h_proto) >= 1536) {
if (ntohs(eth->h_proto) >= ETH_P_802_3_MIN) {
protocol = eth->h_proto;
} else {
rawp = (u16 *)skb->data;
Expand Down
2 changes: 1 addition & 1 deletion drivers/isdn/i4l/isdn_net.c
Original file line number Diff line number Diff line change
Expand Up @@ -1385,7 +1385,7 @@ isdn_net_type_trans(struct sk_buff *skb, struct net_device *dev)
if (memcmp(eth->h_dest, dev->dev_addr, ETH_ALEN))
skb->pkt_type = PACKET_OTHERHOST;
}
if (ntohs(eth->h_proto) >= 1536)
if (ntohs(eth->h_proto) >= ETH_P_802_3_MIN)
return eth->h_proto;

rawp = skb->data;
Expand Down
10 changes: 5 additions & 5 deletions drivers/media/dvb-core/dvb_net.c
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ static __be16 dvb_net_eth_type_trans(struct sk_buff *skb,
skb->pkt_type=PACKET_MULTICAST;
}

if (ntohs(eth->h_proto) >= 1536)
if (ntohs(eth->h_proto) >= ETH_P_802_3_MIN)
return eth->h_proto;

rawp = skb->data;
Expand Down Expand Up @@ -228,9 +228,9 @@ static int ule_test_sndu( struct dvb_net_priv *p )
static int ule_bridged_sndu( struct dvb_net_priv *p )
{
struct ethhdr *hdr = (struct ethhdr*) p->ule_next_hdr;
if(ntohs(hdr->h_proto) < 1536) {
if(ntohs(hdr->h_proto) < ETH_P_802_3_MIN) {
int framelen = p->ule_sndu_len - ((p->ule_next_hdr+sizeof(struct ethhdr)) - p->ule_skb->data);
/* A frame Type < 1536 for a bridged frame, introduces a LLC Length field. */
/* A frame Type < ETH_P_802_3_MIN for a bridged frame, introduces a LLC Length field. */
if(framelen != ntohs(hdr->h_proto)) {
return -1;
}
Expand Down Expand Up @@ -320,7 +320,7 @@ static int handle_ule_extensions( struct dvb_net_priv *p )
(int) p->ule_sndu_type, l, total_ext_len);
#endif

} while (p->ule_sndu_type < 1536);
} while (p->ule_sndu_type < ETH_P_802_3_MIN);

return total_ext_len;
}
Expand Down Expand Up @@ -712,7 +712,7 @@ static void dvb_net_ule( struct net_device *dev, const u8 *buf, size_t buf_len )
}

/* Handle ULE Extension Headers. */
if (priv->ule_sndu_type < 1536) {
if (priv->ule_sndu_type < ETH_P_802_3_MIN) {
/* There is an extension header. Handle it accordingly. */
int l = handle_ule_extensions(priv);
if (l < 0) {
Expand Down
2 changes: 1 addition & 1 deletion drivers/net/ethernet/sun/niu.c
Original file line number Diff line number Diff line change
Expand Up @@ -6618,7 +6618,7 @@ static u64 niu_compute_tx_flags(struct sk_buff *skb, struct ethhdr *ehdr,
(len << TXHDR_LEN_SHIFT) |
((l3off / 2) << TXHDR_L3START_SHIFT) |
(ihl << TXHDR_IHL_SHIFT) |
((eth_proto_inner < 1536) ? TXHDR_LLC : 0) |
((eth_proto_inner < ETH_P_802_3_MIN) ? TXHDR_LLC : 0) |
((eth_proto == ETH_P_8021Q) ? TXHDR_VLAN : 0) |
(ipv6 ? TXHDR_IP_VER : 0) |
csum_bits);
Expand Down
2 changes: 1 addition & 1 deletion drivers/net/plip/plip.c
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ static __be16 plip_type_trans(struct sk_buff *skb, struct net_device *dev)
* so don't forget to remove it.
*/

if (ntohs(eth->h_proto) >= 1536)
if (ntohs(eth->h_proto) >= ETH_P_802_3_MIN)
return eth->h_proto;

rawp = skb->data;
Expand Down
2 changes: 1 addition & 1 deletion drivers/net/wireless/ray_cs.c
Original file line number Diff line number Diff line change
Expand Up @@ -953,7 +953,7 @@ static int translate_frame(ray_dev_t *local, struct tx_msg __iomem *ptx,
unsigned char *data, int len)
{
__be16 proto = ((struct ethhdr *)data)->h_proto;
if (ntohs(proto) >= 1536) { /* DIX II ethernet frame */
if (ntohs(proto) >= ETH_P_802_3_MIN) { /* DIX II ethernet frame */
pr_debug("ray_cs translate_frame DIX II\n");
/* Copy LLC header to card buffer */
memcpy_toio(&ptx->var, eth2_llc, sizeof(eth2_llc));
Expand Down
2 changes: 1 addition & 1 deletion include/linux/if_vlan.h
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ static inline void vlan_set_encap_proto(struct sk_buff *skb,
*/

proto = vhdr->h_vlan_encapsulated_proto;
if (ntohs(proto) >= 1536) {
if (ntohs(proto) >= ETH_P_802_3_MIN) {
skb->protocol = proto;
return;
}
Expand Down
3 changes: 3 additions & 0 deletions include/uapi/linux/if_ether.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@
#define ETH_P_EDSA 0xDADA /* Ethertype DSA [ NOT AN OFFICIALLY REGISTERED ID ] */
#define ETH_P_AF_IUCV 0xFBFB /* IBM af_iucv [ NOT AN OFFICIALLY REGISTERED ID ] */

#define ETH_P_802_3_MIN 0x0600 /* If the value in the ethernet type is less than this value
* then the frame is Ethernet II. Else it is 802.3 */

/*
* Non DIX types. Won't clash for 1500 types.
*/
Expand Down
2 changes: 1 addition & 1 deletion net/atm/lec.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ struct lane2_ops {
* field in h_type field. Data follows immediately after header.
* 2. LLC Data frames whose total length, including LLC field and data,
* but not padding required to meet the minimum data frame length,
* is less than 1536(0x0600) MUST be encoded by placing that length
* is less than ETH_P_802_3_MIN MUST be encoded by placing that length
* in the h_type field. The LLC field follows header immediately.
* 3. LLC data frames longer than this maximum MUST be encoded by placing
* the value 0 in the h_type field.
Expand Down
2 changes: 1 addition & 1 deletion net/bluetooth/bnep/netdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ static u16 bnep_net_eth_proto(struct sk_buff *skb)
struct ethhdr *eh = (void *) skb->data;
u16 proto = ntohs(eh->h_proto);

if (proto >= 1536)
if (proto >= ETH_P_802_3_MIN)
return proto;

if (get_unaligned((__be16 *) skb->data) == htons(0xFFFF))
Expand Down
2 changes: 1 addition & 1 deletion net/bridge/netfilter/ebtables.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ ebt_basic_match(const struct ebt_entry *e, const struct sk_buff *skb,
ethproto = h->h_proto;

if (e->bitmask & EBT_802_3) {
if (FWINV2(ntohs(ethproto) >= 1536, EBT_IPROTO))
if (FWINV2(ntohs(ethproto) >= ETH_P_802_3_MIN, EBT_IPROTO))
return 1;
} else if (!(e->bitmask & EBT_NOPROTO) &&
FWINV2(e->ethproto != ethproto, EBT_IPROTO))
Expand Down
2 changes: 1 addition & 1 deletion net/ethernet/eth.c
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ __be16 eth_type_trans(struct sk_buff *skb, struct net_device *dev)
if (netdev_uses_trailer_tags(dev))
return htons(ETH_P_TRAILER);

if (ntohs(eth->h_proto) >= 1536)
if (ntohs(eth->h_proto) >= ETH_P_802_3_MIN)
return eth->h_proto;

/*
Expand Down
2 changes: 1 addition & 1 deletion net/mac80211/tx.c
Original file line number Diff line number Diff line change
Expand Up @@ -2085,7 +2085,7 @@ netdev_tx_t ieee80211_subif_start_xmit(struct sk_buff *skb,
encaps_data = bridge_tunnel_header;
encaps_len = sizeof(bridge_tunnel_header);
skip_header_bytes -= 2;
} else if (ethertype >= 0x600) {
} else if (ethertype >= ETH_P_802_3_MIN) {
encaps_data = rfc1042_header;
encaps_len = sizeof(rfc1042_header);
skip_header_bytes -= 2;
Expand Down
2 changes: 1 addition & 1 deletion net/openvswitch/datapath.c
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,7 @@ static int ovs_packet_cmd_execute(struct sk_buff *skb, struct genl_info *info)
/* Normally, setting the skb 'protocol' field would be handled by a
* call to eth_type_trans(), but it assumes there's a sending
* device, which we may not have. */
if (ntohs(eth->h_proto) >= 1536)
if (ntohs(eth->h_proto) >= ETH_P_802_3_MIN)
packet->protocol = eth->h_proto;
else
packet->protocol = htons(ETH_P_802_2);
Expand Down
6 changes: 3 additions & 3 deletions net/openvswitch/flow.c
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ static __be16 parse_ethertype(struct sk_buff *skb)
proto = *(__be16 *) skb->data;
__skb_pull(skb, sizeof(__be16));

if (ntohs(proto) >= 1536)
if (ntohs(proto) >= ETH_P_802_3_MIN)
return proto;

if (skb->len < sizeof(struct llc_snap_hdr))
Expand All @@ -483,7 +483,7 @@ static __be16 parse_ethertype(struct sk_buff *skb)

__skb_pull(skb, sizeof(struct llc_snap_hdr));

if (ntohs(llc->ethertype) >= 1536)
if (ntohs(llc->ethertype) >= ETH_P_802_3_MIN)
return llc->ethertype;

return htons(ETH_P_802_2);
Expand Down Expand Up @@ -1038,7 +1038,7 @@ int ovs_flow_from_nlattrs(struct sw_flow_key *swkey, int *key_lenp,

if (attrs & (1 << OVS_KEY_ATTR_ETHERTYPE)) {
swkey->eth.type = nla_get_be16(a[OVS_KEY_ATTR_ETHERTYPE]);
if (ntohs(swkey->eth.type) < 1536)
if (ntohs(swkey->eth.type) < ETH_P_802_3_MIN)
return -EINVAL;
attrs &= ~(1 << OVS_KEY_ATTR_ETHERTYPE);
} else {
Expand Down
2 changes: 1 addition & 1 deletion net/wireless/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ int ieee80211_data_from_8023(struct sk_buff *skb, const u8 *addr,
encaps_data = bridge_tunnel_header;
encaps_len = sizeof(bridge_tunnel_header);
skip_header_bytes -= 2;
} else if (ethertype > 0x600) {
} else if (ethertype >= ETH_P_802_3_MIN) {
encaps_data = rfc1042_header;
encaps_len = sizeof(rfc1042_header);
skip_header_bytes -= 2;
Expand Down

0 comments on commit e5c5d22

Please sign in to comment.