Skip to content

Commit 7f4e486

Browse files
Daniel Lezcanodavem330
authored andcommitted
[IPV6]: make the protocol initialization to return an error code
This patchset makes the different protocols to return an error code, so the af_inet6 module can check the initialization was correct or not. The raw6 was taken into account to be consistent with the rest of the protocols, but the registration is at the same place. Because the raw6 has its own init function, the proto and the ops structure can be moved inside the raw6.c file. Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 87c3efb commit 7f4e486

8 files changed

Lines changed: 168 additions & 65 deletions

File tree

‎include/net/ipv6.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ extern int compat_ipv6_getsockopt(struct sock *sk,
545545
char __user *optval,
546546
int __user *optlen);
547547

548-
extern void ipv6_packet_init(void);
548+
extern int ipv6_packet_init(void);
549549

550550
extern void ipv6_packet_cleanup(void);
551551

‎include/net/transp_v6.h‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,14 @@ extern int ipv6_frag_init(void);
2323
extern void ipv6_frag_exit(void);
2424

2525
/* transport protocols */
26-
extern void rawv6_init(void);
27-
extern void udpv6_init(void);
28-
extern void udplitev6_init(void);
29-
extern void tcpv6_init(void);
26+
extern int rawv6_init(void);
27+
extern void rawv6_exit(void);
28+
extern int udpv6_init(void);
29+
extern void udpv6_exit(void);
30+
extern int udplitev6_init(void);
31+
extern void udplitev6_exit(void);
32+
extern int tcpv6_init(void);
33+
extern void tcpv6_exit(void);
3034

