summaryrefslogtreecommitdiff
path: root/accel-pppd/libnetlink/iputils.c
diff options
context:
space:
mode:
authorDmitry Kozlov <xeb@mail.ru>2013-10-30 16:00:16 +0400
committerDmitry Kozlov <xeb@mail.ru>2013-10-30 16:00:16 +0400
commit7499d96d719042e4b8a89dbbacf2fa9138d700cc (patch)
tree195e9c6e7d13faae7fd16e9891c4e8c06d1c74a0 /accel-pppd/libnetlink/iputils.c
parent2351344eb1dfbe882589acc48cf7ef0c989e862f (diff)
downloadaccel-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>
Diffstat (limited to 'accel-pppd/libnetlink/iputils.c')
-rw-r--r--accel-pppd/libnetlink/iputils.c64
1 files changed, 63 insertions, 1 deletions
diff --git a/accel-pppd/libnetlink/iputils.c b/accel-pppd/libnetlink/iputils.c
index 07aed48..1bbe76b 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;