From 6f3ee9680eef44599f1d73ec8fe2a64c133c3e09 Mon Sep 17 00:00:00 2001 From: Tomas Paukrt Date: Mon, 9 Sep 2024 18:46:48 +0200 Subject: [PATCH] pppd: Add net-init-script, net-pre-up-script and net-down-script options These options allow a user to specify paths to scripts usually located at /etc/ppp/net-init, /etc/ppp/net-pre-up and /etc/ppp/net-down, similarly to the existing ip-up-script and ip-down-script options. Signed-off-by: Tomas Paukrt --- pppd/main.c | 10 +++++++--- pppd/options.c | 13 +++++++++++++ pppd/pppd-private.h | 3 +++ 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/pppd/main.c b/pppd/main.c index d62e603..acc1b63 100644 --- a/pppd/main.c +++ b/pppd/main.c @@ -363,6 +363,10 @@ main(int argc, char *argv[]) struct protent *protp; char numbuf[16]; + strlcpy(path_net_init, PPP_PATH_NET_INIT, MAXPATHLEN); + strlcpy(path_net_preup, PPP_PATH_NET_PREUP, MAXPATHLEN); + strlcpy(path_net_down, PPP_PATH_NET_DOWN, MAXPATHLEN); + strlcpy(path_ipup, PPP_PATH_IPUP, MAXPATHLEN); strlcpy(path_ipdown, PPP_PATH_IPDOWN, MAXPATHLEN); @@ -844,7 +848,7 @@ set_ifunit(int iskey) create_pidfile(getpid()); /* write pid to file */ create_linkpidfile(getpid()); } - run_net_script(PPP_PATH_NET_INIT, 1); + run_net_script(path_net_init, 1); } /* @@ -1252,7 +1256,7 @@ new_phase(ppp_phase_t p) if (phase <= PHASE_NETWORK) { char iftmpname[IFNAMSIZ]; int ifindex = if_nametoindex(ifname); - run_net_script(PPP_PATH_NET_PREUP, 1); + run_net_script(path_net_preup, 1); if (if_indextoname(ifindex, iftmpname) && strcmp(iftmpname, ifname)) { info("Detected interface name change from %s to %s.", ifname, iftmpname); strcpy(ifname, iftmpname); @@ -1260,7 +1264,7 @@ new_phase(ppp_phase_t p) } break; case PHASE_DISCONNECT: - run_net_script(PPP_PATH_NET_DOWN, 0); + run_net_script(path_net_down, 0); break; } diff --git a/pppd/options.c b/pppd/options.c index 227e615..9dbc883 100644 --- a/pppd/options.c +++ b/pppd/options.c @@ -121,6 +121,9 @@ char linkname[MAXPATHLEN]; /* logical name for link */ bool tune_kernel; /* may alter kernel settings */ int connect_delay = 1000; /* wait this many ms after connect script */ int req_unit = -1; /* requested interface unit */ +char path_net_init[MAXPATHLEN]; /* pathname of net-init script */ +char path_net_preup[MAXPATHLEN];/* pathname of net-pre-up script */ +char path_net_down[MAXPATHLEN]; /* pathname of net-down script */ char path_ipup[MAXPATHLEN]; /* pathname of ip-up script */ char path_ipdown[MAXPATHLEN];/* pathname of ip-down script */ char req_ifname[IFNAMSIZ]; /* requested interface name */ @@ -331,6 +334,16 @@ struct option general_options[] = { "Metric to use for the default route (Linux only; -1 for default behavior)", OPT_PRIV|OPT_LLIMIT|OPT_INITONLY, NULL, 0, -1 }, + { "net-init-script", o_string, path_net_init, + "Set pathname of net-init script", + OPT_PRIV|OPT_STATIC, NULL, MAXPATHLEN }, + { "net-pre-up-script", o_string, path_net_preup, + "Set pathname of net-preup script", + OPT_PRIV|OPT_STATIC, NULL, MAXPATHLEN }, + { "net-down-script", o_string, path_net_down, + "Set pathname of net-down script", + OPT_PRIV|OPT_STATIC, NULL, MAXPATHLEN }, + { "ip-up-script", o_string, path_ipup, "Set pathname of ip-up script", OPT_PRIV|OPT_STATIC, NULL, MAXPATHLEN }, diff --git a/pppd/pppd-private.h b/pppd/pppd-private.h index 46ce0c8..442c688 100644 --- a/pppd/pppd-private.h +++ b/pppd/pppd-private.h @@ -192,6 +192,9 @@ extern bool tune_kernel; /* May alter kernel settings as necessary */ extern int connect_delay; /* Time to delay after connect script */ extern int max_data_rate; /* max bytes/sec through charshunt */ extern int req_unit; /* interface unit number to use */ +extern char path_net_init[]; /* pathname of net-init script */ +extern char path_net_preup[];/* pathname of net-pre-up script */ +extern char path_net_down[]; /* pathname of net-down script */ extern char path_ipup[]; /* pathname of ip-up script */ extern char path_ipdown[]; /* pathname of ip-down script */ extern char req_ifname[]; /* interface name to use (IFNAMSIZ) */ -- 2.39.5