Skip to content

Commit

Permalink
udp: Add udp6_lib_lookup_skb and udp4_lib_lookup_skb
Browse files Browse the repository at this point in the history
Add externally visible functions to lookup a UDP socket by skb. This
will be used for GRO in UDP sockets. These functions also check
if skb->dst is set, and if it is not skb->dev is used to get dev_net.
This allows calling lookup functions before dst has been set on the
skbuff.

Signed-off-by: Tom Herbert <tom@herbertland.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Tom Herbert authored and David S. Miller committed Apr 7, 2016
1 parent 0340d0b commit 6305830
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
4 changes: 4 additions & 0 deletions include/net/udp.h
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,8 @@ struct sock *udp4_lib_lookup(struct net *net, __be32 saddr, __be16 sport,
struct sock *__udp4_lib_lookup(struct net *net, __be32 saddr, __be16 sport,
__be32 daddr, __be16 dport, int dif,
struct udp_table *tbl, struct sk_buff *skb);
struct sock *udp4_lib_lookup_skb(struct sk_buff *skb,
__be16 sport, __be16 dport);
struct sock *udp6_lib_lookup(struct net *net,
const struct in6_addr *saddr, __be16 sport,
const struct in6_addr *daddr, __be16 dport,
Expand All @@ -278,6 +280,8 @@ struct sock *__udp6_lib_lookup(struct net *net,
const struct in6_addr *daddr, __be16 dport,
int dif, struct udp_table *tbl,
struct sk_buff *skb);
struct sock *udp6_lib_lookup_skb(struct sk_buff *skb,
__be16 sport, __be16 dport);

/*
* SNMP statistics for UDP and UDP-Lite
Expand Down
13 changes: 13 additions & 0 deletions net/ipv4/udp.c
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,19 @@ static inline struct sock *__udp4_lib_lookup_skb(struct sk_buff *skb,
udptable, skb);
}

struct sock *udp4_lib_lookup_skb(struct sk_buff *skb,
__be16 sport, __be16 dport)
{
const struct iphdr *iph = ip_hdr(skb);
const struct net_device *dev =
skb_dst(skb) ? skb_dst(skb)->dev : skb->dev;

return __udp4_lib_lookup(dev_net(dev), iph->saddr, sport,
iph->daddr, dport, inet_iif(skb),
&udp_table, skb);
}
EXPORT_SYMBOL_GPL(udp4_lib_lookup_skb);

/* Must be called under rcu_read_lock().
* Does increment socket refcount.
*/
Expand Down
13 changes: 13 additions & 0 deletions net/ipv6/udp.c
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,19 @@ static struct sock *__udp6_lib_lookup_skb(struct sk_buff *skb,
udptable, skb);
}

struct sock *udp6_lib_lookup_skb(struct sk_buff *skb,
__be16 sport, __be16 dport)
{
const struct ipv6hdr *iph = ipv6_hdr(skb);
const struct net_device *dev =
skb_dst(skb) ? skb_dst(skb)->dev : skb->dev;

return __udp6_lib_lookup(dev_net(dev), &iph->saddr, sport,
&iph->daddr, dport, inet6_iif(skb),
&udp_table, skb);
}
EXPORT_SYMBOL_GPL(udp6_lib_lookup_skb);

/* Must be called under rcu_read_lock().
* Does increment socket refcount.
*/
Expand Down

0 comments on commit 6305830

Please sign in to comment.