diff options
Diffstat (limited to 'accel-pppd/libnetlink')
-rw-r--r-- | accel-pppd/libnetlink/genl.c | 6 | ||||
-rw-r--r-- | accel-pppd/libnetlink/ipset.c | 16 | ||||
-rw-r--r-- | accel-pppd/libnetlink/iputils.c | 84 | ||||
-rw-r--r-- | accel-pppd/libnetlink/libnetlink.c | 2 |
4 files changed, 54 insertions, 54 deletions
diff --git a/accel-pppd/libnetlink/genl.c b/accel-pppd/libnetlink/genl.c index 7d74556..68405ba 100644 --- a/accel-pppd/libnetlink/genl.c +++ b/accel-pppd/libnetlink/genl.c @@ -83,12 +83,12 @@ int __export genl_resolve_mcg(const char *family, const char *name, int *fam_id) if (!tb[CTRL_ATTR_MCAST_GROUPS]) goto out; - + if (fam_id) *fam_id = *(uint32_t *)(RTA_DATA(tb[CTRL_ATTR_FAMILY_ID])); - + parse_rtattr_nested(tb2, GENL_MAX_FAM_GRPS, tb[CTRL_ATTR_MCAST_GROUPS]); - + for (i = 1; i < GENL_MAX_FAM_GRPS; i++) { if (tb2[i]) { parse_rtattr_nested(tb3, CTRL_ATTR_MCAST_GRP_MAX, tb2[i]); diff --git a/accel-pppd/libnetlink/ipset.c b/accel-pppd/libnetlink/ipset.c index 7312535..7834b64 100644 --- a/accel-pppd/libnetlink/ipset.c +++ b/accel-pppd/libnetlink/ipset.c @@ -41,7 +41,7 @@ static int __ipset_cmd(const char *name, in_addr_t addr, int cmd, int flags) log_error("ipset: cannot open rtnetlink\n"); return -1; } - + memset(&req, 0, sizeof(req) - 4096); req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct nfgenmsg)); @@ -53,18 +53,18 @@ static int __ipset_cmd(const char *name, in_addr_t addr, int cmd, int flags) addattr_l(&req.n, 4096, IPSET_ATTR_PROTOCOL, &protocol, 1); addattr_l(&req.n, 4096, IPSET_ATTR_SETNAME, name, strlen(name) + 1); - + tail1 = addattr_nest(&req.n, MAX_MSG, IPSET_ATTR_DATA | NLA_F_NESTED); tail2 = addattr_nest(&req.n, MAX_MSG, IPSET_ATTR_IP | NLA_F_NESTED); addattr32(&req.n, 4096, IPSET_ATTR_IPADDR_IPV4 | NLA_F_NET_BYTEORDER, addr); addattr_nest_end(&req.n, tail2); - + addattr_nest_end(&req.n, tail1); - + if (rtnl_talk(&rth, &req.n, 0, 0, NULL, NULL, NULL, 0) < 0) goto out_err; - + rtnl_close(&rth); return 0; @@ -100,7 +100,7 @@ int __export ipset_flush(const char *name) log_error("ipset: cannot open rtnetlink\n"); return -1; } - + memset(&req, 0, sizeof(req) - 4096); req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct nfgenmsg)); @@ -112,10 +112,10 @@ int __export ipset_flush(const char *name) addattr_l(&req.n, 4096, IPSET_ATTR_PROTOCOL, &protocol, 1); addattr_l(&req.n, 4096, IPSET_ATTR_SETNAME, name, strlen(name) + 1); - + if (rtnl_talk(&rth, &req.n, 0, 0, NULL, NULL, NULL, 0) < 0) goto out_err; - + rtnl_close(&rth); return 0; diff --git a/accel-pppd/libnetlink/iputils.c b/accel-pppd/libnetlink/iputils.c index fb85973..1544508 100644 --- a/accel-pppd/libnetlink/iputils.c +++ b/accel-pppd/libnetlink/iputils.c @@ -39,7 +39,7 @@ static void open_rth(void) if (!rth) return; - + memset(rth, 0, sizeof(*rth)); if (rtnl_open(rth, 0)) { @@ -78,7 +78,7 @@ static int store_nlmsg(const struct sockaddr_nl *who, struct nlmsghdr *n, void * if (tb[IFLA_IFNAME] == NULL) return 0; - + //printf("%i %s\n", ifi->ifi_index, RTA_DATA(tb[IFLA_IFNAME])); return a->func(ifi->ifi_index, ifi->ifi_flags, RTA_DATA(tb[IFLA_IFNAME]), a->arg); @@ -127,12 +127,12 @@ int __export iplink_get_stats(int ifindex, struct rtnl_link_stats *stats) if (!rth) open_rth(); - + if (!rth) return -1; memset(&req, 0, sizeof(req) - 4096); - + req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg)); req.n.nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK; req.n.nlmsg_type = RTM_GETLINK; @@ -158,10 +158,10 @@ int __export iplink_get_stats(int ifindex, struct rtnl_link_stats *stats) memcpy(stats, RTA_DATA(tb[IFLA_STATS]), sizeof(*stats)); else return -1; - + return 0; } - + int __export iplink_vlan_add(const char *ifname, int ifindex, int vid) { struct iplink_req { @@ -173,20 +173,20 @@ int __export iplink_vlan_add(const char *ifname, int ifindex, int vid) if (!rth) open_rth(); - + if (!rth) return -1; memset(&req, 0, sizeof(req) - 4096); - + req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg)); req.n.nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK | NLM_F_CREATE | NLM_F_EXCL; req.n.nlmsg_type = RTM_NEWLINK; req.i.ifi_family = AF_UNSPEC; - + addattr_l(&req.n, 4096, IFLA_LINK, &ifindex, 4); addattr_l(&req.n, 4096, IFLA_IFNAME, ifname, strlen(ifname)); - + linkinfo = NLMSG_TAIL(&req.n); addattr_l(&req.n, 4096, IFLA_LINKINFO, NULL, 0); addattr_l(&req.n, 4096, IFLA_INFO_KIND, "vlan", 4); @@ -195,12 +195,12 @@ int __export iplink_vlan_add(const char *ifname, int ifindex, int vid) addattr_l(&req.n, 4096, IFLA_INFO_DATA, NULL, 0); addattr_l(&req.n, 4096, IFLA_VLAN_ID, &vid, 2); data->rta_len = (void *)NLMSG_TAIL(&req.n) - (void *)data; - + linkinfo->rta_len = (void *)NLMSG_TAIL(&req.n) - (void *)linkinfo; if (rtnl_talk(rth, &req.n, 0, 0, NULL, NULL, NULL, 0) < 0) return -1; - + return 0; } @@ -215,18 +215,18 @@ int __export iplink_vlan_del(int ifindex) if (!rth) open_rth(); - + if (!rth) return -1; memset(&req, 0, sizeof(req) - 4096); - + req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg)); req.n.nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK; req.n.nlmsg_type = RTM_DELLINK; req.i.ifi_family = AF_UNSPEC; req.i.ifi_index = ifindex; - + linkinfo = NLMSG_TAIL(&req.n); addattr_l(&req.n, 4096, IFLA_LINKINFO, NULL, 0); addattr_l(&req.n, 4096, IFLA_INFO_KIND, "vlan", 4); @@ -234,12 +234,12 @@ int __export iplink_vlan_del(int ifindex) /*data = NLMSG_TAIL(&req.n); addattr_l(&req.n, 4096, IFLA_VLAN_ID, &vid, 2); data->rta_len = (void *)NLMSG_TAIL(&req.n) - (void *)data;*/ - + linkinfo->rta_len = (void *)NLMSG_TAIL(&req.n) - (void *)linkinfo; if (rtnl_talk(rth, &req.n, 0, 0, NULL, NULL, NULL, 0) < 0) return -1; - + return 0; } @@ -253,12 +253,12 @@ int __export ipaddr_add(int ifindex, in_addr_t addr, int mask) if (!rth) open_rth(); - + 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 | NLM_F_CREATE; req.n.nlmsg_type = RTM_NEWADDR; @@ -270,7 +270,7 @@ int __export ipaddr_add(int ifindex, in_addr_t addr, int mask) if (rtnl_talk(rth, &req.n, 0, 0, NULL, NULL, NULL, 0) < 0) return -1; - + return 0; } @@ -284,12 +284,12 @@ int __export ipaddr_del(int ifindex, in_addr_t addr, int mask) if (!rth) open_rth(); - + 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; @@ -301,7 +301,7 @@ int __export ipaddr_del(int ifindex, in_addr_t addr, int mask) if (rtnl_talk(rth, &req.n, 0, 0, NULL, NULL, NULL, 0) < 0) return -1; - + return 0; } @@ -315,12 +315,12 @@ int __export iproute_add(int ifindex, in_addr_t src, in_addr_t dst, in_addr_t gw if (!rth) open_rth(); - + if (!rth) return -1; memset(&req, 0, sizeof(req) - 4096); - + 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; @@ -341,7 +341,7 @@ int __export iproute_add(int ifindex, in_addr_t src, in_addr_t dst, in_addr_t gw if (rtnl_talk(rth, &req.n, 0, 0, NULL, NULL, NULL, 0) < 0) return -1; - + return 0; } @@ -355,12 +355,12 @@ int __export iproute_del(int ifindex, in_addr_t dst, int proto) if (!rth) open_rth(); - + if (!rth) return -1; memset(&req, 0, sizeof(req) - 4096); - + 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; @@ -376,7 +376,7 @@ int __export iproute_del(int ifindex, in_addr_t dst, int proto) if (rtnl_talk(rth, &req.n, 0, 0, NULL, NULL, NULL, 0) < 0) return -1; - + return 0; } @@ -390,12 +390,12 @@ int __export ip6route_add(int ifindex, struct in6_addr *dst, int pref_len, int p if (!rth) open_rth(); - + if (!rth) return -1; memset(&req, 0, sizeof(req) - 4096); - + 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; @@ -411,7 +411,7 @@ int __export ip6route_add(int ifindex, struct in6_addr *dst, int pref_len, int p if (rtnl_talk(rth, &req.n, 0, 0, NULL, NULL, NULL, 0) < 0) return -1; - + return 0; } @@ -433,12 +433,12 @@ in_addr_t __export iproute_get(in_addr_t dst, in_addr_t *gw) if (!rth) open_rth(); - + if (!rth) return -1; memset(&req, 0, sizeof(req) - 4096); - + req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct rtmsg)); req.n.nlmsg_flags = NLM_F_REQUEST; req.n.nlmsg_type = RTM_GETROUTE; @@ -460,7 +460,7 @@ in_addr_t __export iproute_get(in_addr_t dst, in_addr_t *gw) 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; @@ -473,7 +473,7 @@ in_addr_t __export iproute_get(in_addr_t dst, in_addr_t *gw) } parse_rtattr(tb, RTA_MAX, RTM_RTA(r), len); - + if (tb[RTA_PREFSRC]) res = *(uint32_t *)RTA_DATA(tb[RTA_PREFSRC]); @@ -494,12 +494,12 @@ int __export iprule_add(uint32_t addr, int table) if (!rth) open_rth(); - + if (!rth) return -1; memset(&req, 0, sizeof(req) - 4096); - + req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct rtmsg)); req.n.nlmsg_flags = NLM_F_REQUEST; req.n.nlmsg_type = RTM_NEWRULE; @@ -516,7 +516,7 @@ int __export iprule_add(uint32_t addr, int table) if (rtnl_talk(rth, &req.n, 0, 0, NULL, NULL, NULL, 0) < 0) return -1; - + return 0; } @@ -530,12 +530,12 @@ int __export iprule_del(uint32_t addr, int table) if (!rth) open_rth(); - + if (!rth) return -1; memset(&req, 0, sizeof(req) - 4096); - + req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct rtmsg)); req.n.nlmsg_flags = NLM_F_REQUEST; req.n.nlmsg_type = RTM_DELRULE; @@ -552,7 +552,7 @@ int __export iprule_del(uint32_t addr, int table) if (rtnl_talk(rth, &req.n, 0, 0, NULL, NULL, NULL, 0) < 0) return -1; - + return 0; } diff --git a/accel-pppd/libnetlink/libnetlink.c b/accel-pppd/libnetlink/libnetlink.c index 026df82..0536783 100644 --- a/accel-pppd/libnetlink/libnetlink.c +++ b/accel-pppd/libnetlink/libnetlink.c @@ -139,7 +139,7 @@ int __export rtnl_send_check(struct rtnl_handle *rth, const char *buf, int len) struct nlmsgerr *err = (struct nlmsgerr*)NLMSG_DATA(h); if (h->nlmsg_len < NLMSG_LENGTH(sizeof(struct nlmsgerr))) log_debug("libnetlink: ""ERROR truncated\n"); - else + else errno = -err->error; return -1; } |