summaryrefslogtreecommitdiff
path: root/accel-pppd
diff options
context:
space:
mode:
Diffstat (limited to 'accel-pppd')
-rw-r--r--accel-pppd/ctrl/ipoe/ipoe.c23
-rw-r--r--accel-pppd/libnetlink/iputils.c64
-rw-r--r--accel-pppd/libnetlink/iputils.h1
3 files changed, 85 insertions, 3 deletions
diff --git a/accel-pppd/ctrl/ipoe/ipoe.c b/accel-pppd/ctrl/ipoe/ipoe.c
index 36ba4e36..d9d71de5 100644
--- a/accel-pppd/ctrl/ipoe/ipoe.c
+++ b/accel-pppd/ctrl/ipoe/ipoe.c
@@ -641,8 +641,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)
@@ -940,7 +959,7 @@ static void ipoe_session_finished(struct ap_session *s)
if (ses->relay_addr && ses->serv->dhcpv4_relay)
dhcpv4_relay_send_release(ses->serv->dhcpv4_relay, ses->hwaddr, ses->xid, ses->yiaddr, ses->client_id, ses->relay_agent, ses->serv->ifname, conf_agent_remote_id);
- if (s->ipv4) {
+ if (s->ipv4 && s->ipv4->owner) {
ipdb_put_ipv4(s, s->ipv4);
s->ipv4 = NULL;
}
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);