70
#define get_inet6_sysctl(code) inet6_sysctl(code, 0, 0)
71
#define set_inet6_sysctl(code, val) inet6_sysctl(code, val, 1)
57
inet6_sysctl(int code)
73
inet6_sysctl(int code, int val, int action)
59
75
int mib[] = { CTL_NET, PF_INET6, IPPROTO_IPV6, 0 };
64
79
size = sizeof(val);
81
if (sysctl(mib, sizeof(mib)/sizeof(mib[0]),
82
NULL, 0, &val, size) == -1)
65
86
if (sysctl(mib, sizeof(mib)/sizeof(mib[0]), &val, &size, NULL, 0) == -1)
92
restore_kernel_ra(void)
95
if (options & DHCPCD_FORKED)
97
syslog(LOG_INFO, "restoring Kernel IPv6 RA support");
98
if (set_inet6_sysctl(IPV6CTL_ACCEPT_RTADV, 1) == -1)
99
syslog(LOG_ERR, "IPV6CTL_ACCEPT_RTADV: %m");
106
char dummy[IFNAMSIZ + 8];
108
s = socket(AF_INET6, SOCK_DGRAM, 0);
111
strcpy(dummy, "lo0");
112
if (ioctl(s, SIOCSRTRFLUSH_IN6, (caddr_t)&dummy) == -1)
113
syslog(LOG_ERR, "SIOSRTRFLUSH_IN6: %m");
114
// if (ioctl(s, SIOCSPFXFLUSH_IN6, (caddr_t)&dummy) == -1)
115
// syslog(LOG_ERR, "SIOSPFXFLUSH_IN6: %m");
71
check_ipv6(const char *ifname)
121
check_ipv6(const char *ifname, int own)
123
static int set_restore = 0, forward_warned = 0, global_ra = 0;
74
/* BSD doesn't support these values per iface, so just reutrn 1 */
126
/* BSD doesn't support these values per iface, so just return
127
* the global ra setting */
78
if (inet6_sysctl(IPV6CTL_ACCEPT_RTADV) != 1) {
80
"Kernel is not configured to accept IPv6 RAs");
83
if (inet6_sysctl(IPV6CTL_FORWARDING) != 0) {
85
"Kernel is configured as a router, not a host");
131
ra = get_inet6_sysctl(IPV6CTL_ACCEPT_RTADV);
133
/* The sysctl probably doesn't exist, but this isn't an
134
* error as such so just log it and continue */
135
syslog(errno == ENOENT ? LOG_DEBUG : LOG_WARNING,
136
"IPV6CTL_ACCEPT_RTADV: %m");
137
else if (ra != 0 && own) {
138
syslog(LOG_INFO, "disabling Kernel IPv6 RA support");
139
if (set_inet6_sysctl(IPV6CTL_ACCEPT_RTADV, 0) == -1) {
140
syslog(LOG_ERR, "IPV6CTL_ACCEPT_RTADV: %m");
145
atexit(restore_kernel_ra);
152
if (!forward_warned) {
153
forward = get_inet6_sysctl(IPV6CTL_FORWARDING);
155
/* The sysctl probably doesn't exist, but this isn't an
156
* error as such so just log it and continue */
157
syslog(errno == ENOENT ? LOG_DEBUG : LOG_WARNING,
158
"IPV6CTL_FORWARDING: %m");
159
else if (forward != 0) {
162
"Kernel is configured as a router, not a host");
166
/* Flush the kernel knowledge of advertised routers */
173
ipv6_dadtransmits(__unused const char *ifname)
177
r = get_inet6_sysctl(IPV6CTL_DAD_COUNT);
178
return r < 0 ? 0 : r;