back to topotato report
topotato coverage report
Current view: top level - lib - zclient.h (source / functions) Hit Total Coverage
Test: test_pim6_bootstrap.py::PIM6Bootstrap Lines: 0 29 0.0 %
Date: 2023-02-16 02:07:22 Functions: 0 1 0.0 %

          Line data    Source code
       1             : /* Zebra's client header.
       2             :  * Copyright (C) 1999 Kunihiro Ishiguro
       3             :  *
       4             :  * This file is part of GNU Zebra.
       5             :  *
       6             :  * GNU Zebra is free software; you can redistribute it and/or modify it
       7             :  * under the terms of the GNU General Public License as published by
       8             :  * the Free Software Foundation; either version 2, or (at your option)
       9             :  * any later version.
      10             :  *
      11             :  * GNU Zebra is distributed in the hope that it will be useful, but
      12             :  * WITHOUT ANY WARRANTY; without even the implied warranty of
      13             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      14             :  * General Public License for more details.
      15             :  *
      16             :  * You should have received a copy of the GNU General Public License along
      17             :  * with this program; see the file COPYING; if not, write to the Free Software
      18             :  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
      19             :  */
      20             : 
      21             : #ifndef _ZEBRA_ZCLIENT_H
      22             : #define _ZEBRA_ZCLIENT_H
      23             : 
      24             : struct zclient;
      25             : 
      26             : /* For struct zapi_route. */
      27             : #include "prefix.h"
      28             : #include "ipaddr.h"
      29             : 
      30             : /* For struct interface and struct connected. */
      31             : #include "if.h"
      32             : 
      33             : /* For vrf_bitmap_t. */
      34             : #include "vrf.h"
      35             : 
      36             : /* For union g_addr */
      37             : #include "nexthop.h"
      38             : /* For resilience */
      39             : #include "nexthop_group.h"
      40             : 
      41             : /* For union pw_protocol_fields */
      42             : #include "pw.h"
      43             : 
      44             : #include "mlag.h"
      45             : #include "srte.h"
      46             : #include "srv6.h"
      47             : 
      48             : #ifdef __cplusplus
      49             : extern "C" {
      50             : #endif
      51             : 
      52             : /* Zebra types. Used in Zserv message header. */
      53             : typedef uint16_t zebra_size_t;
      54             : 
      55             : /* Marker value used in new Zserv, in the byte location corresponding
      56             :  * the command value in the old zserv header. To allow old and new
      57             :  * Zserv headers to be distinguished from each other.
      58             :  */
      59             : #define ZEBRA_HEADER_MARKER              254
      60             : 
      61             : /* For input/output buffer to zebra. */
      62             : #define ZEBRA_MAX_PACKET_SIZ          16384U
      63             : #define ZEBRA_SMALL_PACKET_SIZE       200U
      64             : 
      65             : /* Zebra header size. */
      66             : #define ZEBRA_HEADER_SIZE             10
      67             : 
      68             : /* special socket path name to use TCP
      69             :  * @ is used as first character because that's abstract socket names on Linux
      70             :  */
      71             : #define ZAPI_TCP_PATHNAME             "@tcp"
      72             : 
      73             : /* IPset size name stands for the name of the ipset entry
      74             :  * that can be created by using some zapi interfaces
      75             :  */
      76             : #define ZEBRA_IPSET_NAME_SIZE   32
      77             : 
      78             : /* IPTable action is defined by two values: either
      79             :  * forward or drop
      80             :  */
      81             : #define ZEBRA_IPTABLES_FORWARD 0
      82             : #define ZEBRA_IPTABLES_DROP    1
      83             : 
      84             : /* Zebra FEC register command flags. */
      85             : #define ZEBRA_FEC_REGISTER_LABEL          0x1
      86             : #define ZEBRA_FEC_REGISTER_LABEL_INDEX    0x2
      87             : 
      88             : /* Client capabilities */
      89             : enum zserv_client_capabilities {
      90             :         ZEBRA_CLIENT_GR_CAPABILITIES = 1,
      91             :         ZEBRA_CLIENT_ROUTE_UPDATE_COMPLETE = 2,
      92             :         ZEBRA_CLIENT_ROUTE_UPDATE_PENDING = 3,
      93             :         ZEBRA_CLIENT_GR_DISABLE = 4,
      94             :         ZEBRA_CLIENT_RIB_STALE_TIME
      95             : };
      96             : 
      97             : /* Macro to check if there GR enabled. */
      98             : #define ZEBRA_CLIENT_GR_ENABLED(X) (X == ZEBRA_CLIENT_GR_CAPABILITIES)
      99             : 
     100             : #define ZEBRA_SR_POLICY_NAME_MAX_LENGTH 100
     101             : 
     102             : extern struct sockaddr_storage zclient_addr;
     103             : extern socklen_t zclient_addr_len;
     104             : 
     105             : /* Zebra message types. */
     106             : typedef enum {
     107             :         ZEBRA_INTERFACE_ADD,
     108             :         ZEBRA_INTERFACE_DELETE,
     109             :         ZEBRA_INTERFACE_ADDRESS_ADD,
     110             :         ZEBRA_INTERFACE_ADDRESS_DELETE,
     111             :         ZEBRA_INTERFACE_UP,
     112             :         ZEBRA_INTERFACE_DOWN,
     113             :         ZEBRA_INTERFACE_SET_MASTER,
     114             :         ZEBRA_INTERFACE_SET_PROTODOWN,
     115             :         ZEBRA_ROUTE_ADD,
     116             :         ZEBRA_ROUTE_DELETE,
     117             :         ZEBRA_ROUTE_NOTIFY_OWNER,
     118             :         ZEBRA_REDISTRIBUTE_ADD,
     119             :         ZEBRA_REDISTRIBUTE_DELETE,
     120             :         ZEBRA_REDISTRIBUTE_DEFAULT_ADD,
     121             :         ZEBRA_REDISTRIBUTE_DEFAULT_DELETE,
     122             :         ZEBRA_ROUTER_ID_ADD,
     123             :         ZEBRA_ROUTER_ID_DELETE,
     124             :         ZEBRA_ROUTER_ID_UPDATE,
     125             :         ZEBRA_HELLO,
     126             :         ZEBRA_CAPABILITIES,
     127             :         ZEBRA_NEXTHOP_REGISTER,
     128             :         ZEBRA_NEXTHOP_UNREGISTER,
     129             :         ZEBRA_NEXTHOP_UPDATE,
     130             :         ZEBRA_INTERFACE_NBR_ADDRESS_ADD,
     131             :         ZEBRA_INTERFACE_NBR_ADDRESS_DELETE,
     132             :         ZEBRA_INTERFACE_BFD_DEST_UPDATE,
     133             :         ZEBRA_BFD_DEST_REGISTER,
     134             :         ZEBRA_BFD_DEST_DEREGISTER,
     135             :         ZEBRA_BFD_DEST_UPDATE,
     136             :         ZEBRA_BFD_DEST_REPLAY,
     137             :         ZEBRA_REDISTRIBUTE_ROUTE_ADD,
     138             :         ZEBRA_REDISTRIBUTE_ROUTE_DEL,
     139             :         ZEBRA_VRF_UNREGISTER,
     140             :         ZEBRA_VRF_ADD,
     141             :         ZEBRA_VRF_DELETE,
     142             :         ZEBRA_VRF_LABEL,
     143             :         ZEBRA_INTERFACE_VRF_UPDATE,
     144             :         ZEBRA_BFD_CLIENT_REGISTER,
     145             :         ZEBRA_BFD_CLIENT_DEREGISTER,
     146             :         ZEBRA_INTERFACE_ENABLE_RADV,
     147             :         ZEBRA_INTERFACE_DISABLE_RADV,
     148             :         ZEBRA_NEXTHOP_LOOKUP_MRIB,
     149             :         ZEBRA_INTERFACE_LINK_PARAMS,
     150             :         ZEBRA_MPLS_LABELS_ADD,
     151             :         ZEBRA_MPLS_LABELS_DELETE,
     152             :         ZEBRA_MPLS_LABELS_REPLACE,
     153             :         ZEBRA_SR_POLICY_SET,
     154             :         ZEBRA_SR_POLICY_DELETE,
     155             :         ZEBRA_SR_POLICY_NOTIFY_STATUS,
     156             :         ZEBRA_IPMR_ROUTE_STATS,
     157             :         ZEBRA_LABEL_MANAGER_CONNECT,
     158             :         ZEBRA_LABEL_MANAGER_CONNECT_ASYNC,
     159             :         ZEBRA_GET_LABEL_CHUNK,
     160             :         ZEBRA_RELEASE_LABEL_CHUNK,
     161             :         ZEBRA_FEC_REGISTER,
     162             :         ZEBRA_FEC_UNREGISTER,
     163             :         ZEBRA_FEC_UPDATE,
     164             :         ZEBRA_ADVERTISE_DEFAULT_GW,
     165             :         ZEBRA_ADVERTISE_SVI_MACIP,
     166             :         ZEBRA_ADVERTISE_SUBNET,
     167             :         ZEBRA_ADVERTISE_ALL_VNI,
     168             :         ZEBRA_LOCAL_ES_ADD,
     169             :         ZEBRA_LOCAL_ES_DEL,
     170             :         ZEBRA_REMOTE_ES_VTEP_ADD,
     171             :         ZEBRA_REMOTE_ES_VTEP_DEL,
     172             :         ZEBRA_LOCAL_ES_EVI_ADD,
     173             :         ZEBRA_LOCAL_ES_EVI_DEL,
     174             :         ZEBRA_VNI_ADD,
     175             :         ZEBRA_VNI_DEL,
     176             :         ZEBRA_L3VNI_ADD,
     177             :         ZEBRA_L3VNI_DEL,
     178             :         ZEBRA_REMOTE_VTEP_ADD,
     179             :         ZEBRA_REMOTE_VTEP_DEL,
     180             :         ZEBRA_MACIP_ADD,
     181             :         ZEBRA_MACIP_DEL,
     182             :         ZEBRA_IP_PREFIX_ROUTE_ADD,
     183             :         ZEBRA_IP_PREFIX_ROUTE_DEL,
     184             :         ZEBRA_REMOTE_MACIP_ADD,
     185             :         ZEBRA_REMOTE_MACIP_DEL,
     186             :         ZEBRA_DUPLICATE_ADDR_DETECTION,
     187             :         ZEBRA_PW_ADD,
     188             :         ZEBRA_PW_DELETE,
     189             :         ZEBRA_PW_SET,
     190             :         ZEBRA_PW_UNSET,
     191             :         ZEBRA_PW_STATUS_UPDATE,
     192             :         ZEBRA_RULE_ADD,
     193             :         ZEBRA_RULE_DELETE,
     194             :         ZEBRA_RULE_NOTIFY_OWNER,
     195             :         ZEBRA_TABLE_MANAGER_CONNECT,
     196             :         ZEBRA_GET_TABLE_CHUNK,
     197             :         ZEBRA_RELEASE_TABLE_CHUNK,
     198             :         ZEBRA_IPSET_CREATE,
     199             :         ZEBRA_IPSET_DESTROY,
     200             :         ZEBRA_IPSET_ENTRY_ADD,
     201             :         ZEBRA_IPSET_ENTRY_DELETE,
     202             :         ZEBRA_IPSET_NOTIFY_OWNER,
     203             :         ZEBRA_IPSET_ENTRY_NOTIFY_OWNER,
     204             :         ZEBRA_IPTABLE_ADD,
     205             :         ZEBRA_IPTABLE_DELETE,
     206             :         ZEBRA_IPTABLE_NOTIFY_OWNER,
     207             :         ZEBRA_VXLAN_FLOOD_CONTROL,
     208             :         ZEBRA_VXLAN_SG_ADD,
     209             :         ZEBRA_VXLAN_SG_DEL,
     210             :         ZEBRA_VXLAN_SG_REPLAY,
     211             :         ZEBRA_MLAG_PROCESS_UP,
     212             :         ZEBRA_MLAG_PROCESS_DOWN,
     213             :         ZEBRA_MLAG_CLIENT_REGISTER,
     214             :         ZEBRA_MLAG_CLIENT_UNREGISTER,
     215             :         ZEBRA_MLAG_FORWARD_MSG,
     216             :         ZEBRA_NHG_ADD,
     217             :         ZEBRA_NHG_DEL,
     218             :         ZEBRA_NHG_NOTIFY_OWNER,
     219             :         ZEBRA_EVPN_REMOTE_NH_ADD,
     220             :         ZEBRA_EVPN_REMOTE_NH_DEL,
     221             :         ZEBRA_SRV6_LOCATOR_ADD,
     222             :         ZEBRA_SRV6_LOCATOR_DELETE,
     223             :         ZEBRA_SRV6_MANAGER_GET_LOCATOR_CHUNK,
     224             :         ZEBRA_SRV6_MANAGER_RELEASE_LOCATOR_CHUNK,
     225             :         ZEBRA_ERROR,
     226             :         ZEBRA_CLIENT_CAPABILITIES,
     227             :         ZEBRA_OPAQUE_MESSAGE,
     228             :         ZEBRA_OPAQUE_REGISTER,
     229             :         ZEBRA_OPAQUE_UNREGISTER,
     230             :         ZEBRA_NEIGH_DISCOVER,
     231             :         ZEBRA_ROUTE_NOTIFY_REQUEST,
     232             :         ZEBRA_CLIENT_CLOSE_NOTIFY,
     233             :         ZEBRA_NHRP_NEIGH_ADDED,
     234             :         ZEBRA_NHRP_NEIGH_REMOVED,
     235             :         ZEBRA_NHRP_NEIGH_GET,
     236             :         ZEBRA_NHRP_NEIGH_REGISTER,
     237             :         ZEBRA_NHRP_NEIGH_UNREGISTER,
     238             :         ZEBRA_NEIGH_IP_ADD,
     239             :         ZEBRA_NEIGH_IP_DEL,
     240             :         ZEBRA_CONFIGURE_ARP,
     241             :         ZEBRA_GRE_GET,
     242             :         ZEBRA_GRE_UPDATE,
     243             :         ZEBRA_GRE_SOURCE_SET,
     244             :         ZEBRA_TC_QDISC_INSTALL,
     245             :         ZEBRA_TC_QDISC_UNINSTALL,
     246             :         ZEBRA_TC_CLASS_ADD,
     247             :         ZEBRA_TC_CLASS_DELETE,
     248             :         ZEBRA_TC_FILTER_ADD,
     249             :         ZEBRA_TC_FILTER_DELETE,
     250             : } zebra_message_types_t;
     251             : 
     252             : enum zebra_error_types {
     253             :         ZEBRA_UNKNOWN_ERROR,    /* Error of unknown type */
     254             :         ZEBRA_NO_VRF,           /* Vrf in header was not found */
     255             :         ZEBRA_INVALID_MSG_TYPE, /* No handler found for msg type */
     256             : };
     257             : 
     258           0 : static inline const char *zebra_error_type2str(enum zebra_error_types type)
     259             : {
     260           0 :         const char *ret = "UNKNOWN";
     261             : 
     262           0 :         switch (type) {
     263           0 :         case ZEBRA_UNKNOWN_ERROR:
     264           0 :                 ret = "ZEBRA_UNKNOWN_ERROR";
     265           0 :                 break;
     266           0 :         case ZEBRA_NO_VRF:
     267           0 :                 ret = "ZEBRA_NO_VRF";
     268           0 :                 break;
     269           0 :         case ZEBRA_INVALID_MSG_TYPE:
     270           0 :                 ret = "ZEBRA_INVALID_MSG_TYPE";
     271           0 :                 break;
     272             :         }
     273             : 
     274           0 :         return ret;
     275             : }
     276             : 
     277             : struct redist_proto {
     278             :         uint8_t enabled;
     279             :         struct list *instances;
     280             : };
     281             : 
     282             : struct zclient_capabilities {
     283             :         uint32_t ecmp;
     284             :         bool mpls_enabled;
     285             :         enum mlag_role role;
     286             : };
     287             : 
     288             : /* Graceful Restart Capabilities message */
     289             : struct zapi_cap {
     290             :         enum zserv_client_capabilities cap;
     291             :         uint32_t stale_removal_time;
     292             :         afi_t afi;
     293             :         safi_t safi;
     294             :         vrf_id_t vrf_id;
     295             : };
     296             : 
     297             : /* clang-format off */
     298             : #define ZAPI_CALLBACK_ARGS                                                     \
     299             :         int cmd, struct zclient *zclient, uint16_t length, vrf_id_t vrf_id
     300             : 
     301             : /* function-type typedef (pointer not included) */
     302             : typedef int (zclient_handler)(ZAPI_CALLBACK_ARGS);
     303             : /* clang-format on */
     304             : 
     305             : /* Structure for the zebra client. */
     306             : struct zclient {
     307             :         /* The thread master we schedule ourselves on */
     308             :         struct thread_master *master;
     309             : 
     310             :         /* Privileges to change socket values */
     311             :         struct zebra_privs_t *privs;
     312             : 
     313             :         /* Do we care about failure events for route install? */
     314             :         bool receive_notify;
     315             : 
     316             :         /* Is this a synchronous client? */
     317             :         bool synchronous;
     318             : 
     319             :         /* BFD enabled with bfd_protocol_integration_init() */
     320             :         bool bfd_integration;
     321             : 
     322             :         /* Session id (optional) to support clients with multiple sessions */
     323             :         uint32_t session_id;
     324             : 
     325             :         /* Socket to zebra daemon. */
     326             :         int sock;
     327             : 
     328             :         /* Connection failure count. */
     329             :         int fail;
     330             : 
     331             :         /* Input buffer for zebra message. */
     332             :         struct stream *ibuf;
     333             : 
     334             :         /* Output buffer for zebra message. */
     335             :         struct stream *obuf;
     336             : 
     337             :         /* Buffer of data waiting to be written to zebra. */
     338             :         struct buffer *wb;
     339             : 
     340             :         /* Read and connect thread. */
     341             :         struct thread *t_read;
     342             :         struct thread *t_connect;
     343             : 
     344             :         /* Thread to write buffered data to zebra. */
     345             :         struct thread *t_write;
     346             : 
     347             :         /* Redistribute information. */
     348             :         uint8_t redist_default; /* clients protocol */
     349             :         unsigned short instance;
     350             :         struct redist_proto mi_redist[AFI_MAX][ZEBRA_ROUTE_MAX];
     351             :         vrf_bitmap_t redist[AFI_MAX][ZEBRA_ROUTE_MAX];
     352             : 
     353             :         /* Redistribute default. */
     354             :         vrf_bitmap_t default_information[AFI_MAX];
     355             : 
     356             :         /* Pointer to the callback functions. */
     357             :         void (*zebra_connected)(struct zclient *);
     358             :         void (*zebra_capabilities)(struct zclient_capabilities *cap);
     359             : 
     360             :         int (*handle_error)(enum zebra_error_types error);
     361             : 
     362             :         /*
     363             :          * When the zclient attempts to write the stream data to
     364             :          * it's named pipe to/from zebra, we may have a situation
     365             :          * where the other daemon has not fully drained the data
     366             :          * from the socket.  In this case provide a mechanism
     367             :          * where we will *still* buffer the data to be sent
     368             :          * and also provide a callback mechanism to the appropriate
     369             :          * place where we can signal that we're ready to receive
     370             :          * more data.
     371             :          */
     372             :         void (*zebra_buffer_write_ready)(void);
     373             : 
     374             :         zclient_handler *const *handlers;
     375             :         size_t n_handlers;
     376             : };
     377             : 
     378             : /* lib handlers added in bfd.c */
     379             : extern int zclient_bfd_session_replay(ZAPI_CALLBACK_ARGS);
     380             : extern int zclient_bfd_session_update(ZAPI_CALLBACK_ARGS);
     381             : 
     382             : /* Zebra API message flag. */
     383             : #define ZAPI_MESSAGE_NEXTHOP  0x01
     384             : #define ZAPI_MESSAGE_DISTANCE 0x02
     385             : #define ZAPI_MESSAGE_METRIC   0x04
     386             : #define ZAPI_MESSAGE_TAG      0x08
     387             : #define ZAPI_MESSAGE_MTU      0x10
     388             : #define ZAPI_MESSAGE_SRCPFX   0x20
     389             : /* Backup nexthops are present */
     390             : #define ZAPI_MESSAGE_BACKUP_NEXTHOPS 0x40
     391             : #define ZAPI_MESSAGE_NHG 0x80
     392             : /*
     393             :  * This should only be used by a DAEMON that needs to communicate
     394             :  * the table being used is not in the VRF.  You must pass the
     395             :  * default vrf, else this will be ignored.
     396             :  */
     397             : #define ZAPI_MESSAGE_TABLEID 0x0100
     398             : #define ZAPI_MESSAGE_SRTE 0x0200
     399             : #define ZAPI_MESSAGE_OPAQUE 0x0400
     400             : 
     401             : #define ZSERV_VERSION 6
     402             : /* Zserv protocol message header */
     403             : struct zmsghdr {
     404             :         uint16_t length;
     405             :         /* Always set to 255 in new zserv */
     406             :         uint8_t marker;
     407             :         uint8_t version;
     408             :         vrf_id_t vrf_id;
     409             :         uint16_t command;
     410             : } __attribute__((packed));
     411             : #define ZAPI_HEADER_CMD_LOCATION offsetof(struct zmsghdr, command)
     412             : 
     413             : /*
     414             :  * ZAPI nexthop. Note that these are sorted when associated with ZAPI routes,
     415             :  * and that sorting must be aligned with the sorting of nexthops in
     416             :  * lib/nexthop.c. Any new fields must be accounted for in zapi_nexthop_cmp().
     417             :  */
     418             : struct zapi_nexthop {
     419             :         enum nexthop_types_t type;
     420             :         vrf_id_t vrf_id;
     421             :         ifindex_t ifindex;
     422             :         uint8_t flags;
     423             :         union {
     424             :                 union g_addr gate;
     425             :                 enum blackhole_type bh_type;
     426             :         };
     427             : 
     428             :         /* MPLS labels for BGP-LU or Segment Routing */
     429             :         uint8_t label_num;
     430             :         mpls_label_t labels[MPLS_MAX_LABELS];
     431             : 
     432             :         struct ethaddr rmac;
     433             : 
     434             :         uint32_t weight;
     435             : 
     436             :         /* Backup nexthops, for IP-FRR, TI-LFA, etc */
     437             :         uint8_t backup_num;
     438             :         uint8_t backup_idx[NEXTHOP_MAX_BACKUPS];
     439             : 
     440             :         /* SR-TE color. */
     441             :         uint32_t srte_color;
     442             : 
     443             :         /* SRv6 localsid info for Endpoint-behaviour */
     444             :         uint32_t seg6local_action;
     445             :         struct seg6local_context seg6local_ctx;
     446             : 
     447             :         /* SRv6 Headend-behaviour */
     448             :         struct in6_addr seg6_segs;
     449             : };
     450             : 
     451             : /*
     452             :  * ZAPI nexthop flags values - we're encoding a single octet
     453             :  * initially, so ensure that the on-the-wire encoding continues
     454             :  * to match the number of valid flags.
     455             :  */
     456             : 
     457             : #define ZAPI_NEXTHOP_FLAG_ONLINK        0x01
     458             : #define ZAPI_NEXTHOP_FLAG_LABEL         0x02
     459             : #define ZAPI_NEXTHOP_FLAG_WEIGHT        0x04
     460             : #define ZAPI_NEXTHOP_FLAG_HAS_BACKUP    0x08 /* Nexthop has a backup */
     461             : #define ZAPI_NEXTHOP_FLAG_SEG6          0x10
     462             : #define ZAPI_NEXTHOP_FLAG_SEG6LOCAL     0x20
     463             : #define ZAPI_NEXTHOP_FLAG_EVPN          0x40
     464             : 
     465             : /*
     466             :  * ZAPI Nexthop Group. For use with protocol creation of nexthop groups.
     467             :  */
     468             : struct zapi_nhg {
     469             :         uint16_t proto;
     470             :         uint32_t id;
     471             : 
     472             :         struct nhg_resilience resilience;
     473             : 
     474             :         uint16_t nexthop_num;
     475             :         struct zapi_nexthop nexthops[MULTIPATH_NUM];
     476             : 
     477             :         uint16_t backup_nexthop_num;
     478             :         struct zapi_nexthop backup_nexthops[MULTIPATH_NUM];
     479             : };
     480             : 
     481             : /*
     482             :  * Some of these data structures do not map easily to
     483             :  * a actual data structure size giving different compilers
     484             :  * and systems.  For those data structures we need
     485             :  * to use the smallest available stream_getX/putX functions
     486             :  * to encode/decode.
     487             :  */
     488             : struct zapi_route {
     489             :         uint8_t type;
     490             :         unsigned short instance;
     491             : 
     492             :         /* If you add flags, update zclient_dump_route_flags */
     493             :         uint32_t flags;
     494             : /*
     495             :  * Cause Zebra to consider this routes nexthops recursively
     496             :  */
     497             : #define ZEBRA_FLAG_ALLOW_RECURSION    0x01
     498             : /*
     499             :  * This is a route that is read in on startup that was left around
     500             :  * from a previous run of FRR
     501             :  */
     502             : #define ZEBRA_FLAG_SELFROUTE          0x02
     503             : /*
     504             :  * This flag is used to tell Zebra that the BGP route being passed
     505             :  * down is a IBGP route
     506             :  */
     507             : #define ZEBRA_FLAG_IBGP               0x04
     508             : /*
     509             :  * This is a route that has been selected for FIB installation.
     510             :  * This flag is set in zebra and can be passed up to routing daemons
     511             :  */
     512             : #define ZEBRA_FLAG_SELECTED           0x08
     513             : /*
     514             :  * This is a route that we are telling Zebra that this route *must*
     515             :  * win and will be installed even over ZEBRA_FLAG_SELECTED
     516             :  */
     517             : #define ZEBRA_FLAG_FIB_OVERRIDE       0x10
     518             : /*
     519             :  * This flag tells Zebra that the route is a EVPN route and should
     520             :  * be treated specially
     521             :  */
     522             : #define ZEBRA_FLAG_EVPN_ROUTE         0x20
     523             : /*
     524             :  * This flag tells Zebra that it should treat the distance passed
     525             :  * down as an additional discriminator for route selection of the
     526             :  * route entry.  This mainly is used for backup static routes.
     527             :  */
     528             : #define ZEBRA_FLAG_RR_USE_DISTANCE    0x40
     529             : /*
     530             :  * This flag tells everyone that the route was intentionally
     531             :  * not offloaded and the route will be sent to the cpu for
     532             :  * forwarding.  This flag makes no sense unless you are in
     533             :  * an asic offload situation
     534             :  */
     535             : #define ZEBRA_FLAG_TRAPPED            0x80
     536             : /*
     537             :  * This flag tells everyone that the route has been
     538             :  * successfully offloaded to an asic for forwarding.
     539             :  * This flag makes no sense unless you are in an asic
     540             :  * offload situation.
     541             :  */
     542             : #define ZEBRA_FLAG_OFFLOADED          0x100
     543             : /*
     544             :  * This flag tells everyone that the route has
     545             :  * failed offloading.
     546             :  * This flag makes no sense unless you are in an asic
     547             :  * offload situation.
     548             :  */
     549             : #define ZEBRA_FLAG_OFFLOAD_FAILED     0x200
     550             : 
     551             : /*
     552             :  * This flag lets us know that we think the route entry
     553             :  * received has caused us to be out of sync with the
     554             :  * kernel (NLM_F_APPEND at the very least )
     555             :  */
     556             : #define ZEBRA_FLAG_OUTOFSYNC          0x400
     557             : 
     558             :         /* The older XXX_MESSAGE flags live here */
     559             :         uint32_t message;
     560             : 
     561             :         /*
     562             :          * This is an enum but we are going to treat it as a uint8_t
     563             :          * for purpose of encoding/decoding
     564             :          */
     565             :         safi_t safi;
     566             : 
     567             :         struct prefix prefix;
     568             :         struct prefix_ipv6 src_prefix;
     569             : 
     570             :         uint16_t nexthop_num;
     571             :         struct zapi_nexthop nexthops[MULTIPATH_NUM];
     572             : 
     573             :         /* Support backup routes for IP FRR, TI-LFA, traffic engineering */
     574             :         uint16_t backup_nexthop_num;
     575             :         struct zapi_nexthop backup_nexthops[MULTIPATH_NUM];
     576             : 
     577             :         uint32_t nhgid;
     578             : 
     579             :         uint8_t distance;
     580             : 
     581             :         uint32_t metric;
     582             : 
     583             :         route_tag_t tag;
     584             : 
     585             :         uint32_t mtu;
     586             : 
     587             :         vrf_id_t vrf_id;
     588             : 
     589             :         uint32_t tableid;
     590             : 
     591             :         /* SR-TE color (used for nexthop updates only). */
     592             :         uint32_t srte_color;
     593             : 
     594             : #define ZAPI_MESSAGE_OPAQUE_LENGTH 1024
     595             :         struct {
     596             :                 uint16_t length;
     597             :                 uint8_t data[ZAPI_MESSAGE_OPAQUE_LENGTH];
     598             :         } opaque;
     599             : };
     600             : 
     601             : extern char *zclient_dump_route_flags(uint32_t flags, char *buf, size_t len);
     602             : 
     603             : struct zapi_labels {
     604             :         uint8_t message;
     605             : #define ZAPI_LABELS_FTN           0x01
     606             : #define ZAPI_LABELS_HAS_BACKUPS   0x02
     607             :         enum lsp_types_t type;
     608             :         mpls_label_t local_label;
     609             :         struct {
     610             :                 struct prefix prefix;
     611             :                 uint8_t type;
     612             :                 unsigned short instance;
     613             :         } route;
     614             : 
     615             :         uint16_t nexthop_num;
     616             :         struct zapi_nexthop nexthops[MULTIPATH_NUM];
     617             : 
     618             :         /* Backup nexthops, if present */
     619             :         uint16_t backup_nexthop_num;
     620             :         struct zapi_nexthop backup_nexthops[MULTIPATH_NUM];
     621             : };
     622             : 
     623             : struct zapi_srte_tunnel {
     624             :         enum lsp_types_t type;
     625             :         mpls_label_t local_label;
     626             :         uint8_t label_num;
     627             :         mpls_label_t labels[MPLS_MAX_LABELS];
     628             : };
     629             : 
     630             : struct zapi_sr_policy {
     631             :         uint32_t color;
     632             :         struct ipaddr endpoint;
     633             :         char name[SRTE_POLICY_NAME_MAX_LENGTH];
     634             :         struct zapi_srte_tunnel segment_list;
     635             :         int status;
     636             : };
     637             : 
     638             : struct zapi_pw {
     639             :         char ifname[INTERFACE_NAMSIZ];
     640             :         ifindex_t ifindex;
     641             :         int type;
     642             :         int af;
     643             :         union g_addr nexthop;
     644             :         uint32_t local_label;
     645             :         uint32_t remote_label;
     646             :         uint8_t flags;
     647             :         union pw_protocol_fields data;
     648             :         uint8_t protocol;
     649             : };
     650             : 
     651             : struct zapi_pw_status {
     652             :         char ifname[INTERFACE_NAMSIZ];
     653             :         ifindex_t ifindex;
     654             :         uint32_t status;
     655             : };
     656             : 
     657             : /* IGP instance data associated to a RLFA. */
     658             : struct zapi_rlfa_igp {
     659             :         vrf_id_t vrf_id;
     660             :         int protocol;
     661             :         union {
     662             :                 struct {
     663             :                         char area_tag[32];
     664             :                         struct {
     665             :                                 int tree_id;
     666             :                                 int level;
     667             :                                 unsigned int run_id;
     668             :                         } spf;
     669             :                 } isis;
     670             :         };
     671             : };
     672             : 
     673             : /* IGP -> LDP RLFA (un)registration message. */
     674             : struct zapi_rlfa_request {
     675             :         /* IGP instance data. */
     676             :         struct zapi_rlfa_igp igp;
     677             : 
     678             :         /* Destination prefix. */
     679             :         struct prefix destination;
     680             : 
     681             :         /* PQ node address. */
     682             :         struct in_addr pq_address;
     683             : };
     684             : 
     685             : /* LDP -> IGP RLFA label update. */
     686             : struct zapi_rlfa_response {
     687             :         /* IGP instance data. */
     688             :         struct zapi_rlfa_igp igp;
     689             : 
     690             :         /* Destination prefix. */
     691             :         struct prefix destination;
     692             : 
     693             :         /* Resolved LDP labels. */
     694             :         mpls_label_t pq_label;
     695             :         uint16_t nexthop_num;
     696             :         struct {
     697             :                 int family;
     698             :                 union g_addr gate;
     699             :                 mpls_label_t label;
     700             :         } nexthops[MULTIPATH_NUM];
     701             : };
     702             : 
     703             : enum zapi_route_notify_owner {
     704             :         ZAPI_ROUTE_FAIL_INSTALL,
     705             :         ZAPI_ROUTE_BETTER_ADMIN_WON,
     706             :         ZAPI_ROUTE_INSTALLED,
     707             :         ZAPI_ROUTE_REMOVED,
     708             :         ZAPI_ROUTE_REMOVE_FAIL,
     709             : };
     710             : 
     711             : enum zapi_nhg_notify_owner {
     712             :         ZAPI_NHG_FAIL_INSTALL,
     713             :         ZAPI_NHG_INSTALLED,
     714             :         ZAPI_NHG_REMOVED,
     715             :         ZAPI_NHG_REMOVE_FAIL,
     716             : };
     717             : 
     718             : enum zapi_rule_notify_owner {
     719             :         ZAPI_RULE_FAIL_INSTALL,
     720             :         ZAPI_RULE_INSTALLED,
     721             :         ZAPI_RULE_REMOVED,
     722             :         ZAPI_RULE_FAIL_REMOVE,
     723             : };
     724             : 
     725             : enum ipset_type {
     726             :         IPSET_NET_NET = 1,
     727             :         IPSET_NET_PORT_NET,
     728             :         IPSET_NET_PORT,
     729             :         IPSET_NET
     730             : };
     731             : 
     732             : enum zapi_ipset_notify_owner {
     733             :         ZAPI_IPSET_FAIL_INSTALL = 0,
     734             :         ZAPI_IPSET_INSTALLED,
     735             :         ZAPI_IPSET_REMOVED,
     736             :         ZAPI_IPSET_FAIL_REMOVE,
     737             : };
     738             : 
     739             : enum zapi_ipset_entry_notify_owner {
     740             :         ZAPI_IPSET_ENTRY_FAIL_INSTALL = 0,
     741             :         ZAPI_IPSET_ENTRY_INSTALLED,
     742             :         ZAPI_IPSET_ENTRY_REMOVED,
     743             :         ZAPI_IPSET_ENTRY_FAIL_REMOVE,
     744             : };
     745             : 
     746             : enum zapi_iptable_notify_owner {
     747             :         ZAPI_IPTABLE_FAIL_INSTALL = 0,
     748             :         ZAPI_IPTABLE_INSTALLED,
     749             :         ZAPI_IPTABLE_REMOVED,
     750             :         ZAPI_IPTABLE_FAIL_REMOVE,
     751             : };
     752             : 
     753             : enum zclient_send_status {
     754             :         ZCLIENT_SEND_FAILURE = -1,
     755             :         ZCLIENT_SEND_SUCCESS = 0,
     756             :         ZCLIENT_SEND_BUFFERED = 1
     757             : };
     758             : 
     759             : static inline const char *
     760           0 : zapi_nhg_notify_owner2str(enum zapi_nhg_notify_owner note)
     761             : {
     762           0 :         const char *ret = "UNKNOWN";
     763             : 
     764           0 :         switch (note) {
     765           0 :         case ZAPI_NHG_FAIL_INSTALL:
     766           0 :                 ret = "ZAPI_NHG_FAIL_INSTALL";
     767           0 :                 break;
     768           0 :         case ZAPI_NHG_INSTALLED:
     769           0 :                 ret = "ZAPI_NHG_INSTALLED";
     770           0 :                 break;
     771           0 :         case ZAPI_NHG_REMOVE_FAIL:
     772           0 :                 ret = "ZAPI_NHG_REMOVE_FAIL";
     773           0 :                 break;
     774           0 :         case ZAPI_NHG_REMOVED:
     775           0 :                 ret = "ZAPI_NHG_REMOVED";
     776           0 :                 break;
     777             :         }
     778             : 
     779           0 :         return ret;
     780             : }
     781             : 
     782             : static inline const char *
     783             : zapi_rule_notify_owner2str(enum zapi_rule_notify_owner note)
     784             : {
     785             :         const char *ret = "UNKNOWN";
     786             : 
     787             :         switch (note) {
     788             :         case ZAPI_RULE_FAIL_INSTALL:
     789             :                 ret = "ZAPI_RULE_FAIL_INSTALL";
     790             :                 break;
     791             :         case ZAPI_RULE_INSTALLED:
     792             :                 ret = "ZAPI_RULE_INSTALLED";
     793             :                 break;
     794             :         case ZAPI_RULE_FAIL_REMOVE:
     795             :                 ret = "ZAPI_RULE_FAIL_REMOVE";
     796             :                 break;
     797             :         case ZAPI_RULE_REMOVED:
     798             :                 ret = "ZAPI_RULE_REMOVED";
     799             :                 break;
     800             :         }
     801             : 
     802             :         return ret;
     803             : }
     804             : 
     805             : /* Zebra MAC types */
     806             : #define ZEBRA_MACIP_TYPE_STICKY                0x01 /* Sticky MAC*/
     807             : #define ZEBRA_MACIP_TYPE_GW                    0x02 /* gateway (SVI) mac*/
     808             : #define ZEBRA_MACIP_TYPE_ROUTER_FLAG           0x04 /* Router Flag - proxy NA */
     809             : #define ZEBRA_MACIP_TYPE_OVERRIDE_FLAG         0x08 /* Override Flag */
     810             : #define ZEBRA_MACIP_TYPE_SVI_IP                0x10 /* SVI MAC-IP */
     811             : #define ZEBRA_MACIP_TYPE_PROXY_ADVERT          0x20 /* Not locally active */
     812             : #define ZEBRA_MACIP_TYPE_SYNC_PATH             0x40 /* sync path */
     813             : /* XXX - flags is an u8; that needs to be changed to u32 if you need
     814             :  * to allocate past 0x80.  Additionally touch zclient_evpn_dump_macip_flags
     815             :  */
     816             : #define MACIP_BUF_SIZE 128
     817             : extern char *zclient_evpn_dump_macip_flags(uint8_t flags, char *buf,
     818             :                                            size_t len);
     819             : 
     820             : /* Zebra ES VTEP flags (ZEBRA_REMOTE_ES_VTEP_ADD) */
     821             : /* ESR has been rxed from the VTEP. Only VTEPs that have advertised the
     822             :  * Type-4 route can participate in DF election.
     823             :  */
     824             : #define ZAPI_ES_VTEP_FLAG_ESR_RXED (1 << 0)
     825             : 
     826             : enum zebra_neigh_state { ZEBRA_NEIGH_INACTIVE = 0, ZEBRA_NEIGH_ACTIVE = 1 };
     827             : 
     828             : struct zclient_options {
     829             :         bool receive_notify;
     830             :         bool synchronous;
     831             : };
     832             : 
     833             : extern struct zclient_options zclient_options_default;
     834             : 
     835             : /* link layer representation for GRE like interfaces
     836             :  * ip_in is the underlay IP, ip_out is the tunnel dest
     837             :  * index stands for the index of the interface
     838             :  * ndm state stands for the NDM value in netlink
     839             :  * (see linux/neighbour.h)
     840             :  */
     841             : #define ZEBRA_NEIGH_STATE_INCOMPLETE (0x01)
     842             : #define ZEBRA_NEIGH_STATE_REACHABLE (0x02)
     843             : #define ZEBRA_NEIGH_STATE_STALE (0x04)
     844             : #define ZEBRA_NEIGH_STATE_DELAY (0x08)
     845             : #define ZEBRA_NEIGH_STATE_PROBE (0x10)
     846             : #define ZEBRA_NEIGH_STATE_FAILED (0x20)
     847             : #define ZEBRA_NEIGH_STATE_NOARP (0x40)
     848             : #define ZEBRA_NEIGH_STATE_PERMANENT (0x80)
     849             : #define ZEBRA_NEIGH_STATE_NONE (0x00)
     850             : 
     851             : struct zapi_neigh_ip {
     852             :         int cmd;
     853             :         struct ipaddr ip_in;
     854             :         struct ipaddr ip_out;
     855             :         ifindex_t index;
     856             :         uint32_t ndm_state;
     857             : };
     858             : int zclient_neigh_ip_decode(struct stream *s, struct zapi_neigh_ip *api);
     859             : int zclient_neigh_ip_encode(struct stream *s, uint16_t cmd, union sockunion *in,
     860             :                             union sockunion *out, struct interface *ifp,
     861             :                             int ndm_state);
     862             : 
     863             : /*
     864             :  * We reserve the top 4 bits for l2-NHG, everything else
     865             :  * is for zebra/proto l3-NHG.
     866             :  *
     867             :  * Each client is going to get it's own nexthop group space
     868             :  * and we'll separate them, we'll figure out where to start based upon
     869             :  * the route_types.h
     870             :  */
     871             : #define ZEBRA_NHG_PROTO_UPPER                                                  \
     872             :         ((uint32_t)250000000) /* Bottom 28 bits then rounded down */
     873             : #define ZEBRA_NHG_PROTO_SPACING (ZEBRA_NHG_PROTO_UPPER / ZEBRA_ROUTE_MAX)
     874             : #define ZEBRA_NHG_PROTO_LOWER                                                  \
     875             :         (ZEBRA_NHG_PROTO_SPACING * (ZEBRA_ROUTE_CONNECT + 1))
     876             : 
     877             : extern uint32_t zclient_get_nhg_start(uint32_t proto);
     878             : 
     879             : extern struct zclient *zclient_new(struct thread_master *m,
     880             :                                    struct zclient_options *opt,
     881             :                                    zclient_handler *const *handlers,
     882             :                                    size_t n_handlers);
     883             : 
     884             : extern void zclient_init(struct zclient *, int, unsigned short,
     885             :                          struct zebra_privs_t *privs);
     886             : extern int zclient_start(struct zclient *);
     887             : extern void zclient_stop(struct zclient *);
     888             : extern void zclient_reset(struct zclient *);
     889             : extern void zclient_free(struct zclient *);
     890             : 
     891             : extern int zclient_socket_connect(struct zclient *);
     892             : 
     893             : extern unsigned short *redist_check_instance(struct redist_proto *,
     894             :                                              unsigned short);
     895             : extern void redist_add_instance(struct redist_proto *, unsigned short);
     896             : extern void redist_del_instance(struct redist_proto *, unsigned short);
     897             : extern void redist_del_all_instances(struct redist_proto *red);
     898             : 
     899             : /*
     900             :  * Send to zebra that the specified vrf is using label to resolve
     901             :  * itself for L3VPN's.  Repeated calls of this function with
     902             :  * different labels will cause an effective update of the
     903             :  * label for lookup.  If you pass in MPLS_LABEL_NONE
     904             :  * we will cause a delete action and remove this label pop
     905             :  * operation.
     906             :  *
     907             :  * The underlying AF_MPLS doesn't care about afi's
     908             :  * but we can make the zebra_vrf keep track of what
     909             :  * we have installed and play some special games
     910             :  * to get them both installed.
     911             :  */
     912             : extern enum zclient_send_status
     913             : zclient_send_vrf_label(struct zclient *zclient, vrf_id_t vrf_id, afi_t afi,
     914             :                        mpls_label_t label, enum lsp_types_t ltype);
     915             : 
     916             : extern enum zclient_send_status
     917             : zclient_send_localsid(struct zclient *zclient, const struct in6_addr *sid,
     918             :                       ifindex_t oif, enum seg6local_action_t action,
     919             :                       const struct seg6local_context *context);
     920             : 
     921             : extern void zclient_send_reg_requests(struct zclient *, vrf_id_t);
     922             : extern void zclient_send_dereg_requests(struct zclient *, vrf_id_t);
     923             : extern enum zclient_send_status
     924             : zclient_send_router_id_update(struct zclient *zclient,
     925             :                               zebra_message_types_t type, afi_t afi,
     926             :                               vrf_id_t vrf_id);
     927             : 
     928             : extern enum zclient_send_status
     929             : zclient_send_interface_radv_req(struct zclient *zclient, vrf_id_t vrf_id,
     930             :                                 struct interface *ifp, int enable,
     931             :                                 uint32_t ra_interval);
     932             : extern enum zclient_send_status
     933             : zclient_send_interface_protodown(struct zclient *zclient, vrf_id_t vrf_id,
     934             :                                  struct interface *ifp, bool down);
     935             : 
     936             : /* Send redistribute command to zebra daemon. Do not update zclient state. */
     937             : extern enum zclient_send_status
     938             : zebra_redistribute_send(int command, struct zclient *, afi_t, int type,
     939             :                         unsigned short instance, vrf_id_t vrf_id);
     940             : 
     941             : extern enum zclient_send_status
     942             : zebra_redistribute_default_send(int command, struct zclient *zclient, afi_t afi,
     943             :                                 vrf_id_t vrf_id);
     944             : 
     945             : /* Send route notify request to zebra */
     946             : extern int zebra_route_notify_send(int command, struct zclient *zclient,
     947             :                                    bool set);
     948             : 
     949             : /* If state has changed, update state and call zebra_redistribute_send. */
     950             : extern void zclient_redistribute(int command, struct zclient *, afi_t, int type,
     951             :                                  unsigned short instance, vrf_id_t vrf_id);
     952             : 
     953             : /* If state has changed, update state and send the command to zebra. */
     954             : extern void zclient_redistribute_default(int command, struct zclient *,
     955             :                                          afi_t, vrf_id_t vrf_id);
     956             : 
     957             : /*
     958             :  * Send the message in zclient->obuf to the zebra daemon (or enqueue it).
     959             :  * Returns:
     960             :  * -1 on a I/O error
     961             :  *  0 data was successfully sent
     962             :  *  1 data was buffered for future usage
     963             :  */
     964             : extern enum zclient_send_status zclient_send_message(struct zclient *);
     965             : 
     966             : /* create header for command, length to be filled in by user later */
     967             : extern void zclient_create_header(struct stream *, uint16_t, vrf_id_t);
     968             : /*
     969             :  * Read sizeof(struct zmsghdr) bytes from the provided socket and parse the
     970             :  * received data into the specified fields. If this is successful, read the
     971             :  * rest of the packet into the provided stream.
     972             :  *
     973             :  * s
     974             :  *    The stream to read into
     975             :  *
     976             :  * sock
     977             :  *    The socket to read from
     978             :  *
     979             :  * size
     980             :  *    Parsed message size will be placed in the pointed-at integer
     981             :  *
     982             :  * marker
     983             :  *    Parsed marker will be placed in the pointed-at byte
     984             :  *
     985             :  * version
     986             :  *    Parsed version will be placed in the pointed-at byte
     987             :  *
     988             :  * vrf_id
     989             :  *    Parsed VRF ID will be placed in the pointed-at vrf_id_t
     990             :  *
     991             :  * cmd
     992             :  *    Parsed command number will be placed in the pointed-at integer
     993             :  *
     994             :  * Returns:
     995             :  *    -1 if:
     996             :  *    - insufficient data for header was read
     997             :  *    - a version mismatch was detected
     998             :  *    - a marker mismatch was detected
     999             :  *    - header size field specified more data than could be read
    1000             :  */
    1001             : extern int zclient_read_header(struct stream *s, int sock, uint16_t *size,
    1002             :                                uint8_t *marker, uint8_t *version,
    1003             :                                vrf_id_t *vrf_id, uint16_t *cmd);
    1004             : /*
    1005             :  * Parse header from ZAPI message stream into struct zmsghdr.
    1006             :  * This function assumes the stream getp points at the first byte of the header.
    1007             :  * If the function is successful then the stream getp will point to the byte
    1008             :  * immediately after the last byte of the header.
    1009             :  *
    1010             :  * zmsg
    1011             :  *    The stream containing the header
    1012             :  *
    1013             :  * hdr
    1014             :  *    The header struct to parse into.
    1015             :  *
    1016             :  * Returns:
    1017             :  *    true if parsing succeeded, false otherwise
    1018             :  */
    1019             : extern bool zapi_parse_header(struct stream *zmsg, struct zmsghdr *hdr);
    1020             : 
    1021             : extern enum zclient_send_status
    1022             : zclient_interface_set_master(struct zclient *client, struct interface *master,
    1023             :                              struct interface *slave);
    1024             : extern struct interface *zebra_interface_state_read(struct stream *s, vrf_id_t);
    1025             : extern struct connected *zebra_interface_address_read(int, struct stream *,
    1026             :                                                       vrf_id_t);
    1027             : extern struct nbr_connected *
    1028             : zebra_interface_nbr_address_read(int, struct stream *, vrf_id_t);
    1029             : extern struct interface *zebra_interface_vrf_update_read(struct stream *s,
    1030             :                                                          vrf_id_t vrf_id,
    1031             :                                                          vrf_id_t *new_vrf_id);
    1032             : extern int zebra_router_id_update_read(struct stream *s, struct prefix *rid);
    1033             : 
    1034             : extern struct interface *zebra_interface_link_params_read(struct stream *s,
    1035             :                                                           vrf_id_t vrf_id,
    1036             :                                                           bool *changed);
    1037             : extern size_t zebra_interface_link_params_write(struct stream *,
    1038             :                                                 struct interface *);
    1039             : extern enum zclient_send_status
    1040             : zclient_send_get_label_chunk(struct zclient *zclient, uint8_t keep,
    1041             :                              uint32_t chunk_size, uint32_t base);
    1042             : 
    1043             : extern int lm_label_manager_connect(struct zclient *zclient, int async);
    1044             : extern int lm_get_label_chunk(struct zclient *zclient, uint8_t keep,
    1045             :                               uint32_t base, uint32_t chunk_size,
    1046             :                               uint32_t *start, uint32_t *end);
    1047             : extern int lm_release_label_chunk(struct zclient *zclient, uint32_t start,
    1048             :                                   uint32_t end);
    1049             : extern int tm_table_manager_connect(struct zclient *zclient);
    1050             : extern int tm_get_table_chunk(struct zclient *zclient, uint32_t chunk_size,
    1051             :                               uint32_t *start, uint32_t *end);
    1052             : extern int tm_release_table_chunk(struct zclient *zclient, uint32_t start,
    1053             :                                   uint32_t end);
    1054             : extern int srv6_manager_get_locator_chunk(struct zclient *zclient,
    1055             :                                           const char *locator_name);
    1056             : extern int srv6_manager_release_locator_chunk(struct zclient *zclient,
    1057             :                                               const char *locator_name);
    1058             : 
    1059             : extern enum zclient_send_status zebra_send_sr_policy(struct zclient *zclient,
    1060             :                                                      int cmd,
    1061             :                                                      struct zapi_sr_policy *zp);
    1062             : extern int zapi_sr_policy_encode(struct stream *s, int cmd,
    1063             :                                  struct zapi_sr_policy *zp);
    1064             : extern int zapi_sr_policy_decode(struct stream *s, struct zapi_sr_policy *zp);
    1065             : extern int zapi_sr_policy_notify_status_decode(struct stream *s,
    1066             :                                                struct zapi_sr_policy *zp);
    1067             : 
    1068             : extern enum zclient_send_status zebra_send_mpls_labels(struct zclient *zclient,
    1069             :                                                        int cmd,
    1070             :                                                        struct zapi_labels *zl);
    1071             : extern int zapi_labels_encode(struct stream *s, int cmd,
    1072             :                               struct zapi_labels *zl);
    1073             : extern int zapi_labels_decode(struct stream *s, struct zapi_labels *zl);
    1074             : 
    1075             : extern int zapi_srv6_locator_encode(struct stream *s,
    1076             :                                     const struct srv6_locator *l);
    1077             : extern int zapi_srv6_locator_decode(struct stream *s, struct srv6_locator *l);
    1078             : extern int zapi_srv6_locator_chunk_encode(struct stream *s,
    1079             :                                           const struct srv6_locator_chunk *c);
    1080             : extern int zapi_srv6_locator_chunk_decode(struct stream *s,
    1081             :                                           struct srv6_locator_chunk *c);
    1082             : 
    1083             : extern enum zclient_send_status zebra_send_pw(struct zclient *zclient,
    1084             :                                               int command, struct zapi_pw *pw);
    1085             : extern int zebra_read_pw_status_update(ZAPI_CALLBACK_ARGS,
    1086             :                                        struct zapi_pw_status *pw);
    1087             : 
    1088             : extern enum zclient_send_status zclient_route_send(uint8_t, struct zclient *,
    1089             :                                                    struct zapi_route *);
    1090             : extern enum zclient_send_status
    1091             : zclient_send_rnh(struct zclient *zclient, int command, const struct prefix *p,
    1092             :                  safi_t safi, bool connected, bool resolve_via_default,
    1093             :                  vrf_id_t vrf_id);
    1094             : int zapi_nexthop_encode(struct stream *s, const struct zapi_nexthop *api_nh,
    1095             :                         uint32_t api_flags, uint32_t api_message);
    1096             : extern int zapi_route_encode(uint8_t, struct stream *, struct zapi_route *);
    1097             : extern int zapi_route_decode(struct stream *s, struct zapi_route *api);
    1098             : extern int zapi_nexthop_decode(struct stream *s, struct zapi_nexthop *api_nh,
    1099             :                                uint32_t api_flags, uint32_t api_message);
    1100             : bool zapi_nhg_notify_decode(struct stream *s, uint32_t *id,
    1101             :                             enum zapi_nhg_notify_owner *note);
    1102             : bool zapi_route_notify_decode(struct stream *s, struct prefix *p,
    1103             :                               uint32_t *tableid,
    1104             :                               enum zapi_route_notify_owner *note,
    1105             :                               afi_t *afi, safi_t *safi);
    1106             : bool zapi_rule_notify_decode(struct stream *s, uint32_t *seqno,
    1107             :                              uint32_t *priority, uint32_t *unique, char *ifname,
    1108             :                              enum zapi_rule_notify_owner *note);
    1109             : bool zapi_ipset_notify_decode(struct stream *s,
    1110             :                               uint32_t *unique,
    1111             :                              enum zapi_ipset_notify_owner *note);
    1112             : 
    1113             : /* Nexthop-group message apis */
    1114             : extern enum zclient_send_status
    1115             : zclient_nhg_send(struct zclient *zclient, int cmd, struct zapi_nhg *api_nhg);
    1116             : 
    1117             : #define ZEBRA_IPSET_NAME_SIZE   32
    1118             : 
    1119             : bool zapi_ipset_entry_notify_decode(struct stream *s,
    1120             :             uint32_t *unique,
    1121             :             char *ipset_name,
    1122             :             enum zapi_ipset_entry_notify_owner *note);
    1123             : bool zapi_iptable_notify_decode(struct stream *s,
    1124             :                 uint32_t *unique,
    1125             :                 enum zapi_iptable_notify_owner *note);
    1126             : 
    1127             : extern struct nexthop *
    1128             : nexthop_from_zapi_nexthop(const struct zapi_nexthop *znh);
    1129             : int zapi_nexthop_from_nexthop(struct zapi_nexthop *znh,
    1130             :                               const struct nexthop *nh);
    1131             : int zapi_backup_nexthop_from_nexthop(struct zapi_nexthop *znh,
    1132             :                                      const struct nexthop *nh);
    1133             : /*
    1134             :  * match -> is the prefix that the calling daemon asked to be matched
    1135             :  * against.
    1136             :  * nhr->prefix -> is the actual prefix that was matched against in the
    1137             :  * rib itself.
    1138             :  *
    1139             :  * This distinction is made because a LPM can be made if there is a
    1140             :  * covering route.  This way the upper level protocol can make a decision
    1141             :  * point about whether or not it wants to use the match or not.
    1142             :  */
    1143             : extern bool zapi_nexthop_update_decode(struct stream *s, struct prefix *match,
    1144             :                                        struct zapi_route *nhr);
    1145             : const char *zapi_nexthop2str(const struct zapi_nexthop *znh, char *buf,
    1146             :                              int bufsize);
    1147             : 
    1148             : /* Decode the zebra error message */
    1149             : extern bool zapi_error_decode(struct stream *s, enum zebra_error_types *error);
    1150             : 
    1151             : /* Encode and decode restart capabilities */
    1152             : extern enum zclient_send_status
    1153             : zclient_capabilities_send(uint32_t cmd, struct zclient *zclient,
    1154             :                           struct zapi_cap *api);
    1155             : extern int32_t zapi_capabilities_decode(struct stream *s, struct zapi_cap *api);
    1156             : 
    1157             : static inline void zapi_route_set_blackhole(struct zapi_route *api,
    1158             :                                             enum blackhole_type bh_type)
    1159             : {
    1160             :         api->nexthop_num = 1;
    1161             :         api->nexthops[0].type = NEXTHOP_TYPE_BLACKHOLE;
    1162             :         api->nexthops[0].vrf_id = VRF_DEFAULT;
    1163             :         api->nexthops[0].bh_type = bh_type;
    1164             :         SET_FLAG(api->message, ZAPI_MESSAGE_NEXTHOP);
    1165             : };
    1166             : 
    1167             : extern enum zclient_send_status
    1168             : zclient_send_mlag_register(struct zclient *client, uint32_t bit_map);
    1169             : extern enum zclient_send_status
    1170             : zclient_send_mlag_deregister(struct zclient *client);
    1171             : 
    1172             : extern enum zclient_send_status zclient_send_mlag_data(struct zclient *client,
    1173             :                                                        struct stream *client_s);
    1174             : 
    1175             : /*
    1176             :  * Send an OPAQUE message, contents opaque to zebra - but note that
    1177             :  * the length of the payload is restricted by the zclient's
    1178             :  * outgoing message buffer.
    1179             :  * The message header is a message subtype; please use the registry
    1180             :  * below to avoid sub-type collisions. Clients use the registration
    1181             :  * apis to manage the specific opaque subtypes they want to receive.
    1182             :  */
    1183             : enum zclient_send_status zclient_send_opaque(struct zclient *zclient,
    1184             :                                              uint32_t type, const uint8_t *data,
    1185             :                                              size_t datasize);
    1186             : 
    1187             : enum zclient_send_status
    1188             : zclient_send_opaque_unicast(struct zclient *zclient, uint32_t type,
    1189             :                             uint8_t proto, uint16_t instance,
    1190             :                             uint32_t session_id, const uint8_t *data,
    1191             :                             size_t datasize);
    1192             : 
    1193             : /* Struct representing the decoded opaque header info */
    1194             : struct zapi_opaque_msg {
    1195             :         uint32_t type; /* Subtype */
    1196             :         uint16_t len;  /* len after zapi header and this info */
    1197             :         uint16_t flags;
    1198             : 
    1199             :         /* Client-specific info - *if* UNICAST flag is set */
    1200             :         uint8_t proto;
    1201             :         uint16_t instance;
    1202             :         uint32_t session_id;
    1203             : };
    1204             : 
    1205             : #define ZAPI_OPAQUE_FLAG_UNICAST   0x01
    1206             : 
    1207             : /* Simple struct to convey registration/unreg requests */
    1208             : struct zapi_opaque_reg_info {
    1209             :         /* Message subtype */
    1210             :         uint32_t type;
    1211             : 
    1212             :         /* Client session tuple */
    1213             :         uint8_t proto;
    1214             :         uint16_t instance;
    1215             :         uint32_t session_id;
    1216             : };
    1217             : 
    1218             : /* Decode incoming opaque */
    1219             : int zclient_opaque_decode(struct stream *msg, struct zapi_opaque_msg *info);
    1220             : 
    1221             : enum zclient_send_status zclient_register_opaque(struct zclient *zclient,
    1222             :                                                  uint32_t type);
    1223             : enum zclient_send_status zclient_unregister_opaque(struct zclient *zclient,
    1224             :                                                    uint32_t type);
    1225             : int zapi_opaque_reg_decode(struct stream *msg,
    1226             :                            struct zapi_opaque_reg_info *info);
    1227             : 
    1228             : /*
    1229             :  * Registry of opaque message types. Please do not reuse an in-use
    1230             :  * type code; some daemons are likely relying on it.
    1231             :  */
    1232             : enum zapi_opaque_registry {
    1233             :         /* Request link-state database dump, at restart for example */
    1234             :         LINK_STATE_SYNC = 1,
    1235             :         /* Update containing link-state db info */
    1236             :         LINK_STATE_UPDATE = 2,
    1237             :         /* Request LDP-SYNC state from LDP */
    1238             :         LDP_IGP_SYNC_IF_STATE_REQUEST = 3,
    1239             :         /* Update containing LDP IGP Sync State info */
    1240             :         LDP_IGP_SYNC_IF_STATE_UPDATE = 4,
    1241             :         /* Announce that LDP is up  */
    1242             :         LDP_IGP_SYNC_ANNOUNCE_UPDATE = 5,
    1243             :         /* Register RLFA with LDP */
    1244             :         LDP_RLFA_REGISTER = 7,
    1245             :         /* Unregister all RLFAs with LDP */
    1246             :         LDP_RLFA_UNREGISTER_ALL = 8,
    1247             :         /* Announce LDP labels associated to a previously registered RLFA */
    1248             :         LDP_RLFA_LABELS = 9,
    1249             : };
    1250             : 
    1251             : /* Send the hello message.
    1252             :  * Returns 0 for success or -1 on an I/O error.
    1253             :  */
    1254             : extern enum zclient_send_status zclient_send_hello(struct zclient *client);
    1255             : 
    1256             : extern enum zclient_send_status
    1257             : zclient_send_neigh_discovery_req(struct zclient *zclient,
    1258             :                                  const struct interface *ifp,
    1259             :                                  const struct prefix *p);
    1260             : 
    1261             : struct zapi_client_close_info {
    1262             :         /* Client session tuple */
    1263             :         uint8_t proto;
    1264             :         uint16_t instance;
    1265             :         uint32_t session_id;
    1266             : };
    1267             : 
    1268             : /* Decode incoming client close notify */
    1269             : extern int zapi_client_close_notify_decode(struct stream *s,
    1270             :                                            struct zapi_client_close_info *info);
    1271             : 
    1272             : extern int zclient_send_zebra_gre_request(struct zclient *client,
    1273             :                                           struct interface *ifp);
    1274             : #ifdef __cplusplus
    1275             : }
    1276             : #endif
    1277             : 
    1278             : #endif /* _ZEBRA_ZCLIENT_H */

Generated by: LCOV version v1.16-topotato