Commit 8fb479a4 authored by Antonio Quartulli's avatar Antonio Quartulli Committed by David S. Miller

netpoll: fix rx_hook() interface by passing the skb

Right now skb->data is passed to rx_hook() even if the skb
has not been linearised and without giving rx_hook() a way
to linearise it.

Change the rx_hook() interface and make it accept the skb
and the offset to the UDP payload as arguments. rx_hook() is
also renamed to rx_skb_hook() to ensure that out of the tree
users notice the API change.

In this way any rx_skb_hook() implementation can perform all
the needed operations to properly (and safely) access the
skb data.
Signed-off-by: default avatarAntonio Quartulli <antonio@meshcoding.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent c7c6effd
...@@ -24,7 +24,8 @@ struct netpoll { ...@@ -24,7 +24,8 @@ struct netpoll {
struct net_device *dev; struct net_device *dev;
char dev_name[IFNAMSIZ]; char dev_name[IFNAMSIZ];
const char *name; const char *name;
void (*rx_hook)(struct netpoll *, int, char *, int); void (*rx_skb_hook)(struct netpoll *np, int source, struct sk_buff *skb,
int offset, int len);
union inet_addr local_ip, remote_ip; union inet_addr local_ip, remote_ip;
bool ipv6; bool ipv6;
...@@ -41,7 +42,7 @@ struct netpoll_info { ...@@ -41,7 +42,7 @@ struct netpoll_info {
unsigned long rx_flags; unsigned long rx_flags;
spinlock_t rx_lock; spinlock_t rx_lock;
struct semaphore dev_lock; struct semaphore dev_lock;
struct list_head rx_np; /* netpolls that registered an rx_hook */ struct list_head rx_np; /* netpolls that registered an rx_skb_hook */
struct sk_buff_head neigh_tx; /* list of neigh requests to reply to */ struct sk_buff_head neigh_tx; /* list of neigh requests to reply to */
struct sk_buff_head txq; struct sk_buff_head txq;
......
...@@ -636,8 +636,9 @@ static void netpoll_neigh_reply(struct sk_buff *skb, struct netpoll_info *npinfo ...@@ -636,8 +636,9 @@ static void netpoll_neigh_reply(struct sk_buff *skb, struct netpoll_info *npinfo
netpoll_send_skb(np, send_skb); netpoll_send_skb(np, send_skb);
/* If there are several rx_hooks for the same address, /* If there are several rx_skb_hooks for the same
we're fine by sending a single reply */ * address we're fine by sending a single reply
*/
break; break;
} }
spin_unlock_irqrestore(&npinfo->rx_lock, flags); spin_unlock_irqrestore(&npinfo->rx_lock, flags);
...@@ -719,8 +720,9 @@ static void netpoll_neigh_reply(struct sk_buff *skb, struct netpoll_info *npinfo ...@@ -719,8 +720,9 @@ static void netpoll_neigh_reply(struct sk_buff *skb, struct netpoll_info *npinfo
netpoll_send_skb(np, send_skb); netpoll_send_skb(np, send_skb);
/* If there are several rx_hooks for the same address, /* If there are several rx_skb_hooks for the same
we're fine by sending a single reply */ * address, we're fine by sending a single reply
*/
break; break;
} }
spin_unlock_irqrestore(&npinfo->rx_lock, flags); spin_unlock_irqrestore(&npinfo->rx_lock, flags);
...@@ -756,11 +758,12 @@ static bool pkt_is_ns(struct sk_buff *skb) ...@@ -756,11 +758,12 @@ static bool pkt_is_ns(struct sk_buff *skb)
int __netpoll_rx(struct sk_buff *skb, struct netpoll_info *npinfo) int __netpoll_rx(struct sk_buff *skb, struct netpoll_info *npinfo)
{ {
int proto, len, ulen; int proto, len, ulen, data_len;
int hits = 0; int hits = 0, offset;
const struct iphdr *iph; const struct iphdr *iph;
struct udphdr *uh; struct udphdr *uh;
struct netpoll *np, *tmp; struct netpoll *np, *tmp;
uint16_t source;
if (list_empty(&npinfo->rx_np)) if (list_empty(&npinfo->rx_np))
goto out; goto out;
...@@ -820,7 +823,10 @@ int __netpoll_rx(struct sk_buff *skb, struct netpoll_info *npinfo) ...@@ -820,7 +823,10 @@ int __netpoll_rx(struct sk_buff *skb, struct netpoll_info *npinfo)
len -= iph->ihl*4; len -= iph->ihl*4;
uh = (struct udphdr *)(((char *)iph) + iph->ihl*4); uh = (struct udphdr *)(((char *)iph) + iph->ihl*4);
offset = (unsigned char *)(uh + 1) - skb->data;
ulen = ntohs(uh->len); ulen = ntohs(uh->len);
data_len = skb->len - offset;
source = ntohs(uh->source);
if (ulen != len) if (ulen != len)
goto out; goto out;
...@@ -834,9 +840,7 @@ int __netpoll_rx(struct sk_buff *skb, struct netpoll_info *npinfo) ...@@ -834,9 +840,7 @@ int __netpoll_rx(struct sk_buff *skb, struct netpoll_info *npinfo)
if (np->local_port && np->local_port != ntohs(uh->dest)) if (np->local_port && np->local_port != ntohs(uh->dest))
continue; continue;
np->rx_hook(np, ntohs(uh->source), np->rx_skb_hook(np, source, skb, offset, data_len);
(char *)(uh+1),
ulen - sizeof(struct udphdr));
hits++; hits++;
} }
} else { } else {
...@@ -859,7 +863,10 @@ int __netpoll_rx(struct sk_buff *skb, struct netpoll_info *npinfo) ...@@ -859,7 +863,10 @@ int __netpoll_rx(struct sk_buff *skb, struct netpoll_info *npinfo)
if (!pskb_may_pull(skb, sizeof(struct udphdr))) if (!pskb_may_pull(skb, sizeof(struct udphdr)))
goto out; goto out;
uh = udp_hdr(skb); uh = udp_hdr(skb);
offset = (unsigned char *)(uh + 1) - skb->data;
ulen = ntohs(uh->len); ulen = ntohs(uh->len);
data_len = skb->len - offset;
source = ntohs(uh->source);
if (ulen != skb->len) if (ulen != skb->len)
goto out; goto out;
if (udp6_csum_init(skb, uh, IPPROTO_UDP)) if (udp6_csum_init(skb, uh, IPPROTO_UDP))
...@@ -872,9 +879,7 @@ int __netpoll_rx(struct sk_buff *skb, struct netpoll_info *npinfo) ...@@ -872,9 +879,7 @@ int __netpoll_rx(struct sk_buff *skb, struct netpoll_info *npinfo)
if (np->local_port && np->local_port != ntohs(uh->dest)) if (np->local_port && np->local_port != ntohs(uh->dest))
continue; continue;
np->rx_hook(np, ntohs(uh->source), np->rx_skb_hook(np, source, skb, offset, data_len);
(char *)(uh+1),
ulen - sizeof(struct udphdr));
hits++; hits++;
} }
#endif #endif
...@@ -1062,7 +1067,7 @@ int __netpoll_setup(struct netpoll *np, struct net_device *ndev, gfp_t gfp) ...@@ -1062,7 +1067,7 @@ int __netpoll_setup(struct netpoll *np, struct net_device *ndev, gfp_t gfp)
npinfo->netpoll = np; npinfo->netpoll = np;
if (np->rx_hook) { if (np->rx_skb_hook) {
spin_lock_irqsave(&npinfo->rx_lock, flags); spin_lock_irqsave(&npinfo->rx_lock, flags);
npinfo->rx_flags |= NETPOLL_RX_ENABLED; npinfo->rx_flags |= NETPOLL_RX_ENABLED;
list_add_tail(&np->rx, &npinfo->rx_np); list_add_tail(&np->rx, &npinfo->rx_np);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment