summaryrefslogtreecommitdiff
path: root/accel-pppd/libnetlink
diff options
context:
space:
mode:
authorKozlov Dmitry <xeb@mail.ru>2012-07-15 02:21:07 +0400
committerKozlov Dmitry <xeb@mail.ru>2012-07-15 02:21:07 +0400
commite687bb04784040fb26c231540e3c7b3ad9fd73d9 (patch)
treef0fce402e40b2043add9d59c8b9b811aa212b112 /accel-pppd/libnetlink
parent177d7a666c96c66cadc44917654a7892dbad9150 (diff)
downloadaccel-ppp-e687bb04784040fb26c231540e3c7b3ad9fd73d9.tar.gz
accel-ppp-e687bb04784040fb26c231540e3c7b3ad9fd73d9.zip
ipoe: better support for ip unnumbered
Diffstat (limited to 'accel-pppd/libnetlink')
-rw-r--r--accel-pppd/libnetlink/iplink.c138
-rw-r--r--accel-pppd/libnetlink/iplink.h5
2 files changed, 143 insertions, 0 deletions
diff --git a/accel-pppd/libnetlink/iplink.c b/accel-pppd/libnetlink/iplink.c
index df00285b..779a8aeb 100644
--- a/accel-pppd/libnetlink/iplink.c
+++ b/accel-pppd/libnetlink/iplink.c
@@ -11,6 +11,9 @@
#include <errno.h>
#include <time.h>
#include <sys/uio.h>
+//#include <linux/if_link.h>
+//#include <linux/if_addr.h>
+//#include <linux/rtnetlink.h>
#include "triton.h"
#include "log.h"
@@ -158,6 +161,141 @@ int __export iplink_get_stats(int ifindex, struct rtnl_link_stats *stats)
return 0;
}
+int __export ipaddr_add(int ifindex, in_addr_t addr, int mask)
+{
+ struct ipaddr_req {
+ struct nlmsghdr n;
+ struct ifaddrmsg i;
+ char buf[1024];
+ } req;
+
+ if (!rth)
+ open_rth();
+
+ if (!rth)
+ return -1;
+
+ memset(&req, 0, sizeof(req) - 1024);
+
+ req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifaddrmsg));
+ req.n.nlmsg_flags = NLM_F_REQUEST | NLM_F_CREATE;
+ req.n.nlmsg_type = RTM_NEWADDR;
+ req.i.ifa_family = AF_INET;
+ req.i.ifa_index = ifindex;
+ req.i.ifa_prefixlen = mask;
+
+ addattr32(&req.n, sizeof(req), IFA_LOCAL, addr);
+
+ if (rtnl_talk(rth, &req.n, 0, 0, NULL, NULL, NULL, 0) < 0)
+ return -1;
+
+ return 0;
+}
+
+int __export ipaddr_del(int ifindex, in_addr_t addr)
+{
+ struct ipaddr_req {
+ struct nlmsghdr n;
+ struct ifaddrmsg i;
+ char buf[1024];
+ } req;
+
+ if (!rth)
+ open_rth();
+
+ if (!rth)
+ return -1;
+
+ memset(&req, 0, sizeof(req) - 1024);
+
+ 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);
+
+ if (rtnl_talk(rth, &req.n, 0, 0, NULL, NULL, NULL, 0) < 0)
+ return -1;
+
+ return 0;
+}
+
+int __export iproute_add(int ifindex, in_addr_t src, in_addr_t dst)
+{
+ struct ipaddr_req {
+ struct nlmsghdr n;
+ struct rtmsg i;
+ char buf[1024];
+ } req;
+
+ 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 | NLM_F_CREATE;
+ req.n.nlmsg_type = RTM_NEWROUTE;
+ req.i.rtm_family = AF_INET;
+ req.i.rtm_table = RT_TABLE_MAIN;
+ req.i.rtm_scope = RT_SCOPE_LINK;
+ req.i.rtm_protocol = RTPROT_BOOT;
+ req.i.rtm_type = RTN_UNICAST;
+ req.i.rtm_dst_len = 32;
+
+ addattr32(&req.n, sizeof(req), RTA_PREFSRC, src);
+ addattr32(&req.n, sizeof(req), RTA_DST, dst);
+ addattr32(&req.n, sizeof(req), RTA_OIF, ifindex);
+
+ if (rtnl_talk(rth, &req.n, 0, 0, NULL, NULL, NULL, 0) < 0)
+ return -1;
+
+ return 0;
+}
+
+int __export iproute_del(int ifindex, in_addr_t dst)
+{
+ struct ipaddr_req {
+ struct nlmsghdr n;
+ struct rtmsg i;
+ char buf[1024];
+ } req;
+
+ 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 | NLM_F_ACK;
+ req.n.nlmsg_type = RTM_DELROUTE;
+ req.i.rtm_family = AF_INET;
+ req.i.rtm_table = RT_TABLE_MAIN;
+ req.i.rtm_scope = RT_SCOPE_LINK;
+ req.i.rtm_protocol = RTPROT_BOOT;
+ req.i.rtm_type = RTN_UNICAST;
+ req.i.rtm_dst_len = 32;
+
+ addattr32(&req.n, sizeof(req), RTA_DST, dst);
+ addattr32(&req.n, sizeof(req), RTA_OIF, ifindex);
+
+ if (rtnl_talk(rth, &req.n, 0, 0, NULL, NULL, NULL, 0) < 0)
+ return -1;
+
+ return 0;
+}
+
+
+
static void init(void)
{
pthread_key_create(&rth_key, free_rth);
diff --git a/accel-pppd/libnetlink/iplink.h b/accel-pppd/libnetlink/iplink.h
index e67e8ed5..a6af6627 100644
--- a/accel-pppd/libnetlink/iplink.h
+++ b/accel-pppd/libnetlink/iplink.h
@@ -8,4 +8,9 @@ typedef int (*iplink_list_func)(int index, int flags, const char *name, void *ar
int iplink_list(iplink_list_func func, void *arg);
int iplink_get_stats(int ifindex, struct rtnl_link_stats *stats);
+int ipaddr_add(int ifindex, in_addr_t addr, int mask);
+int ipaddr_del(int ifindex, in_addr_t addr);
+
+int iproute_add(int ifindex, in_addr_t src, in_addr_t dst);
+int iproute_del(int ifindex, in_addr_t dst);
#endif