Skip to content

Commit

Permalink
route: add nh type
Browse files Browse the repository at this point in the history
  • Loading branch information
zstas authored and thom311 committed Jul 31, 2023
1 parent 1b6433d commit 780d06a
Show file tree
Hide file tree
Showing 6 changed files with 669 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ libnlinclude_netlink_route_HEADERS = \
include/netlink/route/neightbl.h \
include/netlink/route/netconf.h \
include/netlink/route/nexthop.h \
include/netlink/route/nh.h \
include/netlink/route/pktloc.h \
include/netlink/route/qdisc.h \
include/netlink/route/route.h \
Expand Down Expand Up @@ -437,6 +438,7 @@ lib_libnl_route_3_la_SOURCES = \
lib/route/neightbl.c \
lib/route/netconf.c \
lib/route/nexthop.c \
lib/route/nh.c \
lib/route/nexthop_encap.c \
lib/route/nh_encap_mpls.c \
lib/route/pktloc.c \
Expand Down
5 changes: 5 additions & 0 deletions include/netlink-private/nl-auto.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ void rtnl_route_nh_free(struct rtnl_nexthop *);
#define _nl_auto_rtnl_nexthop _nl_auto(_nl_auto_rtnl_nexthop_fcn)
_NL_AUTO_DEFINE_FCN_TYPED0(struct rtnl_nexthop *, _nl_auto_rtnl_nexthop_fcn, rtnl_route_nh_free);

struct rtnl_nh;
void rtnl_nh_put(struct rtnl_nh *);
#define _nl_auto_rtnl_nh _nl_auto(_nl_auto_rtnl_nh_fcn)
_NL_AUTO_DEFINE_FCN_TYPED0(struct rtnl_nh *, _nl_auto_rtnl_nh_fcn, rtnl_nh_put);

struct nl_cache;
void nl_cache_put(struct nl_cache *);
#define _nl_auto_nl_cache _nl_auto(_nl_auto_nl_cache_fcn)
Expand Down
23 changes: 23 additions & 0 deletions include/netlink-private/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <netlink-private/object-api.h>
#include <netlink-private/route/tc-api.h>
#include <netlink-private/route/link/sriov.h>
#include <netlink/route/nh.h>
#include <netlink-private/route/nexthop-encap.h>
#include <linux/netlink.h>
#include <linux/rtnetlink.h>
Expand Down Expand Up @@ -324,6 +325,28 @@ struct rtnl_nexthop
struct rtnl_nh_encap * rtnh_encap;
};

struct rtnl_nexthop_group
{
struct nl_list_head nexthop_list;
int ce_refcnt;
uint32_t id;
uint8_t weight;
};

struct rtnl_nh
{
NLHDR_COMMON

uint8_t nh_family;
uint32_t nh_flags;

uint32_t nh_id;
uint32_t nh_group_type;
nl_nh_group_t * nh_group;
uint32_t nh_oif;
struct nl_addr * nh_gateway;
};

struct rtnl_route
{
NLHDR_COMMON
Expand Down
57 changes: 57 additions & 0 deletions include/netlink/route/nh.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/* SPDX-License-Identifier: LGPL-2.1-only */
/*
* Copyright (c) 2022 Stanislav Zaikin <[email protected]>
*/

#ifndef NETLINK_ROUTE_NEXTHOP2_H_
#define NETLINK_ROUTE_NEXTHOP2_H_

#include <netlink/netlink.h>
#include <netlink/addr.h>

#ifdef __cplusplus
extern "C" {
#endif

struct rtnl_nh;

typedef struct nl_nh_group_info {
uint32_t nh_id; /*!< VLAN number */
uint8_t weight; /*!< VLAN QOS value */
} nl_nh_group_info_t;

typedef struct nl_nh_group {
int ce_refcnt;
unsigned size;
nl_nh_group_info_t *entries;
} nl_nh_group_t;

extern int rtnl_nh_alloc_cache(struct nl_sock *sk, int family,
struct nl_cache **result);
extern struct rtnl_nh *rtnl_nh_alloc(void);
extern struct rtnl_nh *rtnl_nh_clone(struct rtnl_nh *);
extern void rtnl_nh_put(struct rtnl_nh *);

extern struct rtnl_nh *rtnl_nh_get(struct nl_cache *cache, int nhid);

extern int rtnl_nh_compare(struct rtnl_nh *, struct rtnl_nh *, uint32_t, int);

extern void rtnl_nh_dump(struct rtnl_nh *, struct nl_dump_params *);

extern int rtnl_nh_set_gateway(struct rtnl_nh *, struct nl_addr *);
extern struct nl_addr *rtnl_nh_get_gateway(struct rtnl_nh *);

extern int rtnl_nh_set_fdb(struct rtnl_nh *, int value);
extern int rtnl_nh_get_fdb(struct rtnl_nh *);

extern int rtnl_nh_get_group_entry(struct rtnl_nh *, int n);
extern int rtnl_nh_get_group_size(struct rtnl_nh *);

extern int rtnl_nh_get_id(struct rtnl_nh *);
extern int rtnl_nh_get_oif(struct rtnl_nh *);

#ifdef __cplusplus
}
#endif

#endif
Loading

0 comments on commit 780d06a

Please sign in to comment.