Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

flow_dissector: factor out the ports extraction in skb_flow_get_ports

Factor out the code that extracts the ports from skb_flow_dissect and
add a new function skb_flow_get_ports which can be re-used.

Suggested-by: Veaceslav Falico <vfalico@redhat.com>
Signed-off-by: Nikolay Aleksandrov <nikolay@redhat.com>
Acked-by: Eric Dumazet <edumazet@google.com>
Reviewed-by: Veaceslav Falico <vfalico@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Nikolay Aleksandrov and committed by
David S. Miller
357afe9c 50805466

+29 -11
+1
include/net/flow_keys.h
··· 14 14 }; 15 15 16 16 bool skb_flow_dissect(const struct sk_buff *skb, struct flow_keys *flow); 17 + __be32 skb_flow_get_ports(const struct sk_buff *skb, int thoff, u8 ip_proto); 17 18 #endif
+28 -11
net/core/flow_dissector.c
··· 25 25 memcpy(&flow->src, &iph->saddr, sizeof(flow->src) + sizeof(flow->dst)); 26 26 } 27 27 28 + /** 29 + * skb_flow_get_ports - extract the upper layer ports and return them 30 + * @skb: buffer to extract the ports from 31 + * @thoff: transport header offset 32 + * @ip_proto: protocol for which to get port offset 33 + * 34 + * The function will try to retrieve the ports at offset thoff + poff where poff 35 + * is the protocol port offset returned from proto_ports_offset 36 + */ 37 + __be32 skb_flow_get_ports(const struct sk_buff *skb, int thoff, u8 ip_proto) 38 + { 39 + int poff = proto_ports_offset(ip_proto); 40 + 41 + if (poff >= 0) { 42 + __be32 *ports, _ports; 43 + 44 + ports = skb_header_pointer(skb, thoff + poff, 45 + sizeof(_ports), &_ports); 46 + if (ports) 47 + return *ports; 48 + } 49 + 50 + return 0; 51 + } 52 + EXPORT_SYMBOL(skb_flow_get_ports); 53 + 28 54 bool skb_flow_dissect(const struct sk_buff *skb, struct flow_keys *flow) 29 55 { 30 - int poff, nhoff = skb_network_offset(skb); 56 + int nhoff = skb_network_offset(skb); 31 57 u8 ip_proto; 32 58 __be16 proto = skb->protocol; 33 59 ··· 176 150 } 177 151 178 152 flow->ip_proto = ip_proto; 179 - poff = proto_ports_offset(ip_proto); 180 - if (poff >= 0) { 181 - __be32 *ports, _ports; 182 - 183 - ports = skb_header_pointer(skb, nhoff + poff, 184 - sizeof(_ports), &_ports); 185 - if (ports) 186 - flow->ports = *ports; 187 - } 188 - 153 + flow->ports = skb_flow_get_ports(skb, nhoff, ip_proto); 189 154 flow->thoff = (u16) nhoff; 190 155 191 156 return true;