From: Philippe Guibert Date: Fri, 20 Dec 2019 10:23:05 +0000 (+0100) Subject: nhrpd: cleaning netlink gre information X-Git-Tag: base_8.0~47^2~5 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=aea6c49e01afccb68a6559832dd74924e13b8e61;p=matthieu%2Ffrr.git 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 --- diff --git a/include/linux/if_packet.h b/include/linux/if_packet.h new file mode 100644 index 0000000000..057edb33dc --- /dev/null +++ b/include/linux/if_packet.h @@ -0,0 +1,16 @@ +#ifndef __LINUX_IF_PACKET_H +#define __LINUX_IF_PACKET_H + +#include + +struct sockaddr_ll { + unsigned short sll_family; + __be16 sll_protocol; + int sll_ifindex; + unsigned short sll_hatype; + unsigned char sll_pkttype; + unsigned char sll_halen; + unsigned char sll_addr[8]; +}; + +#endif diff --git a/lib/zclient.c b/lib/zclient.c index e2f99aebf3..3ea1789441 100644 --- a/lib/zclient.c +++ b/lib/zclient.c @@ -4262,8 +4262,6 @@ int zclient_send_zebra_gre_request(struct zclient *client, struct interface *ifp) { struct stream *s; - ifindex_t idx_local; - int ret; if (!client || client->sock < 0) { zlog_err("%s : zclient not ready", __func__); @@ -4278,7 +4276,4 @@ int zclient_send_zebra_gre_request(struct zclient *client, stream_putw_at(s, 0, stream_get_endp(s)); zclient_send_message(client); return 0; -stream_failure: - zlog_err("%s(): error reading response ..", __func__); - return 0; } 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 #include #include -#include -#include -#include +#include #include -#include #include #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 +#include +#include +#include -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 -#include -#include -#include -#include -#include -#include -#include - -#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 \