Changeset View
Changeset View
Standalone View
Standalone View
usr.sbin/rtsold/rtsold.c
Show First 20 Lines • Show All 74 Lines • ▼ Show 20 Lines | |||||
static int log_upto = 999; | static int log_upto = 999; | ||||
static int fflag = 0; | static int fflag = 0; | ||||
int Fflag = 0; /* force setting sysctl parameters */ | int Fflag = 0; /* force setting sysctl parameters */ | ||||
int aflag = 0; | int aflag = 0; | ||||
int dflag = 0; | int dflag = 0; | ||||
int uflag = 0; | int uflag = 0; | ||||
const char *managedconf_script; | |||||
const char *otherconf_script; | const char *otherconf_script; | ||||
const char *resolvconf_script = "/sbin/resolvconf"; | const char *resolvconf_script = "/sbin/resolvconf"; | ||||
cap_channel_t *capllflags, *capscript, *capsendmsg, *capsyslog; | cap_channel_t *capllflags, *capscript, *capsendmsg, *capsyslog; | ||||
/* protocol constants */ | /* protocol constants */ | ||||
#define MAX_RTR_SOLICITATION_DELAY 1 /* second */ | #define MAX_RTR_SOLICITATION_DELAY 1 /* second */ | ||||
#define RTR_SOLICITATION_INTERVAL 4 /* seconds */ | #define RTR_SOLICITATION_INTERVAL 4 /* seconds */ | ||||
Show All 28 Lines | main(int argc, char **argv) | ||||
FILE *dumpfp; | FILE *dumpfp; | ||||
struct ifinfo *ifi; | struct ifinfo *ifi; | ||||
struct timespec *timeout; | struct timespec *timeout; | ||||
const char *opts, *pidfilepath, *progname; | const char *opts, *pidfilepath, *progname; | ||||
int ch, error, kq, once, rcvsock, rtsock; | int ch, error, kq, once, rcvsock, rtsock; | ||||
progname = basename(argv[0]); | progname = basename(argv[0]); | ||||
if (strcmp(progname, "rtsold") == 0) { | if (strcmp(progname, "rtsold") == 0) { | ||||
opts = "adDfFm1O:p:R:u"; | opts = "adDfFm1M:O:p:R:u"; | ||||
once = 0; | once = 0; | ||||
pidfilepath = NULL; | pidfilepath = NULL; | ||||
} else { | } else { | ||||
opts = "adDFO:R:u"; | opts = "adDFM:O:R:u"; | ||||
fflag = 1; | fflag = 1; | ||||
once = 1; | once = 1; | ||||
} | } | ||||
while ((ch = getopt(argc, argv, opts)) != -1) { | while ((ch = getopt(argc, argv, opts)) != -1) { | ||||
switch (ch) { | switch (ch) { | ||||
case 'a': | case 'a': | ||||
aflag = 1; | aflag = 1; | ||||
Show All 11 Lines | case 'F': | ||||
Fflag = 1; | Fflag = 1; | ||||
break; | break; | ||||
case 'm': | case 'm': | ||||
mobile_node = 1; | mobile_node = 1; | ||||
break; | break; | ||||
case '1': | case '1': | ||||
once = 1; | once = 1; | ||||
break; | break; | ||||
case 'M': | |||||
managedconf_script = optarg; | |||||
break; | |||||
case 'O': | case 'O': | ||||
otherconf_script = optarg; | otherconf_script = optarg; | ||||
break; | break; | ||||
case 'p': | case 'p': | ||||
pidfilepath = optarg; | pidfilepath = optarg; | ||||
break; | break; | ||||
case 'R': | case 'R': | ||||
resolvconf_script = optarg; | resolvconf_script = optarg; | ||||
Show All 18 Lines | main(int argc, char **argv) | ||||
/* set log level */ | /* set log level */ | ||||
if (dflag > 1) | if (dflag > 1) | ||||
log_upto = LOG_DEBUG; | log_upto = LOG_DEBUG; | ||||
else if (dflag > 0) | else if (dflag > 0) | ||||
log_upto = LOG_INFO; | log_upto = LOG_INFO; | ||||
else | else | ||||
log_upto = LOG_NOTICE; | log_upto = LOG_NOTICE; | ||||
if (managedconf_script != NULL && *managedconf_script != '/') | |||||
errx(1, "configuration script (%s) must be an absolute path", | |||||
managedconf_script); | |||||
if (otherconf_script != NULL && *otherconf_script != '/') | if (otherconf_script != NULL && *otherconf_script != '/') | ||||
errx(1, "configuration script (%s) must be an absolute path", | errx(1, "configuration script (%s) must be an absolute path", | ||||
otherconf_script); | otherconf_script); | ||||
if (*resolvconf_script != '/') | if (*resolvconf_script != '/') | ||||
errx(1, "configuration script (%s) must be an absolute path", | errx(1, "configuration script (%s) must be an absolute path", | ||||
resolvconf_script); | resolvconf_script); | ||||
if (!fflag) { | if (!fflag) { | ||||
▲ Show 20 Lines • Show All 118 Lines • ▼ Show 20 Lines | main(int argc, char **argv) | ||||
return (0); | return (0); | ||||
} | } | ||||
static int | static int | ||||
init_capabilities(void) | init_capabilities(void) | ||||
{ | { | ||||
#ifdef WITH_CASPER | #ifdef WITH_CASPER | ||||
const char *const scripts[2] = { resolvconf_script, otherconf_script }; | const char *const scripts[3] = | ||||
{ resolvconf_script, managedconf_script, otherconf_script }; | |||||
cap_channel_t *capcasper; | cap_channel_t *capcasper; | ||||
nvlist_t *limits; | nvlist_t *limits; | ||||
int count; | |||||
capcasper = cap_init(); | capcasper = cap_init(); | ||||
if (capcasper == NULL) | if (capcasper == NULL) | ||||
return (-1); | return (-1); | ||||
capllflags = cap_service_open(capcasper, "rtsold.llflags"); | capllflags = cap_service_open(capcasper, "rtsold.llflags"); | ||||
if (capllflags == NULL) | if (capllflags == NULL) | ||||
return (-1); | return (-1); | ||||
capscript = cap_service_open(capcasper, "rtsold.script"); | capscript = cap_service_open(capcasper, "rtsold.script"); | ||||
if (capscript == NULL) | if (capscript == NULL) | ||||
return (-1); | return (-1); | ||||
count = 1; | |||||
if (managedconf_script != NULL) | |||||
count++; | |||||
if (otherconf_script != NULL) | |||||
count++; | |||||
markj: Maybe future-proof it?
```
count = 0;
for (size_t i = 0; i < nitems(scripts); i++)
if… | |||||
limits = nvlist_create(0); | limits = nvlist_create(0); | ||||
nvlist_add_string_array(limits, "scripts", scripts, | nvlist_add_string_array(limits, "scripts", scripts, count); | ||||
otherconf_script != NULL ? 2 : 1); | |||||
if (cap_limit_set(capscript, limits) != 0) | if (cap_limit_set(capscript, limits) != 0) | ||||
return (-1); | return (-1); | ||||
capsendmsg = cap_service_open(capcasper, "rtsold.sendmsg"); | capsendmsg = cap_service_open(capcasper, "rtsold.sendmsg"); | ||||
if (capsendmsg == NULL) | if (capsendmsg == NULL) | ||||
return (-1); | return (-1); | ||||
if (!fflag) { | if (!fflag) { | ||||
▲ Show 20 Lines • Show All 239 Lines • ▼ Show 20 Lines | if (TS_CMP(&ifi->expire, &now, <=)) { | ||||
ifi->probetimer = | ifi->probetimer = | ||||
ifi->probeinterval; | ifi->probeinterval; | ||||
probe = 1; | probe = 1; | ||||
ifi->state = IFS_PROBE; | ifi->state = IFS_PROBE; | ||||
} | } | ||||
/* | /* | ||||
* If we need a probe, clear the previous | * If we need a probe, clear the previous | ||||
* status wrt the "other" configuration. | * status wrt the "managed/other" configuration. | ||||
*/ | */ | ||||
if (probe) | if (probe) { | ||||
ifi->managedconfig = 0; | |||||
ifi->otherconfig = 0; | ifi->otherconfig = 0; | ||||
} | |||||
if (probe && mobile_node) { | if (probe && mobile_node) { | ||||
error = cap_probe_defrouters(capsendmsg, | error = cap_probe_defrouters(capsendmsg, | ||||
ifi); | ifi); | ||||
if (error != 0) | if (error != 0) | ||||
warnmsg(LOG_DEBUG, __func__, | warnmsg(LOG_DEBUG, __func__, | ||||
"failed to probe routers: %d", | "failed to probe routers: %d", | ||||
error); | error); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 299 Lines • Show Last 20 Lines |
Maybe future-proof it?