Skip to content

Commit

Permalink
add CLI about locator, related funcs and KERNELBYPASS flag on dplane_ctx
Browse files Browse the repository at this point in the history
Signed-off-by: ysj17861081006 <[email protected]>
  • Loading branch information
ysj17861081006 committed Sep 13, 2024
1 parent b774fc6 commit 113f49b
Show file tree
Hide file tree
Showing 19 changed files with 1,228 additions and 165 deletions.
57 changes: 29 additions & 28 deletions lib/command.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ struct host {
/* List of CLI nodes. Please remember to update the name array in command.c. */
/* clang-format off */
enum node_type {
AUTH_NODE, /* Authentication mode of vty interface. */
VIEW_NODE, /* View node. Default mode of vty interface. */
AUTH_NODE, /* Authentication mode of vty interface. */
VIEW_NODE, /* View node. Default mode of vty interface. */
AUTH_ENABLE_NODE, /* Authentication mode for change enable. */
ENABLE_NODE, /* Enable node. */
CONFIG_NODE, /* Config node. Default mode of config file. */
Expand Down Expand Up @@ -134,36 +134,37 @@ enum node_type {
ISIS_FLEX_ALGO_NODE, /* ISIS Flex Algo mode */
ACCESS_NODE, /* Access list node. */
ACCESS_IPV6_NODE, /* Access list node. */
ACCESS_MAC_NODE, /* MAC access list node*/
AS_LIST_NODE, /* AS list node. */
COMMUNITY_LIST_NODE, /* Community list node. */
COMMUNITY_ALIAS_NODE, /* Community alias node. */
RMAP_NODE, /* Route map node. */
PBRMAP_NODE, /* PBR map node. */
SMUX_NODE, /* SNMP configuration node. */
DUMP_NODE, /* Packet dump node. */
FORWARDING_NODE, /* IP forwarding node. */
PROTOCOL_NODE, /* protocol filtering node */
MPLS_NODE, /* MPLS config node */
PW_NODE, /* Pseudowire config node */
SEGMENT_ROUTING_NODE, /* Segment routing root node */
SR_TRAFFIC_ENG_NODE, /* SR Traffic Engineering node */
SR_SEGMENT_LIST_NODE, /* SR segment list config node */
SR_POLICY_NODE, /* SR policy config node */
SR_CANDIDATE_DYN_NODE, /* SR dynamic candidate path config node */
PCEP_NODE, /* PCEP node */
PCEP_PCE_CONFIG_NODE, /* PCE shared configuration node */
PCEP_PCE_NODE, /* PCE configuration node */
PCEP_PCC_NODE, /* PCC configuration node */
SRV6_NODE, /* SRv6 node */
SRV6_LOCS_NODE, /* SRv6 locators node */
SRV6_LOC_NODE, /* SRv6 locator node */
ACCESS_MAC_NODE, /* MAC access list node*/
AS_LIST_NODE, /* AS list node. */
COMMUNITY_LIST_NODE, /* Community list node. */
COMMUNITY_ALIAS_NODE, /* Community alias node. */
RMAP_NODE, /* Route map node. */
PBRMAP_NODE, /* PBR map node. */
SMUX_NODE, /* SNMP configuration node. */
DUMP_NODE, /* Packet dump node. */
FORWARDING_NODE, /* IP forwarding node. */
PROTOCOL_NODE, /* protocol filtering node */
MPLS_NODE, /* MPLS config node */
PW_NODE, /* Pseudowire config node */
SEGMENT_ROUTING_NODE, /* Segment routing root node */
SR_TRAFFIC_ENG_NODE, /* SR Traffic Engineering node */
SR_SEGMENT_LIST_NODE, /* SR segment list config node */
SR_POLICY_NODE, /* SR policy config node */
SR_CANDIDATE_DYN_NODE, /* SR dynamic candidate path config node */
PCEP_NODE, /* PCEP node */
PCEP_PCE_CONFIG_NODE, /* PCE shared configuration node */
PCEP_PCE_NODE, /* PCE configuration node */
PCEP_PCC_NODE, /* PCC configuration node */
SRV6_NODE, /* SRv6 node */
SRV6_LOCS_NODE, /* SRv6 locators node */
SRV6_LOC_NODE, /* SRv6 locator node */
SRV6_PREFIX_NODE, /* SRv6 locator prefix node */
SRV6_ENCAP_NODE, /* SRv6 encapsulation node */
SRV6_SID_FORMATS_NODE, /* SRv6 SID formats config node */
SRV6_SID_FORMAT_USID_F3216_NODE, /* SRv6 uSID f3216 format config node */
SRV6_SID_FORMAT_UNCOMPRESSED_F4024_NODE, /* SRv6 uncompressed f4024 format config node */
VTY_NODE, /* Vty node. */
FPM_NODE, /* Dataplane FPM node. */
VTY_NODE, /* Vty node. */
FPM_NODE, /* Dataplane FPM node. */
LINK_PARAMS_NODE, /* Link-parameters node */
BGP_EVPN_VNI_NODE, /* BGP EVPN VNI */
RPKI_NODE, /* RPKI node for configuration of RPKI cache server
Expand Down
3 changes: 3 additions & 0 deletions lib/nexthop.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ struct nexthop {
(CHECK_FLAG(flags, NEXTHOP_FLAG_ACTIVE) \
&& !CHECK_FLAG(flags, NEXTHOP_FLAG_DUPLICATE))

uint8_t nh_flags;
#define NEXTHOP_FLAG_EVPN_RVTEP (1 << 0) /* EVPN remote vtep nexthop */

/* Nexthop address */
union {
union g_addr gate;
Expand Down
65 changes: 63 additions & 2 deletions lib/srv6.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,14 +158,23 @@ void srv6_locator_chunk_list_free(void *data)
srv6_locator_chunk_free(&chunk);
}

struct srv6_locator *srv6_locator_new()
{
struct srv6_locator *locator = NULL;
locator = XCALLOC(MTYPE_SRV6_LOCATOR, sizeof(struct srv6_locator));
return locator;
}

struct srv6_locator *srv6_locator_alloc(const char *name)
{
struct srv6_locator *locator = NULL;

locator = XCALLOC(MTYPE_SRV6_LOCATOR, sizeof(struct srv6_locator));
locator = srv6_locator_new();
strlcpy(locator->name, name, sizeof(locator->name));
locator->chunks = list_new();
locator->chunks->del = srv6_locator_chunk_list_free;
locator->chunks->del = (void (*)(void *))srv6_locator_chunk_free;

locator->sids = list_new();

QOBJ_REG(locator, srv6_locator);
return locator;
Expand All @@ -179,6 +188,15 @@ struct srv6_locator_chunk *srv6_locator_chunk_alloc(void)
sizeof(struct srv6_locator_chunk));
return chunk;
}
void srv6_locator_del(struct srv6_locator *locator)
{
if (locator->chunks)
list_delete(&locator->chunks);
if (locator->sids)
list_delete(&locator->sids);
XFREE(MTYPE_SRV6_LOCATOR, locator);
return;
}

void srv6_locator_copy(struct srv6_locator *copy,
const struct srv6_locator *locator)
Expand All @@ -205,6 +223,49 @@ void srv6_locator_free(struct srv6_locator *locator)
}
}

