Skip to content

Commit

Permalink
flow_dissector: factor out the ports extraction in skb_flow_get_ports
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Nikolay Aleksandrov authored and David S. Miller committed Oct 3, 2013
1 parent 5080546 commit 357afe9
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 11 deletions.
1 change: 1 addition & 0 deletions include/net/flow_keys.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ struct flow_keys {
};

bool skb_flow_dissect(const struct sk_buff *skb, struct flow_keys *flow);
__be32 skb_flow_get_ports(const struct sk_buff *skb, int thoff, u8 ip_proto);
#endif
39 changes: 28 additions & 11 deletions net/core/flow_dissector.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,35 @@ static void iph_to_flow_copy_addrs(struct flow_keys *flow, const struct iphdr *i
memcpy(&flow->src, &iph->saddr, sizeof(flow->src) + sizeof(flow->dst));
}

/**
* skb_flow_get_ports - extract the upper layer ports and return them
* @skb: buffer to extract the ports from
* @thoff: transport header offset
* @ip_proto: protocol for which to get port offset
*
* The function will try to retrieve the ports at offset thoff + poff where poff
* is the protocol port offset returned from proto_ports_offset
*/
__be32 skb_flow_get_ports(const struct sk_buff *skb, int thoff, u8 ip_proto)
{
int poff = proto_ports_offset(ip_proto);

if (poff >= 0) {
__be32 *ports, _ports;

ports = skb_header_pointer(skb, thoff + poff,
sizeof(_ports), &_ports);
if (ports)
return *ports;
}

return 0;
}
EXPORT_SYMBOL(skb_flow_get_ports);

bool skb_flow_dissect(const struct sk_buff *skb, struct flow_keys *flow)
{
int poff, nhoff = skb_network_offset(skb);
int nhoff = skb_network_offset(skb);
u8 ip_proto;
__be16 proto = skb->protocol;

Expand Down Expand Up @@ -150,16 +176,7 @@ bool skb_flow_dissect(const struct sk_buff *skb, struct flow_keys *flow)
}

flow->ip_proto = ip_proto;
poff = proto_ports_offset(ip_proto);
if (poff >= 0) {
__be32 *ports, _ports;

ports = skb_header_pointer(skb, nhoff + poff,
sizeof(_ports), &_ports);
if (ports)
flow->ports = *ports;
}

flow->ports = skb_flow_get_ports(skb, nhoff, ip_proto);
flow->thoff = (u16) nhoff;

return true;
Expand Down

0 comments on commit 357afe9

Please sign in to comment.