Re: [RFC PATCH v3 04/10] ip: factor out protocol delivery helper
On Thu, 2018-11-01 at 00:35 -0600, Subash Abhinov Kasiviswanathan wrote: > On 2018-10-30 11:24, Paolo Abeni wrote: > > So that we can re-use it at the UDP lavel in a later patch > > > > Hi Paolo > > Minor queries - > Should it be "level" instead of "lavel"? Similar comment for the ipv6 > patch as well. Indeed. Will fix in the next iteration. > > diff --git a/net/ipv4/ip_input.c b/net/ipv4/ip_input.c > > index 35a786c0aaa0..72250b4e466d 100644 > > --- a/net/ipv4/ip_input.c > > +++ b/net/ipv4/ip_input.c > > @@ -188,51 +188,50 @@ bool ip_call_ra_chain(struct sk_buff *skb) > > 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) > > Would it be better if this function was declared in include/net/ip.h & > include/net/ipv6.h rather than in net/ipv4/udp.c & net/ipv6/udp.c as in > the patch "udp: cope with UDP GRO packet misdirection" > > diff --git a/include/net/ip.h b/include/net/ip.h > index 72593e1..3d7fdb4 100644 > --- a/include/net/ip.h > +++ b/include/net/ip.h > @@ -717,4 +717,6 @@ static inline void ip_cmsg_recv(struct msghdr *msg, > struct sk_buff *skb) > int rtm_getroute_parse_ip_proto(struct nlattr *attr, u8 *ip_proto, > struct netlink_ext_ack *extack); > > +void ip_protocol_deliver_rcu(struct net *net, struct sk_buff *skb, int > proto); > + > #endif /* _IP_H */ > diff --git a/include/net/ipv6.h b/include/net/ipv6.h > index 8296505..4d4d2cfe 100644 > --- a/include/net/ipv6.h > +++ b/include/net/ipv6.h > @@ -1101,4 +1101,8 @@ int ipv6_sock_mc_join_ssm(struct sock *sk, int > ifindex, >const struct in6_addr *addr, unsigned int > mode); > int ipv6_sock_mc_drop(struct sock *sk, int ifindex, >const struct in6_addr *addr); > + > +void ip6_protocol_deliver_rcu(struct net *net, struct sk_buff *skb, int > nexthdr, > + bool have_final); > + > #endif /* _NET_IPV6_H */ > Agreed, I will do in the next iteration. Thanks, Paolo
Re: [RFC PATCH v3 04/10] ip: factor out protocol delivery helper
On 2018-10-30 11:24, Paolo Abeni wrote: So that we can re-use it at the UDP lavel in a later patch Hi Paolo Minor queries - Should it be "level" instead of "lavel"? Similar comment for the ipv6 patch as well. Signed-off-by: Paolo Abeni --- net/ipv4/ip_input.c | 73 ++--- 1 file changed, 36 insertions(+), 37 deletions(-) diff --git a/net/ipv4/ip_input.c b/net/ipv4/ip_input.c index 35a786c0aaa0..72250b4e466d 100644 --- a/net/ipv4/ip_input.c +++ b/net/ipv4/ip_input.c @@ -188,51 +188,50 @@ bool ip_call_ra_chain(struct sk_buff *skb) 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) Would it be better if this function was declared in include/net/ip.h & include/net/ipv6.h rather than in net/ipv4/udp.c & net/ipv6/udp.c as in the patch "udp: cope with UDP GRO packet misdirection" diff --git a/include/net/ip.h b/include/net/ip.h index 72593e1..3d7fdb4 100644 --- a/include/net/ip.h +++ b/include/net/ip.h @@ -717,4 +717,6 @@ static inline void ip_cmsg_recv(struct msghdr *msg, struct sk_buff *skb) int rtm_getroute_parse_ip_proto(struct nlattr *attr, u8 *ip_proto, struct netlink_ext_ack *extack); +void ip_protocol_deliver_rcu(struct net *net, struct sk_buff *skb, int proto); + #endif /* _IP_H */ diff --git a/include/net/ipv6.h b/include/net/ipv6.h index 8296505..4d4d2cfe 100644 --- a/include/net/ipv6.h +++ b/include/net/ipv6.h @@ -1101,4 +1101,8 @@ int ipv6_sock_mc_join_ssm(struct sock *sk, int ifindex, const struct in6_addr *addr, unsigned int mode); int ipv6_sock_mc_drop(struct sock *sk, int ifindex, const struct in6_addr *addr); + +void ip6_protocol_deliver_rcu(struct net *net, struct sk_buff *skb, int nexthdr, + bool have_final); + #endif /* _NET_IPV6_H */ -- Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project
[RFC PATCH v3 04/10] ip: factor out protocol delivery helper
So that we can re-use it at the UDP lavel in a later patch Signed-off-by: Paolo Abeni --- net/ipv4/ip_input.c | 73 ++--- 1 file changed, 36 insertions(+), 37 deletions(-) diff --git a/net/ipv4/ip_input.c b/net/ipv4/ip_input.c index 35a786c0aaa0..72250b4e466d 100644 --- a/net/ipv4/ip_input.c +++ b/net/ipv4/ip_input.c @@ -188,51 +188,50 @@ bool ip_call_ra_chain(struct sk_buff *skb) 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)); - - rcu_read_lock(); - { - int protocol = ip_hdr(skb)->protocol; - const struct net_protocol *ipprot; - int raw; + const struct net_protocol *ipprot; + int raw, ret; - resubmit: - raw = raw_local_deliver(skb, protocol); +resubmit: + raw = raw_local_deliver(skb, protocol); - ipprot = rcu_dereference(inet_protos[protocol]); - if (ipprot) { - int ret; - - if (!ipprot->no_policy) { - if (!xfrm4_policy_check(NULL, XFRM_POLICY_IN, skb)) { - kfree_skb(skb); - goto out; - } - nf_reset(skb); + ipprot = rcu_dereference(inet_protos[protocol]); + if (ipprot) { + if (!ipprot->no_policy) { + if (!xfrm4_policy_check(NULL, XFRM_POLICY_IN, skb)) { + kfree_skb(skb); + return; } - ret = ipprot->handler(skb); - if (ret < 0) { - protocol = -ret; - goto resubmit; + nf_reset(skb); + } + ret = ipprot->handler(skb); + 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 { - 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); - } - kfree_skb(skb); - } else { - __IP_INC_STATS(net, IPSTATS_MIB_INDELIVERS); - consume_skb(skb); - } + __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(); return 0; -- 2.17.2