3135
extern int udpv6_connect(struct sock *sk,
3236
struct sockaddr *uaddr,

‎net/ipv6/af_inet6.c‎

Lines changed: 33 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -529,42 +529,6 @@ static struct net_proto_family inet6_family_ops = {
529529
.owner = THIS_MODULE,
530530
};
531531

532-
/* Same as inet6_dgram_ops, sans udp_poll. */
533-
static const struct proto_ops inet6_sockraw_ops = {
534-
.family = PF_INET6,
535-
.owner = THIS_MODULE,
536-
.release = inet6_release,
537-
.bind = inet6_bind,
538-
.connect = inet_dgram_connect, /* ok */
539-
.socketpair = sock_no_socketpair, /* a do nothing */
540-
.accept = sock_no_accept, /* a do nothing */
541-
.getname = inet6_getname,
542-
.poll = datagram_poll, /* ok */
543-
.ioctl = inet6_ioctl, /* must change */
544-
.listen = sock_no_listen, /* ok */
545-
.shutdown = inet_shutdown, /* ok */
546-
.setsockopt = sock_common_setsockopt, /* ok */
547-
.getsockopt = sock_common_getsockopt, /* ok */
548-
.sendmsg = inet_sendmsg, /* ok */
549-
.recvmsg = sock_common_recvmsg, /* ok */
550-
.mmap = sock_no_mmap,
551-
.sendpage = sock_no_sendpage,
552-
#ifdef CONFIG_COMPAT
553-
.compat_setsockopt = compat_sock_common_setsockopt,
554-
.compat_getsockopt = compat_sock_common_getsockopt,
555-
#endif
556-
};
557-
558-
static struct inet_protosw rawv6_protosw = {
559-
.type = SOCK_RAW,
560-
.protocol = IPPROTO_IP, /* wild card */
561-
.prot = &rawv6_prot,
562-
.ops = &inet6_sockraw_ops,
563-
.capability = CAP_NET_RAW,
564-
.no_check = UDP_CSUM_DEFAULT,
565-
.flags = INET_PROTOSW_REUSE,
566-
};
567-
568532
int inet6_register_protosw(struct inet_protosw *p)
569533
{
570534
struct list_head *lh;
@@ -771,7 +735,6 @@ static int __init inet6_init(void)
771735
__this_module.can_unload = &ipv6_unload;
772736
#endif
773737
#endif
774-
775738
err = proto_register(&tcpv6_prot, 1);
776739
if (err)
777740
goto out;
@@ -796,14 +759,16 @@ static int __init inet6_init(void)
796759
/* We MUST register RAW sockets before we create the ICMP6,
797760
* IGMP6, or NDISC control sockets.
798761
*/
799-
inet6_register_protosw(&rawv6_protosw);
762+
err = rawv6_init();
763+
if (err)
764+
goto out_unregister_raw_proto;
800765

801766
/* Register the family here so that the init calls below will
802767
* be able to create sockets. (?? is this dangerous ??)
803768
*/
804769
err = sock_register(&inet6_family_ops);
805770
if (err)
806-
goto out_unregister_raw_proto;
771+
goto out_sock_register_fail;
807772

808773
/* Initialise ipv6 mibs */
809774
err = init_ipv6_mibs();
@@ -871,15 +836,32 @@ static int __init inet6_init(void)
871836
goto ipv6_frag_fail;
872837

873838
/* Init v6 transport protocols. */
874-
udpv6_init();
875-
udplitev6_init();
876-
tcpv6_init();
839+
err = udpv6_init();
840+
if (err)
841+
goto udpv6_fail;
877842

878-
ipv6_packet_init();
879-
err = 0;
843+
err = udplitev6_init();
844+
if (err)
845+
goto udplitev6_fail;
846+
847+
err = tcpv6_init();
848+
if (err)
849+
goto tcpv6_fail;
850+
851+
err = ipv6_packet_init();
852+
if (err)
853+
goto ipv6_packet_fail;
880854
out:
881855
return err;
882856

857+
ipv6_packet_fail:
858+
tcpv6_exit();
859+
tcpv6_fail:
860+
udplitev6_exit();
861+
udplitev6_fail:
862+
udpv6_exit();
863+
udpv6_fail:
864+
ipv6_frag_exit();
883865
ipv6_frag_fail:
884866
ipv6_exthdrs_exit();
885867
ipv6_exthdrs_fail:
@@ -920,6 +902,8 @@ static int __init inet6_init(void)
920902
out_unregister_sock:
921903
sock_unregister(PF_INET6);
922904
rtnl_unregister_all(PF_INET6);
905+
out_sock_register_fail:
906+
rawv6_exit();
923907
out_unregister_raw_proto:
924908
proto_unregister(&rawv6_prot);
925909
out_unregister_udplite_proto:
@@ -939,6 +923,10 @@ static void __exit inet6_exit(void)
939923
/* Disallow any further netlink messages */
940924
rtnl_unregister_all(PF_INET6);
941925

926+
udpv6_exit();
927+
udplitev6_exit();
928+
tcpv6_exit();
929+
942930
/* Cleanup code parts. */
943931
ipv6_packet_cleanup();
944932
ipv6_frag_exit();
@@ -961,6 +949,7 @@ static void __exit inet6_exit(void)
961949
igmp6_cleanup();
962950
ndisc_cleanup();
963951
icmpv6_cleanup();
952+
rawv6_exit();
964953
#ifdef CONFIG_SYSCTL
965954
ipv6_sysctl_unregister();
966955
#endif

‎net/ipv6/ipv6_sockglue.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1128,9 +1128,10 @@ int compat_ipv6_getsockopt(struct sock *sk, int level, int optname,
11281128
EXPORT_SYMBOL(compat_ipv6_getsockopt);
11291129
#endif
11301130

1131-
void __init ipv6_packet_init(void)
1131+
int __init ipv6_packet_init(void)
11321132
{
11331133
dev_add_pack(&ipv6_packet_type);
1134+
return 0;
11341135
}
11351136

11361137
void ipv6_packet_cleanup(void)

‎net/ipv6/raw.c‎

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1273,3 +1273,55 @@ void raw6_proc_exit(void)
12731273
proc_net_remove(&init_net, "raw6");
12741274
}
12751275
#endif /* CONFIG_PROC_FS */
1276+
1277+
/* Same as inet6_dgram_ops, sans udp_poll. */
1278+
static const struct proto_ops inet6_sockraw_ops = {
1279+
.family = PF_INET6,
1280+
.owner = THIS_MODULE,
1281+
.release = inet6_release,
1282+
.bind = inet6_bind,
1283+
.connect = inet_dgram_connect, /* ok */
1284+
.socketpair = sock_no_socketpair, /* a do nothing */
1285+
.accept = sock_no_accept, /* a do nothing */
1286+
.getname = inet6_getname,
1287+
.poll = datagram_poll, /* ok */
1288+
.ioctl = inet6_ioctl, /* must change */
1289+
.listen = sock_no_listen, /* ok */
1290+
.shutdown = inet_shutdown, /* ok */
1291+
.setsockopt = sock_common_setsockopt, /* ok */
1292+
.getsockopt = sock_common_getsockopt, /* ok */
1293+
.sendmsg = inet_sendmsg, /* ok */
1294+
.recvmsg = sock_common_recvmsg, /* ok */
1295+
.mmap = sock_no_mmap,
1296+
.sendpage = sock_no_sendpage,
1297+
#ifdef CONFIG_COMPAT
1298+
.compat_setsockopt = compat_sock_common_setsockopt,
1299+
.compat_getsockopt = compat_sock_common_getsockopt,
1300+
#endif
1301+
};
1302+
1303+
static struct inet_protosw rawv6_protosw = {
1304+
.type = SOCK_RAW,
1305+
.protocol = IPPROTO_IP, /* wild card */
1306+
.prot = &rawv6_prot,
1307+
.ops = &inet6_sockraw_ops,
1308+
.capability = CAP_NET_RAW,
1309+
.no_check = UDP_CSUM_DEFAULT,
1310+
.flags = INET_PROTOSW_REUSE,
1311+
};
1312+
1313+
int __init rawv6_init(void)
1314+
{
1315+
int ret;
1316+
1317+
ret = inet6_register_protosw(&rawv6_protosw);
1318+
if (ret)
1319+
goto out;
1320+
out:
1321+
return ret;
1322+
}
1323+
1324+
void __exit rawv6_exit(void)
1325+
{
1326+
inet6_unregister_protosw(&rawv6_protosw);
1327+
}

‎net/ipv6/tcp_ipv6.c‎

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2166,14 +2166,36 @@ static struct inet_protosw tcpv6_protosw = {
21662166
INET_PROTOSW_ICSK,
21672167
};
21682168

2169-
void __init tcpv6_init(void)
2169+
int __init tcpv6_init(void)
21702170
{
2171+
int ret;
2172+
2173+
ret = inet6_add_protocol(&tcpv6_protocol, IPPROTO_TCP);
2174+
if (ret)
2175+
goto out;
2176+
21712177
/* register inet6 protocol */
2172-
if (inet6_add_protocol(&tcpv6_protocol, IPPROTO_TCP) < 0)
2173-
printk(KERN_ERR "tcpv6_init: Could not register protocol\n");
2174-
inet6_register_protosw(&tcpv6_protosw);
2178+
ret = inet6_register_protosw(&tcpv6_protosw);
2179+
if (ret)
2180+
goto out_tcpv6_protocol;
2181+
2182+
ret = inet_csk_ctl_sock_create(&tcp6_socket, PF_INET6,
2183+
SOCK_RAW, IPPROTO_TCP);
2184+
if (ret)
2185+
goto out_tcpv6_protosw;
2186+
out:
2187+
return ret;
21752188

2176-
if (inet_csk_ctl_sock_create(&tcp6_socket, PF_INET6, SOCK_RAW,
2177-
IPPROTO_TCP) < 0)
2178-
panic("Failed to create the TCPv6 control socket.\n");
2189+
out_tcpv6_protocol:
2190+
inet6_del_protocol(&tcpv6_protocol, IPPROTO_TCP);
2191+
out_tcpv6_protosw:
2192+
inet6_unregister_protosw(&tcpv6_protosw);
2193+
goto out;
2194+
}
2195+
2196+
void __exit tcpv6_exit(void)
2197+
{
2198+
sock_release(tcp6_socket);
2199+
inet6_unregister_protosw(&tcpv6_protosw);
2200+
inet6_del_protocol(&tcpv6_protocol, IPPROTO_TCP);
21792201
}

‎net/ipv6/udp.c‎

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,9 +1016,27 @@ static struct inet_protosw udpv6_protosw = {
10161016
};
10171017

10181018

1019-
void __init udpv6_init(void)
1019+
int __init udpv6_init(void)
10201020
{
1021-
if (inet6_add_protocol(&udpv6_protocol, IPPROTO_UDP) < 0)
1022-
printk(KERN_ERR "udpv6_init: Could not register protocol\n");
1023-
inet6_register_protosw(&udpv6_protosw);
1021+
int ret;
1022+
1023+
ret = inet6_add_protocol(&udpv6_protocol, IPPROTO_UDP);
1024+
if (ret)
1025+
goto out;
1026+
1027+
ret = inet6_register_protosw(&udpv6_protosw);
1028+
if (ret)
1029+
goto out_udpv6_protocol;
1030+
out:
1031+
return ret;
1032+
1033+
out_udpv6_protocol:
1034+
inet6_del_protocol(&udpv6_protocol, IPPROTO_UDP);
1035+
goto out;
1036+
}
1037+
1038+
void __exit udpv6_exit(void)
1039+
{
1040+
inet6_unregister_protosw(&udpv6_protosw);
1041+
inet6_del_protocol(&udpv6_protocol, IPPROTO_UDP);
10241042
}

‎net/ipv6/udplite.c‎

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,29 @@ static struct inet_protosw udplite6_protosw = {
7777
.flags = INET_PROTOSW_PERMANENT,
7878
};
7979

80-
void __init udplitev6_init(void)
80+
int __init udplitev6_init(void)
8181
{
82-
if (inet6_add_protocol(&udplitev6_protocol, IPPROTO_UDPLITE) < 0)
83-
printk(KERN_ERR "%s: Could not register.\n", __FUNCTION__);
82+
int ret;
8483

85-
inet6_register_protosw(&udplite6_protosw);
84+
ret = inet6_add_protocol(&udplitev6_protocol, IPPROTO_UDPLITE);
85+
if (ret)
86+
goto out;
87+
88+
ret = inet6_register_protosw(&udplite6_protosw);
89+
if (ret)
90+
goto out_udplitev6_protocol;
91+
out:
92+
return ret;
93+
94+
out_udplitev6_protocol:
95+
inet6_del_protocol(&udplitev6_protocol, IPPROTO_UDPLITE);
96+
goto out;
97+
}
98+
99+
void __exit udplitev6_exit(void)
100+
{
101+
inet6_unregister_protosw(&udplite6_protosw);
102+
inet6_del_protocol(&udplitev6_protocol, IPPROTO_UDPLITE);
86103
}
87104

88105
#ifdef CONFIG_PROC_FS

0 commit comments

Comments
 (0)