diff options
author | Dmitry Kozlov <xeb@mail.ru> | 2014-05-18 03:02:29 +0000 |
---|---|---|
committer | Dmitry Kozlov <xeb@mail.ru> | 2014-05-18 03:02:29 +0000 |
commit | d3a17940de818452970a80cb7dba7a793f8ee1e2 (patch) | |
tree | 0800f5975b6e5bd6fca886f3922e74f407aa3e9e | |
parent | ad39c45f1fe5ba4f84c87de6166c55c2c176840c (diff) | |
download | accel-ppp-d3a17940de818452970a80cb7dba7a793f8ee1e2.tar.gz accel-ppp-d3a17940de818452970a80cb7dba7a793f8ee1e2.zip |
2-way interface renaming
First try to rename interface immediately and if it fails then do second try later just before bring interface up.
In case single-session=replace first try to rename interface may fail because first session may be active
-rw-r--r-- | accel-pppd/ifcfg.c | 19 | ||||
-rw-r--r-- | accel-pppd/include/ap_session.h | 1 | ||||
-rw-r--r-- | accel-pppd/session.c | 5 |
3 files changed, 21 insertions, 4 deletions
diff --git a/accel-pppd/ifcfg.c b/accel-pppd/ifcfg.c index bbbcc02d..02428087 100644 --- a/accel-pppd/ifcfg.c +++ b/accel-pppd/ifcfg.c @@ -18,6 +18,7 @@ #include "ipdb.h" #include "log.h" #include "backup.h" +#include "memdebug.h" // from /usr/include/linux/ipv6.h struct in6_ifreq { @@ -63,6 +64,12 @@ void ap_session_ifup(struct ap_session *ses) struct sockaddr_in addr; struct ppp_t *ppp; + if (ses->ifname_rename) { + ap_session_rename(ses, ses->ifname_rename, -1); + _free(ses->ifname_rename); + ses->ifname_rename = NULL; + } + triton_event_fire(EV_SES_ACCT_START, ses); if (ses->stop_time) return; @@ -246,10 +253,14 @@ void __export ap_session_rename(struct ap_session *ses, const char *ifname, int strcpy(ifr.ifr_name, ses->ifname); memcpy(ifr.ifr_newname, ifname, len); ifr.ifr_newname[len] = 0; - - if (ioctl(sock_fd, SIOCSIFNAME, &ifr)) - log_ppp_warn("interface rename failed: %s\n", strerror(errno)); - else { + + if (ioctl(sock_fd, SIOCSIFNAME, &ifr)) { + if (!ses->ifname_rename) + ses->ifname_rename = _strdup(ifr.ifr_newname); + else + log_ppp_warn("interface rename failed: %s\n", strerror(errno)); + } else { + log_ppp_info2("rename interface to '%s'\n", ifr.ifr_newname); memcpy(ses->ifname, ifname, len); ses->ifname[len] = 0; } diff --git a/accel-pppd/include/ap_session.h b/accel-pppd/include/ap_session.h index cde8dc09..a7cc43fe 100644 --- a/accel-pppd/include/ap_session.h +++ b/accel-pppd/include/ap_session.h @@ -66,6 +66,7 @@ struct ap_session int state; char *chan_name; char ifname[AP_IFNAME_LEN]; + char *ifname_rename; int unit_idx; int ifindex; char sessionid[AP_SESSIONID_LEN+1]; diff --git a/accel-pppd/session.c b/accel-pppd/session.c index 5d12635f..267b960f 100644 --- a/accel-pppd/session.c +++ b/accel-pppd/session.c @@ -176,6 +176,11 @@ void __export ap_session_finished(struct ap_session *ses) _free(ses->ipv6_pool_name); ses->ipv6_pool_name = NULL; } + + if (ses->ifname_rename) { + _free(ses->ifname_rename); + ses->ifname_rename = NULL; + } #ifdef USE_BACKUP if (ses->backup) |