From f5b1c3f98bf082d4ecf57e8f2e3c61fc993d80e7 Mon Sep 17 00:00:00 2001 From: Simon Chopin Date: Fri, 28 Feb 2020 11:28:07 +0100 Subject: net: new function get_ifindex The index of a given interface is an operation that highly depends on the network namespace we're in. This patch simply cuts out a function to get the index for a given interface name from the session initialization code, and expose it in the ap_net structure. This function can then be used to refresh the index when moving interfaces around. Signed-off-by: Simon Chopin --- accel-pppd/include/ap_net.h | 1 + accel-pppd/net.c | 18 ++++++++++++++++++ accel-pppd/session.c | 14 ++------------ 3 files changed, 21 insertions(+), 12 deletions(-) (limited to 'accel-pppd') diff --git a/accel-pppd/include/ap_net.h b/accel-pppd/include/ap_net.h index 91ebdd5..984c6c1 100644 --- a/accel-pppd/include/ap_net.h +++ b/accel-pppd/include/ap_net.h @@ -31,6 +31,7 @@ struct ap_net { void (*rtnl_put)(struct rtnl_handle *); int (*rtnl_open)(struct rtnl_handle *h, int proto); int (*move_link)(struct ap_net *net, int ifindex); + int (*get_ifindex)(const char * ifname); void (*release)(struct ap_net *net); }; diff --git a/accel-pppd/net.c b/accel-pppd/net.c index e5cf281..9a025ed 100644 --- a/accel-pppd/net.c +++ b/accel-pppd/net.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -215,6 +216,22 @@ static int def_move_link(struct ap_net *new_net, int ifindex) #endif } +static int def_get_ifindex(const char *ifname) +{ + struct kern_net *n = container_of(net, typeof(*n), net); + struct ifreq ifr; + + memset(&ifr, 0, sizeof(ifr)); + strcpy(ifr.ifr_name, ifname); + + if (ioctl(n->sock, SIOCGIFINDEX, &ifr)) { + log_ppp_error("ioctl(SIOCGIFINDEX): %s\n", strerror(errno)); + return -1; + } + return ifr.ifr_ifindex; +} + + static void def_release(struct ap_net *d) { struct kern_net *n = container_of(d, typeof(*n), net); @@ -299,6 +316,7 @@ static struct ap_net *alloc_net(const char *name) net->rtnl_put = def_rtnl_put; net->rtnl_open = def_rtnl_open; net->move_link = def_move_link; + net->get_ifindex = def_get_ifindex; net->release = def_release; n->sock = socket(AF_INET, SOCK_DGRAM, 0); diff --git a/accel-pppd/session.c b/accel-pppd/session.c index 8ef569e..1411f24 100644 --- a/accel-pppd/session.c +++ b/accel-pppd/session.c @@ -88,21 +88,11 @@ void __export ap_session_set_ifindex(struct ap_session *ses) int __export ap_session_starting(struct ap_session *ses) { - struct ifreq ifr; - if (ap_shutdown) return -1; - if (ses->ifindex == -1 && ses->ifname[0]) { - memset(&ifr, 0, sizeof(ifr)); - strcpy(ifr.ifr_name, ses->ifname); - - if (net->sock_ioctl(SIOCGIFINDEX, &ifr)) { - log_ppp_error("ioctl(SIOCGIFINDEX): %s\n", strerror(errno)); - return -1; - } - ses->ifindex = ifr.ifr_ifindex; - } + if (ses->ifindex == -1 && ses->ifname[0]) + ses->ifindex = net->get_ifindex(ses->ifname); if (ses->ifindex != -1) ap_session_set_ifindex(ses); -- cgit v1.2.3 From 8a1dcdb180e7e5486e4c9c0f81f02c5a03ec0b31 Mon Sep 17 00:00:00 2001 From: Simon Chopin Date: Fri, 28 Feb 2020 11:43:06 +0100 Subject: ifconfig: reset the ifindex when moving namespaces If you move an interface into a namespace where there is alreay an interface with the same index, the moved interface will get a new index assigned to it. We need to update our data structure accordingly. Signed-off-by: Simon Chopin --- accel-pppd/ifcfg.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'accel-pppd') diff --git a/accel-pppd/ifcfg.c b/accel-pppd/ifcfg.c index fbd11bf..d939547 100644 --- a/accel-pppd/ifcfg.c +++ b/accel-pppd/ifcfg.c @@ -319,6 +319,9 @@ int __export ap_session_rename(struct ap_session *ses, const char *ifname, int l } ses->net = ns; net = ns; + + /* Refresh the index now that it is in a new namespace */ + ses->ifindex = net->get_ifindex(ses->ifname); log_ppp_info2("move to namespace %s\n", ns->name); } -- cgit v1.2.3 From c4c85030efdba8a927bbca7f8b010a0152f823cb Mon Sep 17 00:00:00 2001 From: Simon Chopin Date: Fri, 28 Feb 2020 11:43:06 +0100 Subject: ppp: reset the ifindex when moving back to the default namespace If you move an interface into a namespace where there is alreay an interface with the same index, the moved interface will get a new index assigned to it. We need to update our data structure accordingly. Signed-off-by: Simon Chopin --- accel-pppd/ppp/ppp.c | 1 + 1 file changed, 1 insertion(+) (limited to 'accel-pppd') diff --git a/accel-pppd/ppp/ppp.c b/accel-pppd/ppp/ppp.c index 0606f3f..49b53b1 100644 --- a/accel-pppd/ppp/ppp.c +++ b/accel-pppd/ppp/ppp.c @@ -280,6 +280,7 @@ static void destablish_ppp(struct ppp_t *ppp) } ppp->ses.net = def_net; net = def_net; + ppp->ses.ifindex = net->get_ifindex(ppp->ses.ifname); } sprintf(ifr.ifr_newname, "ppp%i", ppp->ses.unit_idx); -- cgit v1.2.3 From a00278542122641b82cd0ba74c5f232099de182a Mon Sep 17 00:00:00 2001 From: stetsyuk <52718548+stetsyuk@users.noreply.github.com> Date: Thu, 2 Apr 2020 11:17:28 +0300 Subject: Fix radius Framed-IP-Address Add htonl to check if Framed-IP-Address==0xFFFFFFFE Ignore 0xFFFFFFFE as Framed-IP-Address in DM/CoA requests --- accel-pppd/radius/radius.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'accel-pppd') diff --git a/accel-pppd/radius/radius.c b/accel-pppd/radius/radius.c index e5a65a5..e3fe4b3 100644 --- a/accel-pppd/radius/radius.c +++ b/accel-pppd/radius/radius.c @@ -316,7 +316,7 @@ int rad_proc_attrs(struct rad_req_t *req) case Framed_IP_Address: if (!conf_gw_ip_address && rpd->ses->ctrl->ppp) log_ppp_warn("radius: gw-ip-address not specified, cann't assign IP address...\n"); - else if (attr->val.ipaddr != 0xfffffffe) { + else if (attr->val.ipaddr != htonl(0xfffffffe)) { rpd->ipv4_addr.owner = &ipdb; rpd->ipv4_addr.peer_addr = attr->val.ipaddr; rpd->ipv4_addr.addr = rpd->ses->ctrl->ppp ? conf_gw_ip_address : 0; @@ -817,7 +817,8 @@ struct radius_pd_t *rad_find_session_pack(struct rad_packet_t *pack) port_id = attr->val.string; break; case Framed_IP_Address: - ipaddr = attr->val.ipaddr; + if (attr->val.ipaddr != htonl(0xfffffffe)) + ipaddr = attr->val.ipaddr; break; case Calling_Station_Id: csid = attr->val.string; -- cgit v1.2.3