diff options
| author | Philippe Guibert <philippe.guibert@6wind.com> | 2019-12-20 11:23:05 +0100 | 
|---|---|---|
| committer | Philippe Guibert <philippe.guibert@6wind.com> | 2021-04-30 10:33:18 +0200 | 
| commit | aea6c49e01afccb68a6559832dd74924e13b8e61 (patch) | |
| tree | 1a36c71a49c3f5e119d31fa73cdf825ec324a0e7 /nhrpd | |
| parent | 7f48cfa5e4d93bb8899e0eb815074741df3c8177 (diff) | |
nhrpd: cleaning netlink gre information
flush netlink related dependencies with gre information.
Add some linux headers required to compile with it.
Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
Diffstat (limited to 'nhrpd')
| -rw-r--r-- | nhrpd/linux.c | 6 | ||||
| -rw-r--r-- | nhrpd/netlink.h | 11 | ||||
| -rw-r--r-- | nhrpd/netlink_arp.c | 8 | ||||
| -rw-r--r-- | nhrpd/netlink_gre.c | 152 | ||||
| -rw-r--r-- | nhrpd/nhrp_interface.c | 1 | ||||
| -rw-r--r-- | nhrpd/nhrp_main.c | 2 | ||||
| -rw-r--r-- | nhrpd/subdir.am | 1 | 
7 files changed, 4 insertions, 177 deletions
diff --git a/nhrpd/linux.c b/nhrpd/linux.c index f697311d49..b55e656562 100644 --- a/nhrpd/linux.c +++ b/nhrpd/linux.c @@ -21,16 +21,12 @@  #include <sys/types.h>  #include <asm/types.h>  #include <arpa/inet.h> -#include <linux/netlink.h> -#include <linux/rtnetlink.h> -#include <linux/ip.h> +#include <linux/if_packet.h>  #include <linux/if_arp.h> -#include <linux/if_tunnel.h>  #include <linux/limits.h>  #include "nhrp_protocol.h"  #include "os.h" -#include "netlink.h"  #ifndef HAVE_STRLCPY  size_t strlcpy(char *__restrict dest, diff --git a/nhrpd/netlink.h b/nhrpd/netlink.h index 5e971cabf1..f1143a2b5e 100644 --- a/nhrpd/netlink.h +++ b/nhrpd/netlink.h @@ -7,21 +7,16 @@   * (at your option) any later version.   */ -#include <stdint.h> +#include <zebra.h> +#include <vrf.h> +#include <if.h> -union sockunion; -struct interface;  extern int netlink_nflog_group;  extern int netlink_mcast_nflog_group; -extern int netlink_req_fd; -void netlink_init(void);  int netlink_configure_arp(unsigned int ifindex, int pf);  void netlink_update_binding(struct interface *ifp, union sockunion *proto,  			    union sockunion *nbma);  void netlink_set_nflog_group(int nlgroup); -void netlink_gre_get_info(unsigned int ifindex, uint32_t *gre_key, -			  unsigned int *link_index, struct in_addr *saddr); -void netlink_gre_set_link(unsigned int ifindex, unsigned int link_index); diff --git a/nhrpd/netlink_arp.c b/nhrpd/netlink_arp.c index ecea0a9ec5..5fcb311888 100644 --- a/nhrpd/netlink_arp.c +++ b/nhrpd/netlink_arp.c @@ -25,7 +25,6 @@  #include "netlink.h"  #include "znl.h" -int netlink_req_fd = -1;  int netlink_nflog_group;  static int netlink_log_fd = -1;  static struct thread *netlink_log_thread; @@ -203,10 +202,3 @@ void nhrp_neighbor_operation(ZAPI_CALLBACK_ARGS)  		nhrp_cache_set_used(c, state == ZEBRA_NEIGH_STATE_REACHABLE);  	}  } - -void netlink_init(void) -{ -	netlink_req_fd = znl_open(NETLINK_ROUTE, 0); -	if (netlink_req_fd < 0) -		return; -} diff --git a/nhrpd/netlink_gre.c b/nhrpd/netlink_gre.c deleted file mode 100644 index 3fdfa9c313..0000000000 --- a/nhrpd/netlink_gre.c +++ /dev/null @@ -1,152 +0,0 @@ -/* NHRP netlink/GRE tunnel configuration code - * Copyright (c) 2014-2016 Timo Teräs - * - * This file is free software: you may copy, redistribute and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) any later version. - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include <sys/socket.h> -#include <linux/netlink.h> -#include <linux/rtnetlink.h> -#include <linux/in.h> -#include <linux/if.h> -#include <linux/ip.h> -#include <linux/ipv6.h> -#include <linux/if_tunnel.h> - -#include "debug.h" -#include "netlink.h" -#include "znl.h" - -static int __netlink_gre_get_data(struct zbuf *zb, struct zbuf *data, -				  int ifindex) -{ -	struct nlmsghdr *n; -	struct ifinfomsg *ifi; -	struct zbuf payload, rtapayload; -	struct rtattr *rta; - -	debugf(NHRP_DEBUG_KERNEL, "netlink-link-gre: get-info %u", ifindex); - -	n = znl_nlmsg_push(zb, RTM_GETLINK, NLM_F_REQUEST); -	ifi = znl_push(zb, sizeof(*ifi)); -	*ifi = (struct ifinfomsg){ -		.ifi_index = ifindex, -	}; -	znl_nlmsg_complete(zb, n); - -	if (zbuf_send(zb, netlink_req_fd) < 0 -	    || zbuf_recv(zb, netlink_req_fd) < 0) -		return -1; - -	n = znl_nlmsg_pull(zb, &payload); -	if (!n) -		return -1; - -	if (n->nlmsg_type != RTM_NEWLINK) -		return -1; - -	ifi = znl_pull(&payload, sizeof(struct ifinfomsg)); -	if (!ifi) -		return -1; - -	debugf(NHRP_DEBUG_KERNEL, -	       "netlink-link-gre: ifindex %u, receive msg_type %u, msg_flags %u", -	       ifi->ifi_index, n->nlmsg_type, n->nlmsg_flags); - -	if (ifi->ifi_index != ifindex) -		return -1; - -	while ((rta = znl_rta_pull(&payload, &rtapayload)) != NULL) -		if (rta->rta_type == IFLA_LINKINFO) -			break; -	if (!rta) -		return -1; - -	payload = rtapayload; -	while ((rta = znl_rta_pull(&payload, &rtapayload)) != NULL) -		if (rta->rta_type == IFLA_INFO_DATA) -			break; -	if (!rta) -		return -1; - -	*data = rtapayload; -	return 0; -} - -void netlink_gre_get_info(unsigned int ifindex, uint32_t *gre_key, -			  unsigned int *link_index, struct in_addr *saddr) -{ -	struct zbuf *zb = zbuf_alloc(8192), data, rtapl; -	struct rtattr *rta; - -	*link_index = 0; -	*gre_key = 0; -	saddr->s_addr = 0; - -	if (__netlink_gre_get_data(zb, &data, ifindex) < 0) -		goto err; - -	while ((rta = znl_rta_pull(&data, &rtapl)) != NULL) { -		switch (rta->rta_type) { -		case IFLA_GRE_LINK: -			*link_index = zbuf_get32(&rtapl); -			break; -		case IFLA_GRE_IKEY: -		case IFLA_GRE_OKEY: -			*gre_key = zbuf_get32(&rtapl); -			break; -		case IFLA_GRE_LOCAL: -			saddr->s_addr = zbuf_get32(&rtapl); -			break; -		} -	} -err: -	zbuf_free(zb); -} - -void netlink_gre_set_link(unsigned int ifindex, unsigned int link_index) -{ -	struct nlmsghdr *n; -	struct ifinfomsg *ifi; -	struct rtattr *rta_info, *rta_data, *rta; -	struct zbuf *zr = zbuf_alloc(8192), data, rtapl; -	struct zbuf *zb = zbuf_alloc(8192); -	size_t len; - -	if (__netlink_gre_get_data(zr, &data, ifindex) < 0) -		goto err; - -	n = znl_nlmsg_push(zb, RTM_NEWLINK, NLM_F_REQUEST); -	ifi = znl_push(zb, sizeof(*ifi)); -	*ifi = (struct ifinfomsg){ -		.ifi_index = ifindex, -	}; -	rta_info = znl_rta_nested_push(zb, IFLA_LINKINFO); -	znl_rta_push(zb, IFLA_INFO_KIND, "gre", 3); -	rta_data = znl_rta_nested_push(zb, IFLA_INFO_DATA); - -	znl_rta_push_u32(zb, IFLA_GRE_LINK, link_index); -	while ((rta = znl_rta_pull(&data, &rtapl)) != NULL) { -		if (rta->rta_type == IFLA_GRE_LINK) -			continue; -		len = zbuf_used(&rtapl); -		znl_rta_push(zb, rta->rta_type, zbuf_pulln(&rtapl, len), len); -	} - -	znl_rta_nested_complete(zb, rta_data); -	znl_rta_nested_complete(zb, rta_info); - -	znl_nlmsg_complete(zb, n); -	zbuf_send(zb, netlink_req_fd); -	zbuf_recv(zb, netlink_req_fd); -err: -	zbuf_free(zb); -	zbuf_free(zr); -} diff --git a/nhrpd/nhrp_interface.c b/nhrpd/nhrp_interface.c index 12c86c3876..541e5a992a 100644 --- a/nhrpd/nhrp_interface.c +++ b/nhrpd/nhrp_interface.c @@ -19,7 +19,6 @@  #include "nhrpd.h"  #include "os.h" -#include "netlink.h"  #include "hash.h"  DEFINE_MTYPE_STATIC(NHRPD, NHRP_IF, "NHRP interface"); diff --git a/nhrpd/nhrp_main.c b/nhrpd/nhrp_main.c index e9bce3e09a..c2111a7706 100644 --- a/nhrpd/nhrp_main.c +++ b/nhrpd/nhrp_main.c @@ -26,7 +26,6 @@  #include "filter.h"  #include "nhrpd.h" -#include "netlink.h"  #include "nhrp_errors.h"  DEFINE_MGROUP(NHRPD, "NHRP"); @@ -154,7 +153,6 @@ int main(int argc, char **argv)  	assert(nhrpd_privs.change);  	nhrpd_privs.change(ZPRIVS_RAISE); -	netlink_init();  	evmgr_init();  	nhrp_vc_init();  	nhrp_packet_init(); diff --git a/nhrpd/subdir.am b/nhrpd/subdir.am index d00aecc1ea..9a186d6ed8 100644 --- a/nhrpd/subdir.am +++ b/nhrpd/subdir.am @@ -13,7 +13,6 @@ nhrpd_nhrpd_LDADD = lib/libfrr.la lib/libfrrcares.la $(LIBCAP)  nhrpd_nhrpd_SOURCES = \  	nhrpd/linux.c \  	nhrpd/netlink_arp.c \ -	nhrpd/netlink_gre.c \  	nhrpd/nhrp_cache.c \  	nhrpd/nhrp_errors.c \  	nhrpd/nhrp_event.c \  | 
