linkd

Control plane daemon for unos
git clone git://git.finwo.net/app/linkd
Log | Files | Refs | README

dataplane.h (3255B)


      1 #ifndef __LINKD_DATAPLANE_H__
      2 #define __LINKD_DATAPLANE_H__
      3 
      4 #include <stdbool.h>
      5 #include <stddef.h>
      6 #include <stdint.h>
      7 
      8 #define DP_RET_ERROR -1
      9 #define DP_RET_OK     0
     10 
     11 // Plugins are separate processes speaking RESP, declared in /etc/linkd.cnf:
     12 //
     13 //   plugin /usr/lib/linkd/bcm          spawned, RESP over stdio
     14 //   plugin tcp://user:pass@host:6789   connected to, RESP over the socket
     15 //
     16 // They advertise what they implement via COMMAND, and each operation is
     17 // broadcast to every plugin advertising its verb. There is no in-process ABI
     18 // and nothing is dlopen'd, so a plugin can be written in any language.
     19 
     20 enum dp_fec {
     21   DP_FEC_UNSET = 0,
     22   DP_FEC_OFF,
     23   DP_FEC_AUTO,
     24   DP_FEC_RS,
     25   DP_FEC_BASER,
     26 };
     27 
     28 struct dp_addr {
     29   int     family;      // AF_INET | AF_INET6
     30   uint8_t addr[16];
     31   uint8_t prefixlen;
     32 };
     33 
     34 // Physical-layer properties of a switch port, from /etc/linkd/ports.cnf.
     35 //
     36 // Deliberately narrow: anything the kernel already models on a netdev (MTU,
     37 // admin state, addresses, MAC) is owned by ifupdown and reaches us through
     38 // netlink instead. Only properties with no working kernel path on a KNET stub
     39 // netdev live here.
     40 struct dp_port {
     41   const char *name;    // swp1, ...
     42   uint32_t    speed;   // Mbit/s, 0 = unset
     43   enum dp_fec fec;
     44   int         autoneg; // -1 unset, 0 off, 1 on
     45 };
     46 
     47 struct dp_rif {
     48   const char     *ifname;
     49   struct dp_addr  addr;
     50   uint32_t        table;   // kernel route-table id; RT_TABLE_MAIN = default VRF
     51 };
     52 
     53 struct dp_neigh {
     54   const char     *ifname;
     55   struct dp_addr  addr;
     56   uint8_t         mac[6];
     57   uint32_t        table;   // kernel route-table id; RT_TABLE_MAIN = default VRF
     58 };
     59 
     60 struct dp_nexthop {
     61   const char     *ifname;
     62   struct dp_addr  gw;
     63 };
     64 
     65 struct dp_route {
     66   struct dp_addr     dst;
     67   struct dp_nexthop *nh;
     68   size_t             nh_count;   // >1 = ECMP group
     69   uint32_t           metric;     // RTA_PRIORITY, 0 = unset
     70   uint32_t           table;      // kernel route-table id; RT_TABLE_MAIN = default VRF
     71 };
     72 
     73 // Start every plugin declared in the config. Plugins that fail to start are
     74 // retried with backoff; this is not an error in itself.
     75 int  dp_start(void);
     76 void dp_stop(void);
     77 
     78 // True when at least one plugin is configured. Without any, every operation
     79 // below is a successful no-op -- the kernel has already done the work by the
     80 // time these are called.
     81 int  dp_have_plugins(void);
     82 
     83 // Operations. Each is broadcast to every plugin advertising the verb; all of
     84 // them are called even if an earlier one fails, so plugins cannot end up in
     85 // states that disagree with each other. Returns DP_RET_ERROR if any
     86 // non-optional plugin failed.
     87 int dp_port_apply(const struct dp_port *port);
     88 int dp_port_admin(const char *ifname, bool up);
     89 int dp_port_mtu(const char *ifname, uint32_t mtu);
     90 
     91 int dp_rif_add(const struct dp_rif *rif);
     92 int dp_rif_del(const struct dp_rif *rif);
     93 
     94 int dp_neigh_add(const struct dp_neigh *neigh);
     95 int dp_neigh_del(const struct dp_neigh *neigh);
     96 
     97 int dp_route_add(const struct dp_route *route);
     98 int dp_route_del(const struct dp_route *route);
     99 
    100 // Netlink drops messages under load (ENOBUFS), so following events alone
    101 // drifts; plugins are told to rebuild from scratch periodically.
    102 int dp_resync(void);
    103 
    104 #endif // __LINKD_DATAPLANE_H__