Commit 68cb7d53 authored by Paolo Abeni's avatar Paolo Abeni Committed by David S. Miller

ip: factor out protocol delivery helper

So that we can re-use it at the UDP level in a later patch

rfc v3 -> v1
 - add the helper declaration into the ip header
Signed-off-by: default avatarPaolo Abeni <pabeni@redhat.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent bcd1665e
...@@ -155,6 +155,7 @@ int ip_rcv(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt, ...@@ -155,6 +155,7 @@ int ip_rcv(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt,
void ip_list_rcv(struct list_head *head, struct packet_type *pt, void ip_list_rcv(struct list_head *head, struct packet_type *pt,
struct net_device *orig_dev); struct net_device *orig_dev);
int ip_local_deliver(struct sk_buff *skb); int ip_local_deliver(struct sk_buff *skb);
void ip_protocol_deliver_rcu(struct net *net, struct sk_buff *skb, int proto);
int ip_mr_input(struct sk_buff *skb); int ip_mr_input(struct sk_buff *skb);
int ip_output(struct net *net, struct sock *sk, struct sk_buff *skb); int ip_output(struct net *net, struct sock *sk, struct sk_buff *skb);
int ip_mc_output(struct net *net, struct sock *sk, struct sk_buff *skb); int ip_mc_output(struct net *net, struct sock *sk, struct sk_buff *skb);
......
...@@ -188,51 +188,50 @@ bool ip_call_ra_chain(struct sk_buff *skb) ...@@ -188,51 +188,50 @@ bool ip_call_ra_chain(struct sk_buff *skb)
return false; return false;
} }
static int ip_local_deliver_finish(struct net *net, struct sock *sk, struct sk_buff *skb) void ip_protocol_deliver_rcu(struct net *net, struct sk_buff *skb, int protocol)
{ {
__skb_pull(skb, skb_network_header_len(skb)); const struct net_protocol *ipprot;
int raw, ret;
rcu_read_lock();
{
int protocol = ip_hdr(skb)->protocol;
const struct net_protocol *ipprot;
int raw;
resubmit: resubmit:
raw = raw_local_deliver(skb, protocol); raw = raw_local_deliver(skb, protocol);
ipprot = rcu_dereference(inet_protos[protocol]); ipprot = rcu_dereference(inet_protos[protocol]);
if (ipprot) { if (ipprot) {
int ret; if (!ipprot->no_policy) {
if (!xfrm4_policy_check(NULL, XFRM_POLICY_IN, skb)) {
if (!ipprot->no_policy) { kfree_skb(skb);
if (!xfrm4_policy_check(NULL, XFRM_POLICY_IN, skb)) { return;
kfree_skb(skb);
goto out;
}
nf_reset(skb);
} }
ret = ipprot->handler(skb); nf_reset(skb);
if (ret < 0) { }
protocol = -ret; ret = ipprot->handler(skb);
goto resubmit; if (ret < 0) {
protocol = -ret;
goto resubmit;
}
__IP_INC_STATS(net, IPSTATS_MIB_INDELIVERS);
} else {
if (!raw) {
if (xfrm4_policy_check(NULL, XFRM_POLICY_IN, skb)) {
__IP_INC_STATS(net, IPSTATS_MIB_INUNKNOWNPROTOS);
icmp_send(skb, ICMP_DEST_UNREACH,
ICMP_PROT_UNREACH, 0);
} }
__IP_INC_STATS(net, IPSTATS_MIB_INDELIVERS); kfree_skb(skb);
} else { } else {
if (!raw) { __IP_INC_STATS(net, IPSTATS_MIB_INDELIVERS);
if (xfrm4_policy_check(NULL, XFRM_POLICY_IN, skb)) { consume_skb(skb);
__IP_INC_STATS(net, IPSTATS_MIB_INUNKNOWNPROTOS);
icmp_send(skb, ICMP_DEST_UNREACH,
ICMP_PROT_UNREACH, 0);
}
kfree_skb(skb);
} else {
__IP_INC_STATS(net, IPSTATS_MIB_INDELIVERS);
consume_skb(skb);
}
} }
} }
out: }
static int ip_local_deliver_finish(struct net *net, struct sock *sk, struct sk_buff *skb)
{
__skb_pull(skb, skb_network_header_len(skb));
rcu_read_lock();
ip_protocol_deliver_rcu(net, skb, ip_hdr(skb)->protocol);
rcu_read_unlock(); rcu_read_unlock();
return 0; return 0;
......
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