struct seg6_sid *srv6_locator_sid_alloc(void)
{
struct seg6_sid *sid = NULL;

sid = XCALLOC(MTYPE_SRV6_LOCATOR_CHUNK, sizeof(struct seg6_sid));
strlcpy(sid->vrfName, "Default", sizeof(sid->vrfName));
return sid;
}
void srv6_locator_sid_free(struct seg6_sid *sid)
{
XFREE(MTYPE_SRV6_LOCATOR_CHUNK, sid);
return;
}

void combine_sid(struct srv6_locator *locator, struct in6_addr *sid_addr,
struct in6_addr *result_addr)
{
uint8_t idx = 0;
uint8_t funcid = 0;
uint8_t locatorbit = 0;
/* uint8_t sidbit = 0;*/
uint8_t totalbit = 0;
uint8_t funbit = 0;
locatorbit =
(locator->block_bits_length + locator->node_bits_length) / 8;
/* sidbit = 16 - locatorbit; */
totalbit = (locator->block_bits_length + locator->node_bits_length +
locator->function_bits_length +
locator->argument_bits_length) /
8;
funbit = (locator->function_bits_length +
locator->argument_bits_length) /
8;
for (idx = 0; idx < locatorbit; idx++) {
result_addr->s6_addr[idx] = locator->prefix.prefix.s6_addr[idx];
}
for (; idx < totalbit; idx++) {
result_addr->s6_addr[idx] =
sid_addr->s6_addr[16 - funbit + funcid];
funcid++;
}
}

