From 7fa7bd6ad2ca27f28c91cc116d9cad1aabbf9e73 Mon Sep 17 00:00:00 2001 From: ume Date: Wed, 14 Jan 2004 17:42:03 +0000 Subject: add -F flag, which configures sysctl(8) setting by rtsold itself (rather than warn about the current setting). Obtained from: KAME --- usr.sbin/rtsold/if.c | 16 ++++++++++++++++ usr.sbin/rtsold/rtsold.8 | 18 +++++++++++++++--- usr.sbin/rtsold/rtsold.c | 33 +++++++++++++++++++++------------ usr.sbin/rtsold/rtsold.h | 1 + 4 files changed, 53 insertions(+), 15 deletions(-) (limited to 'usr.sbin') diff --git a/usr.sbin/rtsold/if.c b/usr.sbin/rtsold/if.c index 99a1b0e..23e4e6f 100644 --- a/usr.sbin/rtsold/if.c +++ b/usr.sbin/rtsold/if.c @@ -300,6 +300,22 @@ getinet6sysctl(int code) return value; } +int +setinet6sysctl(int code, int newval) +{ + int mib[] = { CTL_NET, PF_INET6, IPPROTO_IPV6, 0 }; + int value; + size_t size; + + mib[3] = code; + size = sizeof(value); + if (sysctl(mib, sizeof(mib)/sizeof(mib[0]), &value, &size, + &newval, sizeof(newval)) < 0) + return -1; + else + return value; +} + /*------------------------------------------------------------*/ /* get ia6_flags for link-local addr on if. returns -1 on error. */ diff --git a/usr.sbin/rtsold/rtsold.8 b/usr.sbin/rtsold/rtsold.8 index 2490890..1e2a3bf 100644 --- a/usr.sbin/rtsold/rtsold.8 +++ b/usr.sbin/rtsold/rtsold.8 @@ -39,15 +39,15 @@ .\" .Sh SYNOPSIS .Nm -.Op Fl dDfm1 +.Op Fl dDfFm1 .Op Fl O Ar script-name .Ar interface ... .Nm -.Op Fl dDfm1 +.Op Fl dDfFm1 .Op Fl O Ar script-name .Fl a .Nm rtsol -.Op Fl dD +.Op Fl dDF .Op Fl O Ar script-name .Ar interface ... .Nm rtsol @@ -176,6 +176,18 @@ from becoming a daemon (foreground mode). Warning messages are generated to standard error instead of .Xr syslog 3 . +.It Fl F +Configure +.Xr sysctl 8 +variable related to +.Nm +by itself. +Without +.Fl F , +.Nm +will not alter and obey the current +.Xr sysctl 8 +settings. .It Fl m Enable mobility support. If this option is specified, diff --git a/usr.sbin/rtsold/rtsold.c b/usr.sbin/rtsold/rtsold.c index e058dd7..bfdbc68 100644 --- a/usr.sbin/rtsold/rtsold.c +++ b/usr.sbin/rtsold/rtsold.c @@ -62,6 +62,7 @@ struct ifinfo *iflist; struct timeval tm_max = {0x7fffffff, 0x7fffffff}; static int log_upto = 999; static int fflag = 0; +static int Fflag = 0; /* force setting sysctl parameters */ int aflag = 0; int dflag = 0; @@ -120,9 +121,9 @@ main(int argc, char **argv) if (argv0 && argv0[strlen(argv0) - 1] != 'd') { fflag = 1; once = 1; - opts = "adDO:"; + opts = "adDFO:"; } else - opts = "adDfm1O:"; + opts = "adDfFm1O:"; while ((ch = getopt(argc, argv, opts)) != -1) { switch (ch) { @@ -138,6 +139,9 @@ main(int argc, char **argv) case 'f': fflag = 1; break; + case 'F': + Fflag = 1; + break; case 'm': mobile_node = 1; break; @@ -186,12 +190,17 @@ main(int argc, char **argv) srandom((u_long)time(NULL)); #endif - /* warn if accept_rtadv is down */ - if (!getinet6sysctl(IPV6CTL_ACCEPT_RTADV)) - warnx("kernel is configured not to accept RAs"); - /* warn if forwarding is up */ - if (getinet6sysctl(IPV6CTL_FORWARDING)) - warnx("kernel is configured as a router, not a host"); + if (Fflag) { + setinet6sysctl(IPV6CTL_ACCEPT_RTADV, 1); + setinet6sysctl(IPV6CTL_FORWARDING, 0); + } else { + /* warn if accept_rtadv is down */ + if (!getinet6sysctl(IPV6CTL_ACCEPT_RTADV)) + warnx("kernel is configured not to accept RAs"); + /* warn if forwarding is up */ + if (getinet6sysctl(IPV6CTL_FORWARDING)) + warnx("kernel is configured as a router, not a host"); + } /* initialization to dump internal status to a file */ signal(SIGUSR1, rtsold_set_dump_file); @@ -720,11 +729,11 @@ static void usage(char *progname) { if (progname && progname[strlen(progname) - 1] != 'd') { - fprintf(stderr, "usage: rtsol [-dD] interfaces...\n"); - fprintf(stderr, "usage: rtsol [-dD] -a\n"); + fprintf(stderr, "usage: rtsol [-dDF] interfaces...\n"); + fprintf(stderr, "usage: rtsol [-dDF] -a\n"); } else { - fprintf(stderr, "usage: rtsold [-adDfm1] interfaces...\n"); - fprintf(stderr, "usage: rtsold [-dDfm1] -a\n"); + fprintf(stderr, "usage: rtsold [-adDfFm1] interfaces...\n"); + fprintf(stderr, "usage: rtsold [-dDfFm1] -a\n"); } exit(1); } diff --git a/usr.sbin/rtsold/rtsold.h b/usr.sbin/rtsold/rtsold.h index 09577a5..e25ed95 100644 --- a/usr.sbin/rtsold/rtsold.h +++ b/usr.sbin/rtsold/rtsold.h @@ -84,6 +84,7 @@ extern int lladdropt_length __P((struct sockaddr_dl *)); extern void lladdropt_fill __P((struct sockaddr_dl *, struct nd_opt_hdr *)); extern struct sockaddr_dl *if_nametosdl __P((char *)); extern int getinet6sysctl __P((int)); +extern int setinet6sysctl __P((int, int)); /* rtsol.c */ extern int sockopen __P((void)); -- cgit v1.1