summaryrefslogtreecommitdiff
path: root/accel-pppd
diff options
context:
space:
mode:
authorDmitry Kozlov <xeb@mail.ru>2016-12-08 18:12:23 +0300
committerDmitry Kozlov <xeb@mail.ru>2016-12-08 18:19:01 +0300
commitfc33b4c6ec83533d35db3626887fb5156478bca3 (patch)
tree86c67ea62ed87c000149ef6fe703ba53283966a3 /accel-pppd
parentbe063e68bbbba46048215a8fdfccf511af45c490 (diff)
downloadaccel-ppp-fc33b4c6ec83533d35db3626887fb5156478bca3.tar.gz
accel-ppp-fc33b4c6ec83533d35db3626887fb5156478bca3.zip
ipoe: fixed nat support
Diffstat (limited to 'accel-pppd')
-rw-r--r--accel-pppd/ctrl/ipoe/ipoe.c24
-rw-r--r--accel-pppd/libnetlink/iputils.c37
-rw-r--r--accel-pppd/libnetlink/iputils.h3
3 files changed, 57 insertions, 7 deletions
diff --git a/accel-pppd/ctrl/ipoe/ipoe.c b/accel-pppd/ctrl/ipoe/ipoe.c
index fe5f2283..39f414ab 100644
--- a/accel-pppd/ctrl/ipoe/ipoe.c
+++ b/accel-pppd/ctrl/ipoe/ipoe.c
@@ -932,8 +932,10 @@ static void __ipoe_session_activate(struct ipoe_session *ses)
if (ses->ifindex == -1) {
if (serv->opt_ifcfg)
- ipaddr_add_peer(serv->ifindex, ses->router, 32, ses->yiaddr);
- } else
+ ipaddr_add_peer(serv->ifindex, ses->router, ses->yiaddr);
+ } else if (ses->ses.ipv4->peer_addr != ses->yiaddr)
+ ipaddr_add_peer(ses->ifindex, ses->router, ses->yiaddr);
+ else
ses->ctrl.dont_ifcfg = 0;
if (ses->serv->opt_mode == MODE_L2 && ses->serv->opt_ipv6 && sock6_fd != -1) {
@@ -1061,6 +1063,9 @@ static void ipoe_session_started(struct ap_session *s)
}
ses->dhcpv4->recv = ipoe_ses_recv_dhcpv4;
}
+
+ if (ses->ses.ipv4->peer_addr != ses->yiaddr)
+ iproute_add(ses->ifindex, ses->ses.ipv4->addr, ses->ses.ipv4->peer_addr, 0, conf_proto, 32);
}
static void ipoe_session_free(struct ipoe_session *ses)
@@ -1107,11 +1112,23 @@ static void ipoe_session_finished(struct ap_session *s)
struct ipoe_session *ses = container_of(s, typeof(*ses), ses);
struct ipoe_serv *serv = ses->serv;
struct unit_cache *uc;
+ struct ifreq ifr;
log_ppp_info1("ipoe: session finished\n");
if (ses->ifindex != -1) {
- if (uc_size < conf_unit_cache && !ipoe_nl_modify(ses->ifindex, 0, 0, 0, 0, NULL)) {
+ if (uc_size < conf_unit_cache) {
+ strcpy(ifr.ifr_name, s->ifname);
+ ioctl(sock_fd, SIOCGIFFLAGS, &ifr);
+ if (ifr.ifr_flags & IFF_UP) {
+ ifr.ifr_flags &= ~IFF_UP;
+ ioctl(sock_fd, SIOCSIFFLAGS, &ifr);
+ }
+
+ ipaddr_del_peer(ses->ifindex, ses->router, ses->yiaddr);
+
+ ipoe_nl_modify(ses->ifindex, 0, 0, 0, 0, NULL);
+
uc = mempool_alloc(uc_pool);
uc->ifindex = ses->ifindex;
pthread_mutex_lock(&uc_lock);
@@ -1141,7 +1158,6 @@ static void ipoe_session_finished(struct ap_session *s)
triton_event_fire(EV_CTRL_FINISHED, s);
if (s->ifindex == ses->serv->ifindex && strcmp(s->ifname, ses->serv->ifname)) {
- struct ifreq ifr;
int flags;
log_info2("ipoe: rename %s to %s\n", s->ifname, ses->serv->ifname);
diff --git a/accel-pppd/libnetlink/iputils.c b/accel-pppd/libnetlink/iputils.c
index 8bcee50d..1052b609 100644
--- a/accel-pppd/libnetlink/iputils.c
+++ b/accel-pppd/libnetlink/iputils.c
@@ -329,7 +329,7 @@ int __export ipaddr_add(int ifindex, in_addr_t addr, int mask)
return r;
}
-int __export ipaddr_add_peer(int ifindex, in_addr_t addr, int mask, in_addr_t peer_addr)
+int __export ipaddr_add_peer(int ifindex, in_addr_t addr, in_addr_t peer_addr)
{
struct ipaddr_req {
struct nlmsghdr n;
@@ -349,7 +349,7 @@ int __export ipaddr_add_peer(int ifindex, in_addr_t addr, int mask, in_addr_t pe
req.n.nlmsg_type = RTM_NEWADDR;
req.i.ifa_family = AF_INET;
req.i.ifa_index = ifindex;
- req.i.ifa_prefixlen = mask;
+ req.i.ifa_prefixlen = 32;
addattr32(&req.n, sizeof(req), IFA_LOCAL, addr);
addattr32(&req.n, sizeof(req), IFA_ADDRESS, peer_addr);
@@ -394,6 +394,39 @@ int __export ipaddr_del(int ifindex, in_addr_t addr, int mask)
return r;
}
+int __export ipaddr_del_peer(int ifindex, in_addr_t addr, in_addr_t peer)
+{
+ struct ipaddr_req {
+ struct nlmsghdr n;
+ struct ifaddrmsg i;
+ char buf[4096];
+ } req;
+ struct rtnl_handle *rth = net->rtnl_get();
+ int r = 0;
+
+ if (!rth)
+ return -1;
+
+ memset(&req, 0, sizeof(req) - 4096);
+
+ req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifaddrmsg));
+ req.n.nlmsg_flags = NLM_F_REQUEST;
+ req.n.nlmsg_type = RTM_DELADDR;
+ req.i.ifa_family = AF_INET;
+ req.i.ifa_index = ifindex;
+ req.i.ifa_prefixlen = 32;
+
+ addattr32(&req.n, sizeof(req), IFA_LOCAL, addr);
+ addattr32(&req.n, sizeof(req), IFA_ADDRESS, peer);
+
+ if (rtnl_talk(rth, &req.n, 0, 0, NULL, NULL, NULL, 0) < 0)
+ r = -1;
+
+ net->rtnl_put(rth);
+
+ return r;
+}
+
int __export iproute_add(int ifindex, in_addr_t src, in_addr_t dst, in_addr_t gw, int proto, int mask)
{
struct ipaddr_req {
diff --git a/accel-pppd/libnetlink/iputils.h b/accel-pppd/libnetlink/iputils.h
index a623197f..301cfed1 100644
--- a/accel-pppd/libnetlink/iputils.h
+++ b/accel-pppd/libnetlink/iputils.h
@@ -13,8 +13,9 @@ int iplink_vlan_del(int ifindex);
int iplink_vlan_get_vid(int ifindex, int *iflink);
int ipaddr_add(int ifindex, in_addr_t addr, int mask);
-int ipaddr_add_peer(int ifindex, in_addr_t addr, int mask, in_addr_t peer_addr);
+int ipaddr_add_peer(int ifindex, in_addr_t addr, in_addr_t peer_addr);
int ipaddr_del(int ifindex, in_addr_t addr, int mask);
+int ipaddr_del_peer(int ifindex, in_addr_t addr, in_addr_t peer);
int iproute_add(int ifindex, in_addr_t src, in_addr_t dst, in_addr_t gw, int proto, int mask);
int iproute_del(int ifindex, in_addr_t dst, int proto, int mask);