Skip to content

Commit

Permalink
Replace rtadvd (per-interface daemon) with rad (one daemon per machine).
Browse files Browse the repository at this point in the history
Both used the ctl framework for the config file but now we globally enable/
disable as well, not per-inteface. The now-removed 'intrtd' is a good example
of how to store stuff so that conf_dB_single can display it. You'll have to
look at what was removed, intrtd and conf to see how to do a simple
per-interface daemon. The conf_db_single remains but is currently unused!
  • Loading branch information
yellowman committed Sep 19, 2022
1 parent b18890b commit 47e41a5
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 101 deletions.
2 changes: 1 addition & 1 deletion README
Expand Up @@ -7,7 +7,7 @@ replacing /etc/netstart and parts of /etc/rc for appliance-style usage.

Daemons and services encapsulated by nsh:

pf, ospfd, ospf6d, bgpd, ripd, ldpd, relayd, ipsecctl, iked, rtadvd,
pf, ospfd, ospf6d, bgpd, ripd, ldpd, relayd, ipsecctl, iked, rad,
dvmrpd, sasyncd, dhcpd, snmpd, sshd, ntpd, ifstated, tftp-proxy, ftp-proxy,
tftpd, npppd, resolv.conf, inetd, smtpd, ldapd, ifstated

Expand Down
5 changes: 2 additions & 3 deletions commands.c
Expand Up @@ -574,7 +574,6 @@ struct intlist Intlist[] = {
{ "wol", "Wake On LAN", CMPL0 0, 0, intxflags },
{ "mpls", "MPLS", CMPL0 0, 0, intxflags },
{ "inet6", "IPv6", CMPL0 0, 0, intaf },
{ "rtadvd", "IPv6 router advertisement service", CMPL0 0, 0, intrtd },
{ "autoconf6", "IPv6 Autoconfigurable address", CMPL0 0, 0, intxflags },
#ifdef IFXF_INET6_NOPRIVACY /* pre-6.9 */
{ "autoconfprivacy", "Privacy addresses for IPv6 autoconf", CMPL0 0, 0, intxflags },
Expand Down Expand Up @@ -871,7 +870,7 @@ static char
relayhelp[] = "Relay control",
ipsechelp[] = "IPsec IKEv1 control",
ikehelp[] = "IPsec IKEv2 control",
rtadvhelp[] = "Router advertisement control",
radhelp[] = "Router advertisement control",
dvmrphelp[] = "DVMRP control",
sasynchelp[] = "SA synchronization control",
dhcphelp[] = "DHCP server control",
Expand Down Expand Up @@ -951,7 +950,7 @@ Command cmdtab[] = {
{ "ipsec", ipsechelp, CMPL(t) (char **)ctl_ipsec, ssctl, ctlhandler, 1, 0, 1 },
{ "ike", ikehelp, CMPL(t) (char **)ctl_ike, ssctl, ctlhandler, 1, 0, 1 },
{ "dvmrp", dvmrphelp, CMPL(t) (char **)ctl_dvmrp, ssctl, ctlhandler, 1, 0, 1 },
{ "rtadv", rtadvhelp, CMPL(t) (char **)ctl_rtadv, ssctl, ctlhandler, 1, 0, 1 },
{ "rad", radhelp, CMPL(t) (char **)ctl_rad, ssctl, ctlhandler, 1, 0, 1 },
{ "sasync", sasynchelp, CMPL(t) (char **)ctl_sasync, ssctl, ctlhandler, 1, 0, 1 },
{ "dhcp", dhcphelp, CMPL(t) (char **)ctl_dhcp, ssctl, ctlhandler, 1, 0, 1 },
{ "snmp", snmphelp, CMPL(t) (char **)ctl_snmp, ssctl, ctlhandler, 1, 0, 1 },
Expand Down
2 changes: 1 addition & 1 deletion conf.c
Expand Up @@ -206,6 +206,7 @@ conf(FILE *output)
conf_interfaces(output, "pfsync");
conf_interfaces(output, "pflow");

conf_ctl(output, "", "rad", 0);
conf_ctl(output, "", "snmp", 0);
conf_ctl(output, "", "ldp", 0);
conf_ctl(output, "", "rip", 0);
Expand Down Expand Up @@ -531,7 +532,6 @@ void conf_interfaces(FILE *output, char *only)
fprintf(output, " description %s\n", ifrdesc.ifr_data);

conf_lladdr(output, ifnp->if_name);
conf_db_single(output, "rtadvd", NULL, ifnp->if_name);

conf_vnetid(output, ifs, ifnp->if_name);
conf_vnetflowid(output, ifs, ifnp->if_name);
Expand Down
14 changes: 10 additions & 4 deletions ctl.c
Expand Up @@ -79,7 +79,7 @@ struct daemons ctl_daemons[] = {
{ "relay", "Relay",ctl_relay, RELAYCONF_TEMP, 0600, 0, RT_TABLEID_MAX },
{ "ipsec", "IPsec IKEv1",ctl_ipsec,IPSECCONF_TEMP, 0600, 1, RT_TABLEID_MAX },
{ "ike", "IPsec IKEv2",ctl_ike, IKECONF_TEMP, 0600, 0, RT_TABLEID_MAX },
{ "rtadv", "rtadvd",ctl_rtadv, RTADVCONF_TEMP, 0600, 0, 0 },
{ "rad", "rad", ctl_rad, RADCONF_TEMP, 0600, 0, 0 },
{ "dvmrp", "DVMRP",ctl_dvmrp, DVMRPCONF_TEMP, 0600, 0, RT_TABLEID_MAX },
{ "sasync", "SAsync",ctl_sasync, SASYNCCONF_TEMP,0600, 0, RT_TABLEID_MAX },
{ "dhcp", "DHCP", ctl_dhcp, DHCPCONF_TEMP, 0600, 0, RT_TABLEID_MAX },
Expand Down Expand Up @@ -309,10 +309,16 @@ struct ctl ctl_dvmrp[] = {
{ 0, 0, { 0 }, 0, 0, 0 }
};

/* rtadvd */
struct ctl ctl_rtadv[] = {
/* rad */
char *ctl_rad_test[] = { RAD, "-nf", REQTEMP, NULL };
struct ctl ctl_rad[] = {
{ "enable", "enable service",
{ RAD, "-f", REQTEMP, NULL }, NULL, DB_X_ENABLE, T_EXEC },
{ "disable", "disable service",
{ PKILL, table, "rad", NULL }, NULL, DB_X_DISABLE, T_EXEC },
{ "edit", "edit configuration",
{ "rtadv", NULL, NULL}, call_editor, 0, T_HANDLER_FILL1 },
{ "rad", (char *)ctl_rad_test, NULL}, call_editor, 0,
T_HANDLER_FILL1 },
{ 0, 0, { 0 }, 0, 0, 0 }
};

Expand Down
7 changes: 3 additions & 4 deletions externs.h
Expand Up @@ -146,7 +146,7 @@ extern char metricnames[];
#define IPSECCONF_TEMP "/var/run/ipsec.conf"
#define IKECONF_TEMP "/var/run/iked.conf"
#define DVMRPCONF_TEMP "/var/run/dvmrpd.conf"
#define RTADVCONF_TEMP "/var/run/rtadvd.conf"
#define RADCONF_TEMP "/var/run/rad.conf"
#define RELAYCONF_TEMP "/var/run/relayd.conf"
#define SASYNCCONF_TEMP "/var/run/sasyncd.conf"
#define DHCPCONF_TEMP "/var/run/dhcpd.conf"
Expand Down Expand Up @@ -224,7 +224,7 @@ extern struct ctl ctl_nppp[];
extern struct ctl ctl_ifstate[];
extern struct ctl ctl_ike[];
extern struct ctl ctl_dvmrp[];
extern struct ctl ctl_rtadv[];
extern struct ctl ctl_rad[];
extern struct ctl ctl_sasync[];
extern struct ctl ctl_dhcp[];
extern struct ctl ctl_snmp[];
Expand Down Expand Up @@ -380,7 +380,7 @@ int parse_ipv6(char *, struct in6_addr *);
/* if.c */
#define DHCLIENT "/sbin/dhclient"
#define DHCRELAY "/usr/sbin/dhcrelay"
#define RTADVD "/usr/sbin/rtadvd"
#define RAD "/usr/sbin/rad"
#define IFDATA_MTU 1 /* request for if_data.ifi_mtu */
#define IFDATA_BAUDRATE 2 /* request for if_data.ifi_baudrate */
#define MBPS(bps) (bps / 1000 / 1000)
Expand Down Expand Up @@ -408,7 +408,6 @@ int intrdomain(char *, int, int, char **);
int intdhcrelay(char *, int, int, char **);
int intmetric(char *, int, int, char **);
int intllprio(char *, int, int, char **);
int intrtd(char *, int, int, char **);
int intflags(char *, int, int, char **);
int intxflags(char *, int, int, char **);
int intaf(char *, int, int, char **);
Expand Down
71 changes: 0 additions & 71 deletions if.c
Expand Up @@ -2131,77 +2131,6 @@ intlladdr(char *ifname, int ifs, int argc, char **argv)
return(0);
}

int
intrtd(char *ifname, int ifs, int argc, char **argv)
{
StringList *dbreturn;
char *cmdpath, *cmdname;
int set;

if (NO_ARG(argv[0])) {
argv++;
argc--;
set = 0;
} else
set = 1;

if (isprefix(argv[0], "rtadvd")) {
cmdname = "rtadvd";
cmdpath = RTADVD;
} else {
printf("%% intrtd: Internal error\n");
return 0;
}

if (argc > 1) {
printf ("%% %s\n", cmdname);
printf ("%% no %s\n", cmdname);
return(0);
}

dbreturn = sl_init();
if (db_select_flag_x_ctl(dbreturn, cmdname, ifname) < 0) {
printf("%% database failure select flag x ctl\n");
sl_free(dbreturn, 1);
return(1);
}
if (dbreturn->sl_cur > 0) {
/* already found in db for ifname */
if (!set) {
if (db_delete_flag_x_ctl(cmdname, ifname) < 0)
printf("%% database delete failure\n");
} else {
printf("%% %s already running\n", cmdname);
}
if (!set && strcmp(cmdname, "rtadvd") == 0) {
char *args[] = { PKILL, cmdpath, "-c",
"/var/run/rtadvd.0", ifname, NULL };

cmdargs(PKILL, args);
}
} else {
/* not found in db for ifname */
if (set) {
if(db_insert_flag_x(cmdname, ifname, 0, DB_X_ENABLE,
NULL) < 0) {
printf("%% database insert failure\n");
sl_free(dbreturn, 1);
return(1);
}
} else {
printf("%% %s not running\n", cmdname);
}
if (set && strcmp(cmdname, "rtadvd") == 0) {
char *args[] = { cmdpath, "-c", "/var/run/rtadvd.0",
ifname, NULL };

cmdargs(cmdpath, args);
}
}
sl_free(dbreturn, 1);
return(0);
}

int
intrdomain(char *ifname, int ifs, int argc, char **argv)
{
Expand Down
2 changes: 0 additions & 2 deletions main.c
Expand Up @@ -101,8 +101,6 @@ main(int argc, char *argv[])
printf("%% database ipv6linklocal creation failed\n");
if (db_create_table_flag_x("lladdr") < 0)
printf("%% database lladdr creation failed\n");
if (db_create_table_flag_x("rtadvd") < 0)
printf("%% database rtadvd creation failed\n");
if (db_create_table_flag_x("authkey") < 0)
printf("%% database authkey creation failed\n");
if (db_create_table_flag_x("peerkey") < 0)
Expand Down
18 changes: 3 additions & 15 deletions nsh.8
Expand Up @@ -277,7 +277,7 @@ nsh/help
ipsec IPsec IKEv1 control
ike IPsec IKEv2 control
dvmrp DVMRP control
rtadv Router advertisement control
rad Router advertisement control
sasync SA synchronization control
dhcp DHCP server control
snmp SNMP server control
Expand Down Expand Up @@ -2197,7 +2197,7 @@ nsh(p)/ip ?
| vnetflowid | parent | patch | keepalive | mplslabel | pwe\
| syncdev | syncpeer | maxupd | vhid | advbase | advskew | carppass\
| carpdev | carpnode | carppeer | balancing | pflow | debug\
| dhcrelay | wol | mpls | inet6 | rtadvd | autoconf6\
| dhcrelay | wol | mpls | inet6 | autoconf6\
| autoconfprivacy | temporary | monitor | wgpeer | wgport\
| wgkey | wgrtable | trunkport | trunkproto | shutdown |\ ?
interface mode commands, are commands that can be applied to a specific
Expand Down Expand Up @@ -2259,7 +2259,6 @@ nsh(interface-em0)/?
wol Wake On LAN
mpls MPLS
inet6 IPv6
rtadvd IPv6 router advertisement service
autoconf6 IPv6 Autoconfigurable address
autoconfprivacy Privacy addresses for IPv6 autoconf
temporary Temporary addresses for IPv6 autoconf
Expand Down Expand Up @@ -3138,18 +3137,7 @@ E.g. to enable ipv6 link local address on em0
.Bd -literal -offset indent
nsh(p)/interface em0

nsh(interface-em0)/inet6
.Ed
.Pp
.Op no
.Ic rtadvd
enables or disables the ipv6 router advertisement daemon on an interface.
.Pp
E.g. to enable v6 router advertisements on the interface em0
.Bd -literal -offset indent
nsh(p)/interface em0

nsh(interface-em0)/rtadvd
nsh(interface-em0)/rad
.Ed
.Pp
.Op no
Expand Down

0 comments on commit 47e41a5

Please sign in to comment.