bnep endianness bug: filtering by packet type
PATCH 4/4 bnep endianness bug: filtering by packet type
<= and => don't work well on net-endian...
--- net/bluetooth/bnep/bnep.h | 4 ++-- net/bluetooth/bnep/core.c | 16 ++++++++-------- net/bluetooth/bnep/netdev.c | 15 ++++++++------- 3 files changed, 18 insertions(+), 17 deletions(-)
net/bluetooth/bnep/bnep.h +2 -2
@@ -143,8 +143,8 @@ struct bnep_connlist_req { };struct bnep_proto_filter { -__be16 start; -__be16 end; +__u16 start; +__u16 end; };int bnep_add_connection (struct bnep_connadd_req *req,struct socket *sock);
net/bluetooth/bnep/core.c +8 -8
@@ -117,14 +117,14 @@ #ifdef CONFIG_BT_BNEP_PROTO_FILTERstatic inline void bnep_set_default_proto_filter (struct bnep_session *s) {/* (IPv4, ARP) */ - s->proto_filter[0 ].start =htons (0x0800 ); - s->proto_filter[0 ].end =htons (0x0806 ); + s->proto_filter[0 ].start =ETH_P_IP ; + s->proto_filter[0 ].end =ETH_P_ARP ;/* (RARP, AppleTalk) */ - s->proto_filter[1 ].start =htons (0x8035 ); - s->proto_filter[1 ].end =htons (0x80F3 ); + s->proto_filter[1 ].start =ETH_P_RARP ; + s->proto_filter[1 ].end =ETH_P_AARP ;/* (IPX, IPv6) */ - s->proto_filter[2 ].start =htons (0x8137 ); - s->proto_filter[2 ].end =htons (0x86DD ); + s->proto_filter[2 ].start =ETH_P_IPX ; + s->proto_filter[2 ].end =ETH_P_IPV6 ; }#endif
@@ -150,8 +150,8 @@ #ifdef CONFIG_BT_BNEP_PROTO_FILTERint i;for (i =0 ; i < n; i++) { - f[i].start =get_unaligned (data++); - f[i].end =get_unaligned (data++); + f[i].start =ntohs (get_unaligned (data++)); + f[i].end =ntohs (get_unaligned (data++));BT_DBG ("proto filter start %d end %d" , f[i].start, f[i].end);
net/bluetooth/bnep/netdev.c +8 -7
@@ -155,22 +155,23 @@ #endif#ifdef CONFIG_BT_BNEP_PROTO_FILTER /* Determine ether protocol. Based on eth_type_trans. */ -static inline __be16 bnep_net_eth_proto (struct sk_buff *skb) +static inline __u16 bnep_net_eth_proto (struct sk_buff *skb) {struct ethhdr *eh = (void *) skb->data; +u16 proto =ntohs (eh->h_proto); -if (ntohs (eh->h_proto) >=1536 ) -return eh->h_proto; +if (proto >=1536 ) +return proto; -if (get_unaligned ((u16 *) skb->data) ==0xFFFF ) -return htons (ETH_P_802_3 ); +if (get_unaligned ((__be16 *) skb->data) ==htons (0xFFFF )) +return ETH_P_802_3 ; -return htons (ETH_P_802_2 ); +return ETH_P_802_2 ; }static inline int bnep_net_proto_filter (struct sk_buff *skb,struct bnep_session *s) { -__be16 proto =bnep_net_eth_proto (skb); +__u16 proto =bnep_net_eth_proto (skb);struct bnep_proto_filter *f = s->proto_filter;int i;
Signature · 1 line
1.4.2.GIT
Marcel Holtmann
maintainerHi Al,
Quoted 1 line
<= and => don't work well on net-endian...
can we have a clean one for the BNEP part. Not one that changes something and then another one reverting it.
Regards
Marcel
Quoted 6 lines · Marcel Holtmann
Hi Al,
Quoted 1 line
<= and => don't work well on net-endian...
can we have a clean one for the BNEP part. Not one that changes something and then another one reverting it.
*shrug*
I can reorder, of course. FWIW, I prefer to do a patch that annotates existing use and provably does not change behaviour + fixes for whatever crap shows up once said existing use is annotated, but if you prefer it in opposite order...
OTOH, in this case bug is obvious enough as it is, so... Will reorder and send.
Date: Sun, 15 Oct 2006 20:13:58 -0400
Subject: [PATCH] bnep endianness bug: filtering by packet type
<= and => don't work well on net-endian...
--- net/bluetooth/bnep/core.c | 16 ++++++++-------- net/bluetooth/bnep/netdev.c | 11 ++++++----- 2 files changed, 14 insertions(+), 13 deletions(-)
net/bluetooth/bnep/core.c +8 -8
@@ -117,14 +117,14 @@ #ifdef CONFIG_BT_BNEP_PROTO_FILTERstatic inline void bnep_set_default_proto_filter (struct bnep_session *s) {/* (IPv4, ARP) */ - s->proto_filter[0 ].start =htons (0x0800 ); - s->proto_filter[0 ].end =htons (0x0806 ); + s->proto_filter[0 ].start =ETH_P_IP ; + s->proto_filter[0 ].end =ETH_P_ARP ;/* (RARP, AppleTalk) */ - s->proto_filter[1 ].start =htons (0x8035 ); - s->proto_filter[1 ].end =htons (0x80F3 ); + s->proto_filter[1 ].start =ETH_P_RARP ; + s->proto_filter[1 ].end =ETH_P_AARP ;/* (IPX, IPv6) */ - s->proto_filter[2 ].start =htons (0x8137 ); - s->proto_filter[2 ].end =htons (0x86DD ); + s->proto_filter[2 ].start =ETH_P_IPX ; + s->proto_filter[2 ].end =ETH_P_IPV6 ; }#endif
@@ -150,8 +150,8 @@ #ifdef CONFIG_BT_BNEP_PROTO_FILTERint i;for (i =0 ; i < n; i++) { - f[i].start =get_unaligned (data++); - f[i].end =get_unaligned (data++); + f[i].start =ntohs (get_unaligned (data++)); + f[i].end =ntohs (get_unaligned (data++));BT_DBG ("proto filter start %d end %d" , f[i].start, f[i].end);
net/bluetooth/bnep/netdev.c +6 -5
@@ -158,14 +158,15 @@ #ifdef CONFIG_BT_BNEP_PROTO_FILTERstatic inline u16 bnep_net_eth_proto (struct sk_buff *skb) {struct ethhdr *eh = (void *) skb->data; +u16 proto =ntohs (eh->h_proto); -if (ntohs (eh->h_proto) >=1536 ) -return eh->h_proto; +if (proto >=1536 ) +return proto; -if (get_unaligned ((u16 *) skb->data) ==0xFFFF ) -return htons (ETH_P_802_3 ); +if (get_unaligned ((__be16 *) skb->data) ==htons (0xFFFF )) +return ETH_P_802_3 ; -return htons (ETH_P_802_2 ); +return ETH_P_802_2 ; }static inline int bnep_net_proto_filter (struct sk_buff *skb,struct bnep_session *s)
Signature · 1 line
1.4.2.GIT
Date: Thu, 16 Feb 2006 02:47:56 -0500
Subject: [PATCH] bnep endianness annotations
--- net/bluetooth/bnep/bnep.h | 4 ++-- net/bluetooth/bnep/core.c | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-)
net/bluetooth/bnep/bnep.h +2 -2
@@ -95,14 +95,14 @@ struct bnep_setup_conn_req {struct bnep_set_filter_req {__u8 type;__u8 ctrl; -__u16 len; +__be16 len;__u8 list[0 ]; } __attribute__((packed));struct bnep_control_rsp {__u8 type;__u8 ctrl; -__u16 resp; +__be16 resp; } __attribute__((packed));struct bnep_ext_hdr {
net/bluetooth/bnep/core.c +6 -6
@@ -128,7 +128,7 @@ static inline void bnep_set_default_prot }#endif -static int bnep_ctrl_set_netfilter (struct bnep_session *s,u16 *data,int len) +static int bnep_ctrl_set_netfilter (struct bnep_session *s,__be16 *data,int len) {int n;
@@ -180,7 +180,7 @@ static int bnep_ctrl_set_mcfilter(structif (len <2 )return -EILSEQ ; - n =ntohs (get_unaligned ((u16 *) data)); + n =ntohs (get_unaligned ((__be16 *) data)); data +=2 ; len -=2 ;if (len < n)
@@ -332,7 +332,7 @@ static inline int bnep_rx_frame(struct bif (!skb_pull (skb, __bnep_rx_hlen[type &BNEP_TYPE_MASK ])) goto badframe; - s->eh.h_proto =get_unaligned ((u16 *) (skb->data -2 )); + s->eh.h_proto =get_unaligned ((__be16 *) (skb->data -2 ));if (type &BNEP_EXT_HEADER ) {if (bnep_rx_extension (s, skb) <0 )
@@ -343,7 +343,7 @@ static inline int bnep_rx_frame(struct bif (ntohs (s->eh.h_proto) ==0x8100 ) {if (!skb_pull (skb,4 )) goto badframe; - s->eh.h_proto =get_unaligned ((u16 *) (skb->data -2 )); + s->eh.h_proto =get_unaligned ((__be16 *) (skb->data -2 )); }/* We have to alloc new skb and copy data here :(. Because original skb
@@ -365,7 +365,7 @@ static inline int bnep_rx_frame(struct bcase BNEP_COMPRESSED_SRC_ONLY :memcpy (__skb_put (nskb,ETH_ALEN ), s->eh.h_dest,ETH_ALEN );memcpy (__skb_put (nskb,ETH_ALEN ), skb->mac.raw,ETH_ALEN ); -put_unaligned (s->eh.h_proto, (u16 *)__skb_put (nskb,2 )); +put_unaligned (s->eh.h_proto, (__be16 *)__skb_put (nskb,2 ));break ;case BNEP_COMPRESSED_DST_ONLY :
@@ -375,7 +375,7 @@ static inline int bnep_rx_frame(struct bcase BNEP_GENERAL :memcpy (__skb_put (nskb,ETH_ALEN *2 ), skb->mac.raw,ETH_ALEN *2 ); -put_unaligned (s->eh.h_proto, (u16 *)__skb_put (nskb,2 )); +put_unaligned (s->eh.h_proto, (__be16 *)__skb_put (nskb,2 ));break ; }
Signature · 1 line
1.4.2.GIT
Quoted 10 lines · Al Viro
Quoted 6 lines · Marcel Holtmann
Hi Al,
Quoted 1 line
<= and => don't work well on net-endian...
can we have a clean one for the BNEP part. Not one that changes something and then another one reverting it.
*shrug*
Quoted 7 lines
I can reorder, of course. FWIW, I prefer to do a patch that annotates existing use and provably does not change behaviour + fixes for whatever crap shows up once said existing use is annotated, but if you prefer it in opposite order...
OTOH, in this case bug is obvious enough as it is, so... Will reorder and send.
Done.