* [B.A.T.M.A.N.] [PATCHv2] batman-adv: use __constant_htons when possible
@ 2013-05-12 20:09 Antonio Quartulli
2013-05-17 7:09 ` Antonio Quartulli
0 siblings, 1 reply; 2+ messages in thread
From: Antonio Quartulli @ 2013-05-12 20:09 UTC (permalink / raw)
To: b.a.t.m.a.n; +Cc: Antonio Quartulli
When comparing a network ordered value with a constant, it
is better to convert the constant at compile time by means
of __constant_htons() instead of converting the value at
runtime using ntohs().
This refactoring may slightly improve the code performance.
Signed-off-by: Antonio Quartulli <ordex@autistici.org>
---
v2:
- v1 was based on a patch I decided to not send anymore and was generating a
conflict. now it is based on top of
"batman-adv: use VLAN_ETH_HLEN instead of sizeof(struct vlan_eth_hdr)"
bridge_loop_avoidance.c | 12 ++++++------
gateway_client.c | 4 ++--
2 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/bridge_loop_avoidance.c b/bridge_loop_avoidance.c
index 9e691b0..90b27b3 100644
--- a/bridge_loop_avoidance.c
+++ b/bridge_loop_avoidance.c
@@ -863,25 +863,25 @@ static int batadv_bla_process_claim(struct batadv_priv *bat_priv,
struct arphdr *arphdr;
uint8_t *hw_src, *hw_dst;
struct batadv_bla_claim_dst *bla_dst;
- uint16_t proto;
+ __be16 proto;
int headlen;
unsigned short vid = BATADV_NO_FLAGS;
int ret;
ethhdr = eth_hdr(skb);
- if (ntohs(ethhdr->h_proto) == ETH_P_8021Q) {
+ if (ethhdr->h_proto == __constant_htons(ETH_P_8021Q)) {
vhdr = (struct vlan_ethhdr *)ethhdr;
vid = ntohs(vhdr->h_vlan_TCI) & VLAN_VID_MASK;
vid |= BATADV_VLAN_HAS_TAG;
- proto = ntohs(vhdr->h_vlan_encapsulated_proto);
+ proto = vhdr->h_vlan_encapsulated_proto;
headlen = sizeof(*vhdr);
} else {
- proto = ntohs(ethhdr->h_proto);
+ proto = ethhdr->h_proto;
headlen = ETH_HLEN;
}
- if (proto != ETH_P_ARP)
+ if (proto != __constant_htons(ETH_P_ARP))
return 0; /* not a claim frame */
/* this must be a ARP frame. check if it is a claim. */
@@ -1375,7 +1375,7 @@ int batadv_bla_is_backbone_gw(struct sk_buff *skb,
ethhdr = (struct ethhdr *)(((uint8_t *)skb->data) + hdr_size);
- if (ntohs(ethhdr->h_proto) == ETH_P_8021Q) {
+ if (ethhdr->h_proto == __constant_htons(ETH_P_8021Q)) {
if (!pskb_may_pull(skb, hdr_size + VLAN_ETH_HLEN))
return 0;
diff --git a/gateway_client.c b/gateway_client.c
index f59e58d..3cf92f8 100644
--- a/gateway_client.c
+++ b/gateway_client.c
@@ -682,11 +682,11 @@ bool batadv_gw_is_dhcp_target(struct sk_buff *skb, unsigned int *header_len)
/* check for bootp port */
if ((proto == __constant_htons(ETH_P_IP)) &&
- (ntohs(udphdr->dest) != 67))
+ (udphdr->dest != __constant_htons(67)))
return false;
if ((proto == __constant_htons(ETH_P_IPV6)) &&
- (ntohs(udphdr->dest) != 547))
+ (udphdr->dest != __constant_htons(547)))
return false;
return true;
--
1.8.1.5
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2013-05-17 7:09 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-05-12 20:09 [B.A.T.M.A.N.] [PATCHv2] batman-adv: use __constant_htons when possible Antonio Quartulli
2013-05-17 7:09 ` Antonio Quartulli
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox