Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[IPv6] RAW: Compact the API for the kernel

Same as in the previous patch for ipv4, compact the
API and hide hash table and rwlock inside the raw.c
file.

Plus fix some "bad" places from checkpatch.pl point
of view (assignments inside if()).

Signed-off-by: Pavel Emelyanov <xemul@openvz.org>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Pavel Emelyanov and committed by
David S. Miller
69d6da0b 7bc54c90

+51 -44
+3 -16
include/net/rawv6.h
··· 5 5 6 6 #include <net/protocol.h> 7 7 8 - #define RAWV6_HTABLE_SIZE MAX_INET_PROTOS 9 - extern struct hlist_head raw_v6_htable[RAWV6_HTABLE_SIZE]; 10 - extern rwlock_t raw_v6_lock; 11 - 12 - extern int ipv6_raw_deliver(struct sk_buff *skb, int nexthdr); 13 - 14 - extern struct sock *__raw_v6_lookup(struct sock *sk, unsigned short num, 15 - struct in6_addr *loc_addr, struct in6_addr *rmt_addr, 16 - int dif); 8 + void raw6_icmp_error(struct sk_buff *, int nexthdr, 9 + int type, int code, int inner_offset, __be32); 10 + int raw6_local_deliver(struct sk_buff *, int); 17 11 18 12 extern int rawv6_rcv(struct sock *sk, 19 13 struct sk_buff *skb); 20 - 21 - 22 - extern void rawv6_err(struct sock *sk, 23 - struct sk_buff *skb, 24 - struct inet6_skb_parm *opt, 25 - int type, int code, 26 - int offset, __be32 info); 27 14 28 15 #if defined(CONFIG_IPV6_MIP6) || defined(CONFIG_IPV6_MIP6_MODULE) 29 16 int rawv6_mh_filter_register(int (*filter)(struct sock *sock,
+1 -14
net/ipv6/icmp.c
··· 555 555 556 556 static void icmpv6_notify(struct sk_buff *skb, int type, int code, __be32 info) 557 557 { 558 - struct in6_addr *saddr, *daddr; 559 558 struct inet6_protocol *ipprot; 560 - struct sock *sk; 561 559 int inner_offset; 562 560 int hash; 563 561 u8 nexthdr; ··· 577 579 if (!pskb_may_pull(skb, inner_offset+8)) 578 580 return; 579 581 580 - saddr = &ipv6_hdr(skb)->saddr; 581 - daddr = &ipv6_hdr(skb)->daddr; 582 - 583 582 /* BUGGG_FUTURE: we should try to parse exthdrs in this packet. 584 583 Without this we will not able f.e. to make source routed 585 584 pmtu discovery. ··· 592 597 ipprot->err_handler(skb, NULL, type, code, inner_offset, info); 593 598 rcu_read_unlock(); 594 599 595 - read_lock(&raw_v6_lock); 596 - if ((sk = sk_head(&raw_v6_htable[hash])) != NULL) { 597 - while ((sk = __raw_v6_lookup(sk, nexthdr, saddr, daddr, 598 - IP6CB(skb)->iif))) { 599 - rawv6_err(sk, skb, NULL, type, code, inner_offset, info); 600 - sk = sk_next(sk); 601 - } 602 - } 603 - read_unlock(&raw_v6_lock); 600 + raw6_icmp_error(skb, nexthdr, type, code, inner_offset, info); 604 601 } 605 602 606 603 /*
+3 -6
net/ipv6/ip6_input.c
··· 153 153 static int ip6_input_finish(struct sk_buff *skb) 154 154 { 155 155 struct inet6_protocol *ipprot; 156 - struct sock *raw_sk; 157 156 unsigned int nhoff; 158 - int nexthdr; 157 + int nexthdr, raw; 159 158 u8 hash; 160 159 struct inet6_dev *idev; 161 160 ··· 170 171 nhoff = IP6CB(skb)->nhoff; 171 172 nexthdr = skb_network_header(skb)[nhoff]; 172 173 173 - raw_sk = sk_head(&raw_v6_htable[nexthdr & (MAX_INET_PROTOS - 1)]); 174 - if (raw_sk && !ipv6_raw_deliver(skb, nexthdr)) 175 - raw_sk = NULL; 174 + raw = raw6_local_deliver(skb, nexthdr); 176 175 177 176 hash = nexthdr & (MAX_INET_PROTOS - 1); 178 177 if ((ipprot = rcu_dereference(inet6_protos[hash])) != NULL) { ··· 203 206 else if (ret == 0) 204 207 IP6_INC_STATS_BH(idev, IPSTATS_MIB_INDELIVERS); 205 208 } else { 206 - if (!raw_sk) { 209 + if (!raw) { 207 210 if (xfrm6_policy_check(NULL, XFRM_POLICY_IN, skb)) { 208 211 IP6_INC_STATS_BH(idev, IPSTATS_MIB_INUNKNOWNPROTOS); 209 212 icmpv6_send(skb, ICMPV6_PARAMPROB,
+44 -8
net/ipv6/raw.c
··· 60 60 #include <linux/proc_fs.h> 61 61 #include <linux/seq_file.h> 62 62 63 - struct hlist_head raw_v6_htable[RAWV6_HTABLE_SIZE]; 64 - DEFINE_RWLOCK(raw_v6_lock); 63 + #define RAWV6_HTABLE_SIZE MAX_INET_PROTOS 64 + 65 + static struct hlist_head raw_v6_htable[RAWV6_HTABLE_SIZE]; 66 + static DEFINE_RWLOCK(raw_v6_lock); 65 67 66 68 static void raw_v6_hash(struct sock *sk) 67 69 { ··· 85 83 } 86 84 87 85 88 - /* Grumble... icmp and ip_input want to get at this... */ 89 - struct sock *__raw_v6_lookup(struct sock *sk, unsigned short num, 90 - struct in6_addr *loc_addr, struct in6_addr *rmt_addr, 91 - int dif) 86 + static struct sock *__raw_v6_lookup(struct sock *sk, unsigned short num, 87 + struct in6_addr *loc_addr, struct in6_addr *rmt_addr, int dif) 92 88 { 93 89 struct hlist_node *node; 94 90 int is_multicast = ipv6_addr_is_multicast(loc_addr); ··· 167 167 * 168 168 * Caller owns SKB so we must make clones. 169 169 */ 170 - int ipv6_raw_deliver(struct sk_buff *skb, int nexthdr) 170 + static int ipv6_raw_deliver(struct sk_buff *skb, int nexthdr) 171 171 { 172 172 struct in6_addr *saddr; 173 173 struct in6_addr *daddr; ··· 240 240 out: 241 241 read_unlock(&raw_v6_lock); 242 242 return delivered; 243 + } 244 + 245 + int raw6_local_deliver(struct sk_buff *skb, int nexthdr) 246 + { 247 + struct sock *raw_sk; 248 + 249 + raw_sk = sk_head(&raw_v6_htable[nexthdr & (MAX_INET_PROTOS - 1)]); 250 + if (raw_sk && !ipv6_raw_deliver(skb, nexthdr)) 251 + raw_sk = NULL; 252 + 253 + return raw_sk != NULL; 243 254 } 244 255 245 256 /* This cleans up af_inet6 a bit. -DaveM */ ··· 327 316 return err; 328 317 } 329 318 330 - void rawv6_err(struct sock *sk, struct sk_buff *skb, 319 + static void rawv6_err(struct sock *sk, struct sk_buff *skb, 331 320 struct inet6_skb_parm *opt, 332 321 int type, int code, int offset, __be32 info) 333 322 { ··· 359 348 sk->sk_err = err; 360 349 sk->sk_error_report(sk); 361 350 } 351 + } 352 + 353 + void raw6_icmp_error(struct sk_buff *skb, int nexthdr, 354 + int type, int code, int inner_offset, __be32 info) 355 + { 356 + struct sock *sk; 357 + int hash; 358 + struct in6_addr *saddr, *daddr; 359 + 360 + hash = nexthdr & (RAWV6_HTABLE_SIZE - 1); 361 + 362 + read_lock(&raw_v6_lock); 363 + sk = sk_head(&raw_v6_htable[hash]); 364 + if (sk != NULL) { 365 + saddr = &ipv6_hdr(skb)->saddr; 366 + daddr = &ipv6_hdr(skb)->daddr; 367 + 368 + while ((sk = __raw_v6_lookup(sk, nexthdr, saddr, daddr, 369 + IP6CB(skb)->iif))) { 370 + rawv6_err(sk, skb, NULL, type, code, 371 + inner_offset, info); 372 + sk = sk_next(sk); 373 + } 374 + } 375 + read_unlock(&raw_v6_lock); 362 376 } 363 377 364 378 static inline int rawv6_rcv_skb(struct sock * sk, struct sk_buff * skb)