diff options
author | Dmitry Kozlov <xeb@mail.ru> | 2013-10-30 16:00:16 +0400 |
---|---|---|
committer | Dmitry Kozlov <xeb@mail.ru> | 2013-10-30 16:00:16 +0400 |
commit | 7499d96d719042e4b8a89dbbacf2fa9138d700cc (patch) | |
tree | 195e9c6e7d13faae7fd16e9891c4e8c06d1c74a0 | |
parent | 2351344eb1dfbe882589acc48cf7ef0c989e862f (diff) | |
download | accel-ppp-7499d96d719042e4b8a89dbbacf2fa9138d700cc.tar.gz accel-ppp-7499d96d719042e4b8a89dbbacf2fa9138d700cc.zip |
ipoe: implemented source/local address detection for up sessions
Signed-off-by: Dmitry Kozlov <xeb@mail.ru>
-rw-r--r-- | accel-pppd/ctrl/ipoe/ipoe.c | 21 | ||||
-rw-r--r-- | accel-pppd/libnetlink/iputils.c | 64 | ||||
-rw-r--r-- | accel-pppd/libnetlink/iputils.h | 1 |
3 files changed, 84 insertions, 2 deletions
diff --git a/accel-pppd/ctrl/ipoe/ipoe.c b/accel-pppd/ctrl/ipoe/ipoe.c index 05ce44e2..8ec49808 100644 --- a/accel-pppd/ctrl/ipoe/ipoe.c +++ b/accel-pppd/ctrl/ipoe/ipoe.c @@ -640,8 +640,27 @@ static void __ipoe_session_start(struct ipoe_session *ses) ses->timer.period = 0; ses->timer.expire_tv.tv_sec = conf_offer_timeout; triton_timer_add(&ses->ctx, &ses->timer, 0); - } else + } else { + if (!ses->siaddr) + find_gw_addr(ses); + + if (!ses->siaddr) + ses->siaddr = ses->serv->opt_src; + + if (!ses->siaddr) + ses->siaddr = iproute_get(ses->yiaddr); + + if (!ses->siaddr) { + log_ppp_error("can't determine local address\n"); + ap_session_terminate(&ses->ses, TERM_NAS_ERROR, 0); + return; + } + + if (ses->ses.ipv4 && !ses->ses.ipv4->addr) + ses->ses.ipv4->addr = ses->siaddr; + __ipoe_session_activate(ses); + } } static void ipoe_serv_add_addr(struct ipoe_serv *serv, in_addr_t addr) diff --git a/accel-pppd/libnetlink/iputils.c b/accel-pppd/libnetlink/iputils.c index 07aed48e..1bbe76ba 100644 --- a/accel-pppd/libnetlink/iputils.c +++ b/accel-pppd/libnetlink/iputils.c @@ -377,10 +377,72 @@ int __export iproute_del(int ifindex, in_addr_t dst, int proto) return 0; } -int __export iprule_add(uint32_t addr, int table) +in_addr_t __export iproute_get(in_addr_t dst) { struct ipaddr_req { struct nlmsghdr n; + struct rtmsg r; + char buf[1024]; + } req; + struct rtmsg *r; + struct rtattr *tb[RTA_MAX+1]; + int len; + in_addr_t res = 0; + + if (!rth) + open_rth(); + + if (!rth) + return -1; + + memset(&req, 0, sizeof(req) - 1024); + + req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct rtmsg)); + req.n.nlmsg_flags = NLM_F_REQUEST; + req.n.nlmsg_type = RTM_GETROUTE; + req.r.rtm_family = AF_INET; + req.r.rtm_table = 0; + req.r.rtm_protocol = 0; + req.r.rtm_scope = 0; + req.r.rtm_type = 0; + req.r.rtm_tos = 0; + req.r.rtm_src_len = 0; + req.r.rtm_dst_len = 32; + + addattr32(&req.n, 1024, RTA_DST, dst); + + if (rtnl_talk(rth, &req.n, 0, 0, &req.n, NULL, NULL, 0) < 0) { + log_error("failed to detect route to server\n"); + goto out; + } + + r = NLMSG_DATA(&req.n); + len = req.n.nlmsg_len; + + if (req.n.nlmsg_type != RTM_NEWROUTE) { + log_error("failed to detect route to server (wrong netlink message type)"); + goto out; + } + + len -= NLMSG_LENGTH(sizeof(*r)); + if (len < 0) { + log_error("failed to detect route to server (wrong netlink message length)"); + goto out; + } + + parse_rtattr(tb, RTA_MAX, RTM_RTA(r), len); + + if (tb[RTA_PREFSRC]) + res = *(uint32_t *)RTA_DATA(tb[RTA_PREFSRC]); + +out: + return res; +} + +int __export iprule_add(uint32_t addr, int table) +{ + struct { + struct nlmsghdr n; struct rtmsg i; char buf[1024]; } req; diff --git a/accel-pppd/libnetlink/iputils.h b/accel-pppd/libnetlink/iputils.h index 2657a5c9..896b4cc5 100644 --- a/accel-pppd/libnetlink/iputils.h +++ b/accel-pppd/libnetlink/iputils.h @@ -16,6 +16,7 @@ int ipaddr_del(int ifindex, in_addr_t addr); int iproute_add(int ifindex, in_addr_t src, in_addr_t dst, int proto); int iproute_del(int ifindex, in_addr_t dst, int proto); +in_addr_t iproute_get(in_addr_t dst); int iprule_add(uint32_t addr, int table); int iprule_del(uint32_t addr, int table); |