summaryrefslogtreecommitdiff
path: root/net/smcroute/files/patch-mroute-api.c
blob: 8158d37c136abecd30b2d03f309cffdc8a97a431 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
--- mroute-api.c.orig	2016-02-17 21:02:06 UTC
+++ mroute-api.c
@@ -98,13 +98,26 @@ int mroute4_enable(void)
 	unsigned int i;
 	struct iface *iface;
 
+#ifdef SOCK_CLOEXEC
 	mroute4_socket = socket(AF_INET, SOCK_RAW | SOCK_CLOEXEC, IPPROTO_IGMP);
+#else
+	mroute4_socket = socket(AF_INET, SOCK_RAW, IPPROTO_IGMP);
+#endif
 	if (mroute4_socket < 0) {
 		if (ENOPROTOOPT == errno)
 			smclog(LOG_WARNING, "Kernel does not support IPv4 multicast routing, skipping ...");
 
 		return -1;
 	}
+#ifndef SOCK_CLOEXEC
+	if (fcntl(mroute4_socket, F_SETFD, FD_CLOEXEC) < 0) {
+		smclog(LOG_INIT, "Failed initializing IPv4 multicast routing API: %m");
+		close(mroute4_socket);
+		mroute4_socket = -1;
+
+		return -1;
+	}
+#endif
 
 	if (setsockopt(mroute4_socket, IPPROTO_IP, MRT_INIT, (void *)&arg, sizeof(arg))) {
 		switch (errno) {
@@ -472,12 +485,25 @@ int mroute6_enable(void)
 	unsigned int i;
 	struct iface *iface;
 
+#ifdef SOCK_CLOEXEC
 	if ((mroute6_socket = socket(AF_INET6, SOCK_RAW | SOCK_CLOEXEC, IPPROTO_ICMPV6)) < 0) {
+#else
+	if ((mroute6_socket = socket(AF_INET6, SOCK_RAW, IPPROTO_ICMPV6)) < 0) {
+#endif
 		if (ENOPROTOOPT == errno)
 			smclog(LOG_WARNING, "Kernel does not support IPv6 multicast routing, skipping ...");
 
 		return -1;
 	}
+#ifndef SOCK_CLOEXEC
+	if (fcntl(mroute6_socket, F_SETFD, FD_CLOEXEC) < 0) {
+		smclog(LOG_INIT, "Failed initializing IPv6 multicast routing API: %m");
+		close(mroute6_socket);
+		mroute6_socket = -1;
+
+		return -1;
+	}
+#endif
 	if (setsockopt(mroute6_socket, IPPROTO_IPV6, MRT6_INIT, (void *)&arg, sizeof(arg))) {
 		switch (errno) {
 		case EADDRINUSE: