Commit 248b238dc960a42aa235057ba0a51a98ae2b0f0d

Authored by Daniel Lezcano
Committed by David S. Miller
1 parent 0a3e78ac2c

[IPV6]: make extended headers to return an error at initialization

This patch factorize the code for the differents init functions for rthdr,
nodata, destopt in a single function exthdrs_init.
This function returns an error so the af_inet6 module can check correctly
the initialization.

Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

Showing 3 changed files with 48 additions and 31 deletions Side-by-side Diff

include/net/transp_v6.h
... ... @@ -17,10 +17,9 @@
17 17 struct flowi;
18 18  
19 19 /* extention headers */
20   -extern void ipv6_rthdr_init(void);
  20 +extern int ipv6_exthdrs_init(void);
  21 +extern void ipv6_exthdrs_exit(void);
21 22 extern void ipv6_frag_init(void);
22   -extern void ipv6_nodata_init(void);
23   -extern void ipv6_destopt_init(void);
24 23  
25 24 /* transport protocols */
26 25 extern void rawv6_init(void);
... ... @@ -859,10 +859,11 @@
859 859 goto addrconf_fail;
860 860  
861 861 /* Init v6 extension headers. */
862   - ipv6_rthdr_init();
  862 + err = ipv6_exthdrs_init();
  863 + if (err)
  864 + goto ipv6_exthdrs_fail;
  865 +
863 866 ipv6_frag_init();
864   - ipv6_nodata_init();
865   - ipv6_destopt_init();
866 867  
867 868 /* Init v6 transport protocols. */
868 869 udpv6_init();
... ... @@ -874,6 +875,8 @@
874 875 out:
875 876 return err;
876 877  
  878 +ipv6_exthdrs_fail:
  879 + addrconf_cleanup();
877 880 addrconf_fail:
878 881 ip6_flowlabel_cleanup();
879 882 ip6_flowlabel_fail:
... ... @@ -932,6 +935,7 @@
932 935 /* Cleanup code parts. */
933 936 ipv6_packet_cleanup();
934 937  
  938 + ipv6_exthdrs_exit();
935 939 addrconf_cleanup();
936 940 ip6_flowlabel_cleanup();
937 941 ip6_route_cleanup();
... ... @@ -308,28 +308,6 @@
308 308 return -1;
309 309 }
310 310  
311   -static struct inet6_protocol destopt_protocol = {
312   - .handler = ipv6_destopt_rcv,
313   - .flags = INET6_PROTO_NOPOLICY | INET6_PROTO_GSO_EXTHDR,
314   -};
315   -
316   -void __init ipv6_destopt_init(void)
317   -{
318   - if (inet6_add_protocol(&destopt_protocol, IPPROTO_DSTOPTS) < 0)
319   - printk(KERN_ERR "ipv6_destopt_init: Could not register protocol\n");
320   -}
321   -
322   -static struct inet6_protocol nodata_protocol = {
323   - .handler = dst_discard,
324   - .flags = INET6_PROTO_NOPOLICY,
325   -};
326   -
327   -void __init ipv6_nodata_init(void)
328   -{
329   - if (inet6_add_protocol(&nodata_protocol, IPPROTO_NONE) < 0)
330   - printk(KERN_ERR "ipv6_nodata_init: Could not register protocol\n");
331   -}
332   -
333 311 /********************************
334 312 Routing header.
335 313 ********************************/
336 314  
337 315  
... ... @@ -527,11 +505,47 @@
527 505 .flags = INET6_PROTO_NOPOLICY | INET6_PROTO_GSO_EXTHDR,
528 506 };
529 507  
530   -void __init ipv6_rthdr_init(void)
  508 +static struct inet6_protocol destopt_protocol = {
  509 + .handler = ipv6_destopt_rcv,
  510 + .flags = INET6_PROTO_NOPOLICY | INET6_PROTO_GSO_EXTHDR,
  511 +};
  512 +
  513 +static struct inet6_protocol nodata_protocol = {
  514 + .handler = dst_discard,
  515 + .flags = INET6_PROTO_NOPOLICY,
  516 +};
  517 +
  518 +int __init ipv6_exthdrs_init(void)
531 519 {
532   - if (inet6_add_protocol(&rthdr_protocol, IPPROTO_ROUTING) < 0)
533   - printk(KERN_ERR "ipv6_rthdr_init: Could not register protocol\n");
  520 + int ret;
  521 +
  522 + ret = inet6_add_protocol(&rthdr_protocol, IPPROTO_ROUTING);
  523 + if (ret)
  524 + goto out;
  525 +
  526 + ret = inet6_add_protocol(&destopt_protocol, IPPROTO_DSTOPTS);
  527 + if (ret)
  528 + goto out_rthdr;
  529 +
  530 + ret = inet6_add_protocol(&nodata_protocol, IPPROTO_NONE);
  531 + if (ret)
  532 + goto out_destopt;
  533 +
  534 +out:
  535 + return ret;
  536 +out_rthdr:
  537 + inet6_del_protocol(&rthdr_protocol, IPPROTO_ROUTING);
  538 +out_destopt:
  539 + inet6_del_protocol(&destopt_protocol, IPPROTO_DSTOPTS);
  540 + goto out;
534 541 };
  542 +
  543 +void ipv6_exthdrs_exit(void)
  544 +{
  545 + inet6_del_protocol(&nodata_protocol, IPPROTO_NONE);
  546 + inet6_del_protocol(&destopt_protocol, IPPROTO_DSTOPTS);
  547 + inet6_del_protocol(&rthdr_protocol, IPPROTO_ROUTING);
  548 +}
535 549  
536 550 /**********************************
537 551 Hop-by-hop options.