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>
This commit is contained in:
Philippe Guibert 2019-12-20 11:23:05 +01:00
parent 7f48cfa5e4
commit aea6c49e01
9 changed files with 20 additions and 182 deletions

16
include/linux/if_packet.h Normal file
View File

@ -0,0 +1,16 @@
#ifndef __LINUX_IF_PACKET_H
#define __LINUX_IF_PACKET_H
#include <linux/types.h>
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

View File

@ -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;
}

View File

@ -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,

View File

@ -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);

View File

@ -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;
}

View File

@ -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);
}

View File

@ -19,7 +19,6 @@
#include "nhrpd.h"
#include "os.h"
#include "netlink.h"
#include "hash.h"
DEFINE_MTYPE_STATIC(NHRPD, NHRP_IF, "NHRP interface");

View File

@ -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();

View File

@ -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 \