diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/agentx.c | 24 | ||||
| -rw-r--r-- | lib/log.c | 2 | ||||
| -rw-r--r-- | lib/netns_linux.c | 2 | ||||
| -rw-r--r-- | lib/srv6.c | 116 | ||||
| -rw-r--r-- | lib/srv6.h | 133 | ||||
| -rw-r--r-- | lib/subdir.am | 2 | ||||
| -rw-r--r-- | lib/zclient.c | 68 | ||||
| -rw-r--r-- | lib/zclient.h | 38 |
8 files changed, 348 insertions, 37 deletions
diff --git a/lib/agentx.c b/lib/agentx.c index 2c6a43d1a7..b479b5ea4c 100644 --- a/lib/agentx.c +++ b/lib/agentx.c @@ -55,28 +55,42 @@ static int agentx_timeout(struct thread *t) static int agentx_read(struct thread *t) { fd_set fds; - int flags; + int flags, new_flags = 0; int nonblock = false; struct listnode *ln = THREAD_ARG(t); list_delete_node(events, ln); /* fix for non blocking socket */ flags = fcntl(THREAD_FD(t), F_GETFL, 0); - if (-1 == flags) + if (-1 == flags) { + flog_err(EC_LIB_SYSTEM_CALL, "Failed to get FD settings fcntl: %s(%d)", + strerror(errno), errno); return -1; + } if (flags & O_NONBLOCK) nonblock = true; else - fcntl(THREAD_FD(t), F_SETFL, flags | O_NONBLOCK); + new_flags = fcntl(THREAD_FD(t), F_SETFL, flags | O_NONBLOCK); + + if (new_flags == -1) + flog_err(EC_LIB_SYSTEM_CALL, "Failed to set snmp fd non blocking: %s(%d)", + strerror(errno), errno); FD_ZERO(&fds); FD_SET(THREAD_FD(t), &fds); snmp_read(&fds); /* Reset the flag */ - if (!nonblock) - fcntl(THREAD_FD(t), F_SETFL, flags); + if (!nonblock) { + new_flags = fcntl(THREAD_FD(t), F_SETFL, flags); + + if (new_flags == -1) + flog_err( + EC_LIB_SYSTEM_CALL, + "Failed to set snmp fd back to original settings: %s(%d)", + strerror(errno), errno); + } netsnmp_check_outstanding_agent_requests(); agentx_events_update(); @@ -1093,7 +1093,7 @@ static const struct zebra_desc_table command_types[] = { DESC_ENTRY(ZEBRA_VXLAN_SG_DEL), DESC_ENTRY(ZEBRA_VXLAN_SG_REPLAY), DESC_ENTRY(ZEBRA_ERROR), -}; + DESC_ENTRY(ZEBRA_CLIENT_CAPABILITIES)}; #undef DESC_ENTRY static const struct zebra_desc_table unknown = {0, "unknown", '?'}; diff --git a/lib/netns_linux.c b/lib/netns_linux.c index d1a31ae35f..4d4376250f 100644 --- a/lib/netns_linux.c +++ b/lib/netns_linux.c @@ -371,7 +371,7 @@ int ns_enable(struct ns *ns, void (*func)(ns_id_t, void *)) void ns_disable(struct ns *ns) { - return ns_disable_internal(ns); + ns_disable_internal(ns); } struct ns *ns_lookup(ns_id_t ns_id) diff --git a/lib/srv6.c b/lib/srv6.c new file mode 100644 index 0000000000..be340f13f5 --- /dev/null +++ b/lib/srv6.c @@ -0,0 +1,116 @@ +/* + * SRv6 definitions + * Copyright (C) 2020 Hiroki Shirokura, LINE Corporation + * + * This program is free software; you can redistribute it 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. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; see the file COPYING; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "srv6.h" +#include "log.h" + +const char *seg6local_action2str(uint32_t action) +{ + switch (action) { + case ZEBRA_SEG6_LOCAL_ACTION_END: + return "End"; + case ZEBRA_SEG6_LOCAL_ACTION_END_X: + return "End.X"; + case ZEBRA_SEG6_LOCAL_ACTION_END_T: + return "End.T"; + case ZEBRA_SEG6_LOCAL_ACTION_END_DX2: + return "End.DX2"; + case ZEBRA_SEG6_LOCAL_ACTION_END_DX6: + return "End.DX6"; + case ZEBRA_SEG6_LOCAL_ACTION_END_DX4: + return "End.DX4"; + case ZEBRA_SEG6_LOCAL_ACTION_END_DT6: + return "End.DT6"; + case ZEBRA_SEG6_LOCAL_ACTION_END_DT4: + return "End.DT4"; + case ZEBRA_SEG6_LOCAL_ACTION_END_B6: + return "End.B6"; + case ZEBRA_SEG6_LOCAL_ACTION_END_B6_ENCAP: + return "End.B6.Encap"; + case ZEBRA_SEG6_LOCAL_ACTION_END_BM: + return "End.BM"; + case ZEBRA_SEG6_LOCAL_ACTION_END_S: + return "End.S"; + case ZEBRA_SEG6_LOCAL_ACTION_END_AS: + return "End.AS"; + case ZEBRA_SEG6_LOCAL_ACTION_END_AM: + return "End.AM"; + case ZEBRA_SEG6_LOCAL_ACTION_UNSPEC: + return "unspec"; + default: + return "unknown"; + } +} + +int snprintf_seg6_segs(char *str, + size_t size, const struct seg6_segs *segs) +{ + str[0] = '\0'; + for (size_t i = 0; i < segs->num_segs; i++) { + char addr[INET6_ADDRSTRLEN]; + bool not_last = (i + 1) < segs->num_segs; + + inet_ntop(AF_INET6, &segs->segs[i], addr, sizeof(addr)); + strlcat(str, addr, size); + strlcat(str, not_last ? "," : "", size); + } + return strlen(str); +} + +const char *seg6local_context2str(char *str, size_t size, + struct seg6local_context *ctx, uint32_t action) +{ + char b0[128]; + + switch (action) { + + case ZEBRA_SEG6_LOCAL_ACTION_END: + snprintf(str, size, "USP"); + return str; + + case ZEBRA_SEG6_LOCAL_ACTION_END_X: + case ZEBRA_SEG6_LOCAL_ACTION_END_DX6: + inet_ntop(AF_INET6, &ctx->nh6, b0, 128); + snprintf(str, size, "nh6 %s", b0); + return str; + + case ZEBRA_SEG6_LOCAL_ACTION_END_DX4: + inet_ntop(AF_INET, &ctx->nh4, b0, 128); + snprintf(str, size, "nh4 %s", b0); + return str; + + case ZEBRA_SEG6_LOCAL_ACTION_END_T: + case ZEBRA_SEG6_LOCAL_ACTION_END_DT6: + case ZEBRA_SEG6_LOCAL_ACTION_END_DT4: + snprintf(str, size, "table %u", ctx->table); + return str; + + case ZEBRA_SEG6_LOCAL_ACTION_END_DX2: + case ZEBRA_SEG6_LOCAL_ACTION_END_B6: + case ZEBRA_SEG6_LOCAL_ACTION_END_B6_ENCAP: + case ZEBRA_SEG6_LOCAL_ACTION_END_BM: + case ZEBRA_SEG6_LOCAL_ACTION_END_S: + case ZEBRA_SEG6_LOCAL_ACTION_END_AS: + case ZEBRA_SEG6_LOCAL_ACTION_END_AM: + case ZEBRA_SEG6_LOCAL_ACTION_UNSPEC: + default: + snprintf(str, size, "unknown(%s)", __func__); + return str; + } +} diff --git a/lib/srv6.h b/lib/srv6.h new file mode 100644 index 0000000000..24c7ffc3a2 --- /dev/null +++ b/lib/srv6.h @@ -0,0 +1,133 @@ +/* + * SRv6 definitions + * Copyright (C) 2020 Hiroki Shirokura, LINE Corporation + * + * This program is free software; you can redistribute it 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. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; see the file COPYING; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef _FRR_SRV6_H +#define _FRR_SRV6_H + +#include <zebra.h> +#include <arpa/inet.h> +#include <netinet/in.h> + +#define SRV6_MAX_SIDS 16 + +#ifdef __cplusplus +extern "C" { +#endif + +#define sid2str(sid, str, size) \ + inet_ntop(AF_INET6, sid, str, size) + +enum seg6_mode_t { + INLINE, + ENCAP, + L2ENCAP, +}; + +enum seg6local_action_t { + ZEBRA_SEG6_LOCAL_ACTION_UNSPEC = 0, + ZEBRA_SEG6_LOCAL_ACTION_END = 1, + ZEBRA_SEG6_LOCAL_ACTION_END_X = 2, + ZEBRA_SEG6_LOCAL_ACTION_END_T = 3, + ZEBRA_SEG6_LOCAL_ACTION_END_DX2 = 4, + ZEBRA_SEG6_LOCAL_ACTION_END_DX6 = 5, + ZEBRA_SEG6_LOCAL_ACTION_END_DX4 = 6, + ZEBRA_SEG6_LOCAL_ACTION_END_DT6 = 7, + ZEBRA_SEG6_LOCAL_ACTION_END_DT4 = 8, + ZEBRA_SEG6_LOCAL_ACTION_END_B6 = 9, + ZEBRA_SEG6_LOCAL_ACTION_END_B6_ENCAP = 10, + ZEBRA_SEG6_LOCAL_ACTION_END_BM = 11, + ZEBRA_SEG6_LOCAL_ACTION_END_S = 12, + ZEBRA_SEG6_LOCAL_ACTION_END_AS = 13, + ZEBRA_SEG6_LOCAL_ACTION_END_AM = 14, + ZEBRA_SEG6_LOCAL_ACTION_END_BPF = 15, +}; + +struct seg6_segs { + size_t num_segs; + struct in6_addr segs[256]; +}; + +struct seg6local_context { + struct in_addr nh4; + struct in6_addr nh6; + uint32_t table; +}; + +static inline const char *seg6_mode2str(enum seg6_mode_t mode) +{ + switch (mode) { + case INLINE: + return "INLINE"; + case ENCAP: + return "ENCAP"; + case L2ENCAP: + return "L2ENCAP"; + default: + return "unknown"; + } +} + +static inline bool sid_same( + const struct in6_addr *a, + const struct in6_addr *b) +{ + if (!a && !b) + return true; + else if (!(a && b)) + return false; + else + return memcmp(a, b, sizeof(struct in6_addr)) == 0; +} + +static inline bool sid_diff( + const struct in6_addr *a, + const struct in6_addr *b) +{ + return !sid_same(a, b); +} + +static inline bool sid_zero( + const struct in6_addr *a) +{ + struct in6_addr zero = {}; + + return sid_same(a, &zero); +} + +static inline void *sid_copy(struct in6_addr *dst, + const struct in6_addr *src) +{ + return memcpy(dst, src, sizeof(struct in6_addr)); +} + +const char * +seg6local_action2str(uint32_t action); + +const char * +seg6local_context2str(char *str, size_t size, + struct seg6local_context *ctx, uint32_t action); + +int snprintf_seg6_segs(char *str, + size_t size, const struct seg6_segs *segs); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/lib/subdir.am b/lib/subdir.am index cb6fa7a3b8..d804d839db 100644 --- a/lib/subdir.am +++ b/lib/subdir.am @@ -51,6 +51,7 @@ lib_libfrr_la_SOURCES = \ lib/mlag.c \ lib/module.c \ lib/mpls.c \ + lib/srv6.c \ lib/network.c \ lib/nexthop.c \ lib/netns_linux.c \ @@ -193,6 +194,7 @@ pkginclude_HEADERS += \ lib/module.h \ lib/monotime.h \ lib/mpls.h \ + lib/srv6.h \ lib/network.h \ lib/nexthop.h \ lib/nexthop_group.h \ diff --git a/lib/zclient.c b/lib/zclient.c index 7ddf0085de..d879063460 100644 --- a/lib/zclient.c +++ b/lib/zclient.c @@ -3300,31 +3300,71 @@ void zclient_interface_set_master(struct zclient *client, zclient_send_message(client); } -/* Process capabilities message from zebra */ -int zapi_capabilities_decode(struct stream *s, struct zapi_cap *api) +/* + * Send capabilities message to zebra + */ +int32_t zclient_capabilities_send(uint32_t cmd, struct zclient *zclient, + struct zapi_cap *api) { + + struct stream *s; + + if (zclient == NULL) + return -1; + + s = zclient->obuf; + stream_reset(s); + zclient_create_header(s, cmd, 0); + stream_putl(s, api->cap); + + switch (api->cap) { + case ZEBRA_CLIENT_GR_CAPABILITIES: + case ZEBRA_CLIENT_RIB_STALE_TIME: + stream_putl(s, api->stale_removal_time); + stream_putl(s, api->vrf_id); + break; + case ZEBRA_CLIENT_ROUTE_UPDATE_COMPLETE: + case ZEBRA_CLIENT_ROUTE_UPDATE_PENDING: + stream_putl(s, api->afi); + stream_putl(s, api->safi); + stream_putl(s, api->vrf_id); + break; + case ZEBRA_CLIENT_GR_DISABLE: + stream_putl(s, api->vrf_id); + break; + } + + /* Put length at the first point of the stream */ + stream_putw_at(s, 0, stream_get_endp(s)); + + return zclient_send_message(zclient); +} + +/* + * Process capabilities message from zebra + */ +int32_t zapi_capabilities_decode(struct stream *s, struct zapi_cap *api) +{ + memset(api, 0, sizeof(*api)); STREAM_GETL(s, api->cap); switch (api->cap) { case ZEBRA_CLIENT_GR_CAPABILITIES: case ZEBRA_CLIENT_RIB_STALE_TIME: - STREAM_GETL(s, api->stale_removal_time); - STREAM_GETL(s, api->vrf_id); - break; + STREAM_GETL(s, api->stale_removal_time); + STREAM_GETL(s, api->vrf_id); + break; case ZEBRA_CLIENT_ROUTE_UPDATE_COMPLETE: case ZEBRA_CLIENT_ROUTE_UPDATE_PENDING: - STREAM_GETL(s, api->afi); - STREAM_GETL(s, api->safi); - STREAM_GETL(s, api->vrf_id); - break; + STREAM_GETL(s, api->afi); + STREAM_GETL(s, api->safi); + STREAM_GETL(s, api->vrf_id); + break; case ZEBRA_CLIENT_GR_DISABLE: - STREAM_GETL(s, api->vrf_id); - break; - default: - break; + STREAM_GETL(s, api->vrf_id); + break; } - stream_failure: return 0; } diff --git a/lib/zclient.h b/lib/zclient.h index bbc70c3835..9a230d3f34 100644 --- a/lib/zclient.h +++ b/lib/zclient.h @@ -73,13 +73,17 @@ typedef uint16_t zebra_size_t; #define ZEBRA_FEC_REGISTER_LABEL 0x1 #define ZEBRA_FEC_REGISTER_LABEL_INDEX 0x2 -/* Client Graceful Restart */ -#define ZEBRA_CLIENT_GR_CAPABILITIES 0x1 -#define ZEBRA_CLIENT_ROUTE_UPDATE_COMPLETE 0x2 -#define ZEBRA_CLIENT_ROUTE_UPDATE_PENDING 0x3 -#define ZEBRA_CLIENT_GR_DISABLE 0x4 -#define ZEBRA_CLIENT_RIB_STALE_TIME 0x5 -#define ZEBRA_CLIENT_GR_ENABLED(X) (X & ZEBRA_CLIENT_GR_CAPABILITIES) +/* Client capabilities */ +enum zserv_client_capabilities { + ZEBRA_CLIENT_GR_CAPABILITIES = 1, + ZEBRA_CLIENT_ROUTE_UPDATE_COMPLETE = 2, + ZEBRA_CLIENT_ROUTE_UPDATE_PENDING = 3, + ZEBRA_CLIENT_GR_DISABLE = 4, + ZEBRA_CLIENT_RIB_STALE_TIME +}; + +/* Macro to check if there GR enabled. */ +#define ZEBRA_CLIENT_GR_ENABLED(X) (X == ZEBRA_CLIENT_GR_CAPABILITIES) extern struct sockaddr_storage zclient_addr; extern socklen_t zclient_addr_len; @@ -196,7 +200,7 @@ typedef enum { } zebra_message_types_t; enum zebra_error_types { - ZEBRA_UNKNOWN_ERROR, /* Error of unknown type */ + ZEBRA_UNKNOWN_ERROR, /* Error of unknown type */ ZEBRA_NO_VRF, /* Vrf in header was not found */ ZEBRA_INVALID_MSG_TYPE, /* No handler found for msg type */ }; @@ -233,11 +237,11 @@ struct zclient_capabilities { /* Graceful Restart Capabilities message */ struct zapi_cap { - uint32_t cap; - uint32_t stale_removal_time; - afi_t afi; - safi_t safi; - vrf_id_t vrf_id; + enum zserv_client_capabilities cap; + uint32_t stale_removal_time; + afi_t afi; + safi_t safi; + vrf_id_t vrf_id; }; /* Structure for the zebra client. */ @@ -777,6 +781,11 @@ extern bool zapi_nexthop_update_decode(struct stream *s, /* Decode the zebra error message */ extern bool zapi_error_decode(struct stream *s, enum zebra_error_types *error); +/* Encode and decode restart capabilities */ +extern int32_t zclient_capabilities_send(uint32_t cmd, struct zclient *zclient, + struct zapi_cap *api); +extern int32_t zapi_capabilities_decode(struct stream *s, struct zapi_cap *api); + static inline void zapi_route_set_blackhole(struct zapi_route *api, enum blackhole_type bh_type) { @@ -794,7 +803,4 @@ extern void zclient_send_mlag_deregister(struct zclient *client); extern void zclient_send_mlag_data(struct zclient *client, struct stream *client_s); -extern int zclient_capabilities_send(uint32_t cmd, struct zclient *zclient, - struct zapi_cap *api); -extern int zapi_capabilities_decode(struct stream *s, struct zapi_cap *api); #endif /* _ZEBRA_ZCLIENT_H */ |
