forked from radvd-project/radvd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathradvd.c
858 lines (714 loc) · 18.2 KB
/
radvd.c
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
/*
* $Id: radvd.c,v 1.62 2011/06/07 04:53:42 reubenhwk Exp $
*
* Authors:
* Pedro Roque <[email protected]>
* Lars Fenneberg <[email protected]>
*
* This software is Copyright 1996-2000 by the above mentioned author(s),
* All Rights Reserved.
*
* The license which is distributed with this software in the file COPYRIGHT
* applies to this software. If your distribution is missing this file, you
* may request it from <[email protected]>.
*
*/
#include "config.h"
#include "includes.h"
#include "radvd.h"
#include "pathnames.h"
#ifdef HAVE_NETLINK
#include "netlink.h"
#endif
#include <poll.h>
struct Interface *IfaceList = NULL;
#ifdef HAVE_GETOPT_LONG
char usage_str[] = {
"\n"
" -c, --configtest Parse the config file and exit.\n"
" -C, --config=PATH Sets the config file. Default is /etc/radvd.conf.\n"
" -d, --debug=NUM Sets the debug level. Values can be 1, 2, 3, 4 or 5.\n"
" -f, --facility=NUM Sets the logging facility.\n"
" -h, --help Show this help screen.\n"
" -l, --logfile=PATH Sets the log file.\n"
" -m, --logmethod=X Sets the log method to one of: syslog, stderr, stderr_syslog, logfile, or none.\n"
" -p, --pidfile=PATH Sets the pid file.\n"
" -s, --singleprocess Use privsep.\n"
" -t, --chrootdir=PATH Chroot to the specified path.\n"
" -u, --username=USER Switch to the specified user.\n"
" -v, --version Print the version and quit.\n"
};
struct option prog_opt[] = {
{"debug", 1, 0, 'd'},
{"configtest", 0, 0, 'c'},
{"config", 1, 0, 'C'},
{"pidfile", 1, 0, 'p'},
{"logfile", 1, 0, 'l'},
{"logmethod", 1, 0, 'm'},
{"facility", 1, 0, 'f'},
{"username", 1, 0, 'u'},
{"chrootdir", 1, 0, 't'},
{"version", 0, 0, 'v'},
{"help", 0, 0, 'h'},
{"singleprocess", 0, 0, 's'},
{NULL, 0, 0, 0}
};
#else
char usage_str[] =
"[-hsvc] [-d level] [-C config_file] [-m log_method] [-l log_file]\n"
"\t[-f facility] [-p pid_file] [-u username] [-t chrootdir]";
#endif
extern FILE *yyin;
char *conf_file = NULL;
char *pname;
int sock = -1;
volatile int sighup_received = 0;
volatile int sigterm_received = 0;
volatile int sigint_received = 0;
volatile int sigusr1_received = 0;
void sighup_handler(int sig);
void sigterm_handler(int sig);
void sigint_handler(int sig);
void sigusr1_handler(int sig);
void timer_handler(void *data);
void config_interface(void);
void kickoff_adverts(void);
void stop_adverts(void);
void version(void);
void usage(void);
int drop_root_privileges(const char *);
int readin_config(char *);
int check_conffile_perm(const char *, const char *);
void main_loop(void);
int
main(int argc, char *argv[])
{
char pidstr[16];
ssize_t ret;
int c, log_method;
char *logfile, *pidfile;
int facility, fd;
char *username = NULL;
char *chrootdir = NULL;
int configtest = 0;
int singleprocess = 0;
#ifdef HAVE_GETOPT_LONG
int opt_idx;
#endif
pname = ((pname=strrchr(argv[0],'/')) != NULL)?pname+1:argv[0];
srand((unsigned int)time(NULL));
log_method = L_STDERR_SYSLOG;
logfile = PATH_RADVD_LOG;
conf_file = PATH_RADVD_CONF;
facility = LOG_FACILITY;
pidfile = PATH_RADVD_PID;
/* parse args */
#define OPTIONS_STR "d:C:l:m:p:t:u:vhcs"
#ifdef HAVE_GETOPT_LONG
while ((c = getopt_long(argc, argv, OPTIONS_STR, prog_opt, &opt_idx)) > 0)
#else
while ((c = getopt(argc, argv, OPTIONS_STR)) > 0)
#endif
{
switch (c) {
case 'C':
conf_file = optarg;
break;
case 'd':
set_debuglevel(atoi(optarg));
break;
case 'f':
facility = atoi(optarg);
break;
case 'l':
logfile = optarg;
break;
case 'p':
pidfile = optarg;
break;
case 'm':
if (!strcmp(optarg, "syslog"))
{
log_method = L_SYSLOG;
}
else if (!strcmp(optarg, "stderr_syslog"))
{
log_method = L_STDERR_SYSLOG;
}
else if (!strcmp(optarg, "stderr"))
{
log_method = L_STDERR;
}
else if (!strcmp(optarg, "logfile"))
{
log_method = L_LOGFILE;
}
else if (!strcmp(optarg, "none"))
{
log_method = L_NONE;
}
else
{
fprintf(stderr, "%s: unknown log method: %s\n", pname, optarg);
exit(1);
}
break;
case 't':
chrootdir = strdup(optarg);
break;
case 'u':
username = strdup(optarg);
break;
case 'v':
version();
break;
case 'c':
configtest = 1;
break;
case 's':
singleprocess = 1;
break;
case 'h':
usage();
#ifdef HAVE_GETOPT_LONG
case ':':
fprintf(stderr, "%s: option %s: parameter expected\n", pname,
prog_opt[opt_idx].name);
exit(1);
#endif
case '?':
exit(1);
}
}
if (chrootdir) {
if (!username) {
fprintf(stderr, "Chroot as root is not safe, exiting\n");
exit(1);
}
if (chroot(chrootdir) == -1) {
perror("chroot");
exit (1);
}
if (chdir("/") == -1) {
perror("chdir");
exit (1);
}
/* username will be switched later */
}
if (configtest) {
log_method = L_STDERR;
}
if (log_open(log_method, pname, logfile, facility) < 0) {
perror("log_open");
exit(1);
}
if (!configtest) {
flog(LOG_INFO, "version %s started", VERSION);
}
/* get a raw socket for sending and receiving ICMPv6 messages */
sock = open_icmpv6_socket();
if (sock < 0) {
perror("open_icmpv6_socket");
exit(1);
}
/* check that 'other' cannot write the file
* for non-root, also that self/own group can't either
*/
if (check_conffile_perm(username, conf_file) < 0) {
if (get_debuglevel() == 0) {
flog(LOG_ERR, "Exiting, permissions on conf_file invalid.\n");
exit(1);
}
else
flog(LOG_WARNING, "Insecure file permissions, but continuing anyway");
}
/* if we know how to do it, check whether forwarding is enabled */
if (check_ip6_forwarding()) {
flog(LOG_WARNING, "IPv6 forwarding seems to be disabled, but continuing anyway.");
}
/* parse config file */
if (readin_config(conf_file) < 0) {
flog(LOG_ERR, "Exiting, failed to read config file.\n");
exit(1);
}
if (configtest) {
fprintf(stderr, "Syntax OK\n");
exit(0);
}
/* drop root privileges if requested. */
if (username) {
if (!singleprocess) {
dlog(LOG_DEBUG, 3, "Initializing privsep");
if (privsep_init() < 0)
flog(LOG_WARNING, "Failed to initialize privsep.");
}
if (drop_root_privileges(username) < 0) {
perror("drop_root_privileges");
exit(1);
}
}
if ((fd = open(pidfile, O_RDONLY, 0)) > 0)
{
ret = read(fd, pidstr, sizeof(pidstr) - 1);
if (ret < 0)
{
flog(LOG_ERR, "cannot read radvd pid file, terminating: %s", strerror(errno));
exit(1);
}
pidstr[ret] = '\0';
if (!kill((pid_t)atol(pidstr), 0))
{
flog(LOG_ERR, "radvd already running, terminating.");
exit(1);
}
close(fd);
fd = open(pidfile, O_CREAT|O_TRUNC|O_WRONLY, 0644);
}
else /* FIXME: not atomic if pidfile is on an NFS mounted volume */
fd = open(pidfile, O_CREAT|O_EXCL|O_WRONLY, 0644);
if (fd < 0)
{
flog(LOG_ERR, "cannot create radvd pid file, terminating: %s", strerror(errno));
exit(1);
}
/*
* okay, config file is read in, socket and stuff is setup, so
* lets fork now...
*/
if (get_debuglevel() == 0) {
/* Detach from controlling terminal */
if (daemon(0, 0) < 0)
perror("daemon");
/* close old logfiles, including stderr */
log_close();
/* reopen logfiles, but don't log to stderr unless explicitly requested */
if (log_method == L_STDERR_SYSLOG)
log_method = L_SYSLOG;
if (log_open(log_method, pname, logfile, facility) < 0) {
perror("log_open");
exit(1);
}
}
/*
* config signal handlers
*/
signal(SIGHUP, sighup_handler);
signal(SIGTERM, sigterm_handler);
signal(SIGINT, sigint_handler);
signal(SIGUSR1, sigusr1_handler);
snprintf(pidstr, sizeof(pidstr), "%ld\n", (long)getpid());
ret = write(fd, pidstr, strlen(pidstr));
if (ret != strlen(pidstr))
{
flog(LOG_ERR, "cannot write radvd pid file, terminating: %s", strerror(errno));
exit(1);
}
close(fd);
config_interface();
kickoff_adverts();
main_loop();
stop_adverts();
unlink(pidfile);
return 0;
}
void main_loop(void)
{
struct pollfd fds[2];
memset(fds, 0, sizeof(fds));
fds[0].fd = sock;
fds[0].events = POLLIN;
fds[0].revents = 0;
#if HAVE_NETLINK
fds[1].fd = netlink_socket();
fds[1].events = POLLIN;
fds[1].revents = 0;
#else
fds[1].fd = -1;
fds[1].events = 0;
fds[1].revents = 0;
#endif
for (;;) {
struct Interface *next = NULL;
struct Interface *iface;
int timeout = -1;
int rc;
if (IfaceList) {
timeout = next_time_msec(IfaceList);
next = IfaceList;
for (iface = IfaceList; iface; iface = iface->next) {
int t;
t = next_time_msec(iface);
if (timeout > t) {
timeout = t;
next = iface;
}
}
}
dlog(LOG_DEBUG, 5, "polling for %g seconds.", timeout/1000.0);
rc = poll(fds, sizeof(fds)/sizeof(fds[0]), timeout);
if (rc > 0) {
if (fds[0].revents & (POLLERR | POLLHUP | POLLNVAL)) {
flog(LOG_WARNING, "socket error on fds[0].fd");
}
else if (fds[0].revents & POLLIN) {
int len, hoplimit;
struct sockaddr_in6 rcv_addr;
struct in6_pktinfo *pkt_info = NULL;
unsigned char msg[MSG_SIZE_RECV];
len = recv_rs_ra(msg, &rcv_addr, &pkt_info, &hoplimit);
if (len > 0) {
process(IfaceList, msg, len,
&rcv_addr, pkt_info, hoplimit);
}
}
#ifdef HAVE_NETLINK
if (fds[1].revents & (POLLERR | POLLHUP | POLLNVAL)) {
flog(LOG_WARNING, "socket error on fds[1].fd");
}
else if (fds[1].revents & POLLIN) {
process_netlink_msg(fds[1].fd);
}
#endif
}
else if ( rc == 0 ) {
if (next)
timer_handler(next);
}
else if ( rc == -1 ) {
flog(LOG_ERR, "poll error: %s", strerror(errno));
}
if (sigterm_received || sigint_received) {
flog(LOG_WARNING, "Exiting, sigterm or sigint received.\n");
break;
}
if (sighup_received)
{
reload_config();
sighup_received = 0;
}
if (sigusr1_received)
{
reset_prefix_lifetimes();
sigusr1_received = 0;
}
}
}
void
timer_handler(void *data)
{
struct Interface *iface = (struct Interface *) data;
double next;
dlog(LOG_DEBUG, 4, "timer_handler called for %s", iface->Name);
if (send_ra_forall(iface, NULL) != 0) {
return;
}
next = rand_between(iface->MinRtrAdvInterval, iface->MaxRtrAdvInterval);
if (iface->init_racount < MAX_INITIAL_RTR_ADVERTISEMENTS)
{
iface->init_racount++;
next = min(MAX_INITIAL_RTR_ADVERT_INTERVAL, next);
}
iface->next_multicast = next_timeval(next);
}
void
config_interface(void)
{
struct Interface *iface;
for(iface=IfaceList; iface; iface=iface->next)
{
if (iface->AdvLinkMTU)
set_interface_linkmtu(iface->Name, iface->AdvLinkMTU);
if (iface->AdvCurHopLimit)
set_interface_curhlim(iface->Name, iface->AdvCurHopLimit);
if (iface->AdvReachableTime)
set_interface_reachtime(iface->Name, iface->AdvReachableTime);
if (iface->AdvRetransTimer)
set_interface_retranstimer(iface->Name, iface->AdvRetransTimer);
}
}
void
kickoff_adverts(void)
{
struct Interface *iface;
/*
* send initial advertisement and set timers
*/
for(iface=IfaceList; iface; iface=iface->next)
{
double next;
gettimeofday(&iface->last_ra_time, NULL);
if( iface->UnicastOnly )
continue;
gettimeofday(&iface->last_multicast, NULL);
if (!iface->AdvSendAdvert)
continue;
/* send an initial advertisement */
if (send_ra_forall(iface, NULL) == 0) {
iface->init_racount++;
next = min(MAX_INITIAL_RTR_ADVERT_INTERVAL, iface->MaxRtrAdvInterval);
iface->next_multicast = next_timeval(next);
}
}
}
void
stop_adverts(void)
{
struct Interface *iface;
/*
* send final RA (a SHOULD in RFC4861 section 6.2.5)
*/
for (iface=IfaceList; iface; iface=iface->next) {
if( ! iface->UnicastOnly ) {
if (iface->AdvSendAdvert) {
/* send a final advertisement with zero Router Lifetime */
iface->cease_adv = 1;
send_ra_forall(iface, NULL);
}
}
}
}
void reload_config(void)
{
struct Interface *iface;
flog(LOG_INFO, "attempting to reread config file");
dlog(LOG_DEBUG, 4, "reopening log");
if (log_reopen() < 0) {
perror("log_reopen");
exit(1);
}
iface=IfaceList;
while(iface)
{
struct Interface *next_iface = iface->next;
struct AdvPrefix *prefix;
struct AdvRoute *route;
struct AdvRDNSS *rdnss;
struct AdvDNSSL *dnssl;
dlog(LOG_DEBUG, 4, "freeing interface %s", iface->Name);
prefix = iface->AdvPrefixList;
while (prefix)
{
struct AdvPrefix *next_prefix = prefix->next;
free(prefix);
prefix = next_prefix;
}
route = iface->AdvRouteList;
while (route)
{
struct AdvRoute *next_route = route->next;
free(route);
route = next_route;
}
rdnss = iface->AdvRDNSSList;
while (rdnss)
{
struct AdvRDNSS *next_rdnss = rdnss->next;
free(rdnss);
rdnss = next_rdnss;
}
dnssl = iface->AdvDNSSLList;
while (dnssl)
{
struct AdvDNSSL *next_dnssl = dnssl->next;
int i;
for (i = 0; i < dnssl->AdvDNSSLNumber; i++)
free(dnssl->AdvDNSSLSuffixes[i]);
free(dnssl->AdvDNSSLSuffixes);
free(dnssl);
dnssl = next_dnssl;
}
free(iface);
iface = next_iface;
}
IfaceList = NULL;
/* reread config file */
if (readin_config(conf_file) < 0) {
perror("readin_config failed.");
exit(1);
}
/* XXX: fails due to lack of permissions with non-root user */
config_interface();
kickoff_adverts();
flog(LOG_INFO, "resuming normal operation");
}
void
sighup_handler(int sig)
{
/* Linux has "one-shot" signals, reinstall the signal handler */
signal(SIGHUP, sighup_handler);
dlog(LOG_DEBUG, 4, "sighup_handler called");
sighup_received = 1;
}
void
sigterm_handler(int sig)
{
/* Linux has "one-shot" signals, reinstall the signal handler */
signal(SIGTERM, sigterm_handler);
dlog(LOG_DEBUG, 4, "sigterm_handler called");
++sigterm_received;
if(sigterm_received > 1){
dlog(LOG_ERR, 1, "sigterm_handler called %d times...aborting...", sigterm_received);
abort();
}
}
void
sigint_handler(int sig)
{
/* Linux has "one-shot" signals, reinstall the signal handler */
signal(SIGINT, sigint_handler);
dlog(LOG_DEBUG, 4, "sigint_handler called");
++sigint_received;
if(sigint_received > 1){
dlog(LOG_ERR, 1, "sigint_handler called %d times...aborting...", sigint_received);
abort();
}
}
void reset_prefix_lifetimes(void)
{
struct Interface *iface;
struct AdvPrefix *prefix;
char pfx_str[INET6_ADDRSTRLEN];
flog(LOG_INFO, "Resetting prefix lifetimes");
for (iface = IfaceList; iface; iface = iface->next)
{
for (prefix = iface->AdvPrefixList; prefix;
prefix = prefix->next)
{
if (prefix->DecrementLifetimesFlag)
{
print_addr(&prefix->Prefix, pfx_str);
dlog(LOG_DEBUG, 4, "%s/%u%%%s plft reset from %u to %u secs", pfx_str, prefix->PrefixLen, iface->Name, prefix->curr_preferredlft, prefix->AdvPreferredLifetime);
dlog(LOG_DEBUG, 4, "%s/%u%%%s vlft reset from %u to %u secs", pfx_str, prefix->PrefixLen, iface->Name, prefix->curr_validlft, prefix->AdvValidLifetime);
prefix->curr_validlft =
prefix->AdvValidLifetime;
prefix->curr_preferredlft =
prefix->AdvPreferredLifetime;
}
}
}
}
void sigusr1_handler(int sig)
{
/* Linux has "one-shot" signals, reinstall the signal handler */
signal(SIGUSR1, sigusr1_handler);
dlog(LOG_DEBUG, 4, "sigusr1_handler called");
sigusr1_received = 1;
}
int
drop_root_privileges(const char *username)
{
struct passwd *pw = NULL;
pw = getpwnam(username);
if (pw) {
if (initgroups(username, pw->pw_gid) != 0 || setgid(pw->pw_gid) != 0 || setuid(pw->pw_uid) != 0) {
flog(LOG_ERR, "Couldn't change to '%.32s' uid=%d gid=%d",
username, pw->pw_uid, pw->pw_gid);
return (-1);
}
}
else {
flog(LOG_ERR, "Couldn't find user '%.32s'", username);
return (-1);
}
return 0;
}
int
check_conffile_perm(const char *username, const char *conf_file)
{
struct stat stbuf;
struct passwd *pw = NULL;
FILE *fp = fopen(conf_file, "r");
if (fp == NULL) {
flog(LOG_ERR, "can't open %s: %s", conf_file, strerror(errno));
return (-1);
}
fclose(fp);
if (!username)
username = "root";
pw = getpwnam(username);
if (stat(conf_file, &stbuf) || pw == NULL)
return (-1);
if (stbuf.st_mode & S_IWOTH) {
flog(LOG_ERR, "Insecure file permissions (writable by others): %s", conf_file);
return (-1);
}
/* for non-root: must not be writable by self/own group */
if (strncmp(username, "root", 5) != 0 &&
((stbuf.st_mode & S_IWGRP && pw->pw_gid == stbuf.st_gid) ||
(stbuf.st_mode & S_IWUSR && pw->pw_uid == stbuf.st_uid))) {
flog(LOG_ERR, "Insecure file permissions (writable by self/group): %s", conf_file);
return (-1);
}
return 0;
}
int
check_ip6_forwarding(void)
{
int forw_sysctl[] = { SYSCTL_IP6_FORWARDING };
int value;
size_t size = sizeof(value);
FILE *fp = NULL;
static int warned = 0;
#ifdef __linux__
fp = fopen(PROC_SYS_IP6_FORWARDING, "r");
if (fp) {
int rc = fscanf(fp, "%d", &value);
if(rc != 1){
flog(LOG_ERR, "cannot read value from %s: %s", PROC_SYS_IP6_FORWARDING, strerror(errno));
exit(1);
}
fclose(fp);
}
else
flog(LOG_DEBUG, "Correct IPv6 forwarding procfs entry not found, "
"perhaps the procfs is disabled, "
"or the kernel interface has changed?");
#endif /* __linux__ */
if (!fp && sysctl(forw_sysctl, sizeof(forw_sysctl)/sizeof(forw_sysctl[0]),
&value, &size, NULL, 0) < 0) {
flog(LOG_DEBUG, "Correct IPv6 forwarding sysctl branch not found, "
"perhaps the kernel interface has changed?");
return(0); /* this is of advisory value only */
}
if (value != 1 && !warned) {
warned = 1;
flog(LOG_DEBUG, "IPv6 forwarding setting is: %u, should be 1", value);
return(-1);
}
return(0);
}
int
readin_config(char *fname)
{
if ((yyin = fopen(fname, "r")) == NULL)
{
flog(LOG_ERR, "can't open %s: %s", fname, strerror(errno));
return (-1);
}
if (yyparse() != 0)
{
flog(LOG_ERR, "error parsing or activating the config file: %s", fname);
return (-1);
}
fclose(yyin);
return 0;
}
void
version(void)
{
fprintf(stderr, "Version: %s\n\n", VERSION);
fprintf(stderr, "Compiled in settings:\n");
fprintf(stderr, " default config file \"%s\"\n", PATH_RADVD_CONF);
fprintf(stderr, " default pidfile \"%s\"\n", PATH_RADVD_PID);
fprintf(stderr, " default logfile \"%s\"\n", PATH_RADVD_LOG);
fprintf(stderr, " default syslog facility %d\n", LOG_FACILITY);
fprintf(stderr, "Please send bug reports or suggestions to %s.\n",
CONTACT_EMAIL);
exit(1);
}
void
usage(void)
{
fprintf(stderr, "usage: %s %s\n", pname, usage_str);
exit(1);
}