void srv6_locator_chunk_free(struct srv6_locator_chunk **chunk)
{
XFREE(MTYPE_SRV6_LOCATOR_CHUNK, *chunk);
Expand Down
36 changes: 36 additions & 0 deletions lib/srv6.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <zebra.h>
#include "prefix.h"
#include "json.h"
#include "vrf.h"

#include <arpa/inet.h>
#include <netinet/in.h>
Expand Down Expand Up @@ -106,6 +107,17 @@ struct seg6local_context {
struct in6_addr nh6;
uint32_t table;
struct seg6local_flavors_info flv;
uint8_t block_bits_length;
uint8_t node_bits_length;
uint8_t function_bits_length;
uint8_t argument_bits_length;
char vrfName[VRF_NAMSIZ + 1];
};

enum srv6_format {
SRV6_FORMAT_F1 = 0, ///< Format 1.
SRV6_FORMAT_USID_3216, ///< uSID 32/16 Format.
SRV6_FORMAT_MAX,
};

struct srv6_locator {
Expand All @@ -125,8 +137,10 @@ struct srv6_locator {
uint64_t current;
bool status_up;
struct list *chunks;
struct list *sids;

uint8_t flags;
enum srv6_format format;
#define SRV6_LOCATOR_USID (1 << 0) /* The SRv6 Locator is a uSID Locator */

/* Pointer to the SID format. */
Expand Down Expand Up @@ -163,6 +177,21 @@ struct srv6_locator_chunk {
uint8_t flags;
};

struct seg6_sid {
enum seg6local_action_t sidaction;
char vrfName[VRF_NAMSIZ + 1];
struct prefix_ipv6 ipv6Addr;
char sidstr[PREFIX_STRLEN];
char ifname[INTERFACE_NAMSIZ];
struct in6_addr nexthop;
};
struct seg6_sid_msg {
char locator_name[SRV6_LOCNAME_SIZE];
enum seg6local_action_t sidaction;
char vrfName[VRF_NAMSIZ + 1];
struct prefix_ipv6 ipv6Addr;
};

/*
* SRv6 Endpoint Behavior codepoints, as defined by IANA in
* https://www.iana.org/assignments/segment-routing/segment-routing.xhtml
Expand Down Expand Up @@ -372,8 +401,15 @@ static inline const char *srv6_sid_ctx2str(char *str, size_t size,
int snprintf_seg6_segs(char *str,
size_t size, const struct seg6_segs *segs);

extern void combine_sid(struct srv6_locator *locator, struct in6_addr *sid_addr,
struct in6_addr *result_addr);
extern void srv6_locator_del(struct srv6_locator *locator);
extern struct srv6_locator *srv6_locator_new();

extern struct srv6_locator *srv6_locator_alloc(const char *name);
extern struct srv6_locator_chunk *srv6_locator_chunk_alloc(void);
extern struct seg6_sid *srv6_locator_sid_alloc(void);
extern void srv6_locator_sid_free(struct seg6_sid *sid);
extern void srv6_locator_free(struct srv6_locator *locator);
extern void srv6_locator_chunk_list_free(void *data);
extern void srv6_locator_chunk_free(struct srv6_locator_chunk **chunk);
Expand Down
28 changes: 28 additions & 0 deletions lib/zclient.c
Original file line number Diff line number Diff line change
Expand Up @@ -1156,6 +1156,34 @@ int zapi_srv6_locator_decode(struct stream *s, struct srv6_locator *l)
return -1;
}

int zapi_srv6_locator_sid_encode(struct stream *s, struct srv6_locator *loc)
{
struct seg6_sid *sidtmp = NULL;
struct listnode *node = NULL;

stream_putw(s, strlen(loc->name));
stream_put(s, loc->name, strlen(loc->name));

stream_putw(s, loc->prefix.prefixlen);
stream_put(s, &loc->prefix.prefix, sizeof(loc->prefix.prefix));
stream_putc(s, loc->block_bits_length);
stream_putc(s, loc->node_bits_length);
stream_putc(s, loc->function_bits_length);
stream_putc(s, loc->argument_bits_length);

stream_putl(s, loc->sids->count);
for (ALL_LIST_ELEMENTS_RO(loc->sids, node, sidtmp)) {
stream_putw(s, sidtmp->ipv6Addr.prefixlen);
stream_put(s, &sidtmp->ipv6Addr.prefix,
sizeof(sidtmp->ipv6Addr.prefix));
stream_putl(s, sidtmp->sidaction);
stream_putw(s, strlen(sidtmp->vrfName));
stream_put(s, sidtmp->vrfName, strlen(sidtmp->vrfName));
}

return 0;
}

static int zapi_nhg_encode(struct stream *s, int cmd, struct zapi_nhg *api_nhg)
{
int i;
Expand Down
9 changes: 9 additions & 0 deletions lib/zclient.h
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,12 @@ struct zapi_route {
*/
#define ZEBRA_FLAG_OUTOFSYNC 0x400

/*
* This flag lets us know that the route entry is set to bypass
* kernel for some reason (e.g. route-map, etc)
*/
#define ZEBRA_FLAG_KERNEL_BYPASS 0x800

/* The older XXX_MESSAGE flags live here */
uint32_t message;

Expand Down Expand Up @@ -1088,6 +1094,9 @@ extern struct interface *zebra_interface_link_params_read(struct stream *s,
bool *changed);
extern size_t zebra_interface_link_params_write(struct stream *,
struct interface *);

extern int zapi_srv6_locator_sid_encode(struct stream *s,
struct srv6_locator *loc);
extern enum zclient_send_status
zclient_send_get_label_chunk(struct zclient *zclient, uint8_t keep,
uint32_t chunk_size, uint32_t base);
Expand Down
4 changes: 4 additions & 0 deletions lib/zebra.h
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,10 @@ struct in_pktinfo {

#define strmatch(a,b) (!strcmp((a), (b)))

/* Zebra message flags */

#define ZEBRA_FLAG_LOCAL_SID_ROUTE 0x01

#if BYTE_ORDER == LITTLE_ENDIAN
#define htonll(x) (((uint64_t)htonl((x)&0xFFFFFFFF) << 32) | htonl((x) >> 32))
#define ntohll(x) (((uint64_t)ntohl((x)&0xFFFFFFFF) << 32) | ntohl((x) >> 32))
Expand Down
41 changes: 38 additions & 3 deletions vtysh/vtysh.c
Original file line number Diff line number Diff line change
Expand Up @@ -1329,6 +1329,12 @@ static struct cmd_node srv6_loc_node = {
.prompt = "%s(config-srv6-locator)# ",
};

static struct cmd_node srv6_prefix_node = {
.name = "srv6-locator-prefix",
.node = SRV6_PREFIX_NODE,
.parent_node = SRV6_LOC_NODE,
.prompt = "%s(config-srv6-locator-prefix)# "};

static struct cmd_node srv6_encap_node = {
.name = "srv6-encap",
.node = SRV6_ENCAP_NODE,
Expand Down Expand Up @@ -1704,15 +1710,30 @@ DEFUNSH(VTYSH_ZEBRA, srv6_locators, srv6_locators_cmd,
return CMD_SUCCESS;
}

DEFUNSH(VTYSH_ZEBRA, srv6_locator, srv6_locator_cmd,
"locator WORD",
"Segment Routing SRv6 locator\n"
DEFUNSH(VTYSH_ZEBRA, srv6_locator_sid, srv6_locator_cmd, "locator WORD",
"Segment Routing SRv6 locators locator\n"
"Specify locator-name\n")
{
vty->node = SRV6_LOC_NODE;
return CMD_SUCCESS;
}

DEFUNSH(VTYSH_ZEBRA, srv6_prefix_sid, srv6_prefix_cmd,
"prefix X:X::X:X/M$prefix \
[block-len (16-64)$block_bit_len] [node-len (16-64)$node_bit_len] [func-bits (16-80)$func_bit_len]",
"Configure SRv6 locator prefix\n"
"Specify SRv6 locator prefix\n"
"Configure SRv6 locator block length in bits\n"
"Specify SRv6 locator block length in bits\n"
"Configure SRv6 locator node length in bits\n"
"Specify SRv6 locator node length in bits\n"
"Configure SRv6 locator function length in bits\n"
"Specify SRv6 locator function length in bits\n")
{
vty->node = SRV6_PREFIX_NODE;
return CMD_SUCCESS;
}

DEFUNSH(VTYSH_ZEBRA, srv6_encap, srv6_encap_cmd,
"encapsulation",
"Segment Routing SRv6 encapsulation\n")
Expand Down Expand Up @@ -2562,6 +2583,14 @@ DEFUNSH(VTYSH_ZEBRA, exit_srv6_loc_config, exit_srv6_loc_config_cmd, "exit",
return CMD_SUCCESS;
}

DEFUNSH(VTYSH_ZEBRA, exit_srv6_prefix_config, exit_srv6_prefix_config_cmd,
"exit", "Exit from SRv6-locators prefix configuration mode\n")
{
if (vty->node == SRV6_PREFIX_NODE)
vty->node = SRV6_LOC_NODE;
return CMD_SUCCESS;
}

DEFUNSH(VTYSH_ZEBRA, exit_srv6_encap, exit_srv6_encap_cmd, "exit",
"Exit from SRv6-encapsulation configuration mode\n")
{
Expand Down Expand Up @@ -5451,9 +5480,15 @@ void vtysh_init_vty(void)
install_element(SRV6_LOCS_NODE, &exit_srv6_locs_config_cmd);
install_element(SRV6_LOCS_NODE, &vtysh_end_all_cmd);

install_node(&srv6_loc_node);
install_element(SRV6_LOC_NODE, &srv6_prefix_cmd);
install_element(SRV6_LOC_NODE, &exit_srv6_loc_config_cmd);
install_element(SRV6_LOC_NODE, &vtysh_end_all_cmd);

install_node(&srv6_prefix_node);
install_element(SRV6_PREFIX_NODE, &exit_srv6_prefix_config_cmd);
install_element(SRV6_PREFIX_NODE, &vtysh_end_all_cmd);

install_element(SRV6_ENCAP_NODE, &exit_srv6_encap_cmd);
install_element(SRV6_ENCAP_NODE, &vtysh_end_all_cmd);

Expand Down
Loading

0 comments on commit 113f49b

Please sign in to comment.