linkd

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

kernel.c (2832B)


      1 // Built-in dataplane backend.
      2 //
      3 // This is the "there is no switching ASIC" case: generic x86_64, a VM, or a
      4 // soft-router. The Linux kernel is already the forwarding engine, so every
      5 // entry point here is a genuine no-op rather than an unimplemented stub:
      6 //
      7 //   - addresses, MTU, MAC and admin state are applied by ifupdown directly to
      8 //     the netdev, so there is nothing to replicate
      9 //   - routes and neighbours are already in the FIB by the time we observe the
     10 //     netlink message announcing them
     11 //   - speed / FEC / autoneg are PHY properties of a real NIC, driven through
     12 //     ethtool, and meaningless in a VM
     13 //
     14 // Mirroring any of it back into the kernel would be circular. linkd on generic
     15 // hardware is therefore close to inert by design: it parses configuration,
     16 // validates it, and lets Linux do the work.
     17 //
     18 // The table field on rif/neigh/route is accepted and ignored here: there is
     19 // nothing per-VRF to replicate when the kernel itself forwards.
     20 
     21 #include <stdio.h>
     22 
     23 #include "dataplane.h"
     24 
     25 static int kernel_probe(void) {
     26   // Always usable -- this is the fallback of last resort.
     27   return DP_RET_OK;
     28 }
     29 
     30 static int kernel_init(void) {
     31   fprintf(stderr, "dataplane/kernel: forwarding handled by the kernel\n");
     32   return DP_RET_OK;
     33 }
     34 
     35 static void kernel_fini(void) {
     36 }
     37 
     38 static int kernel_port_apply(const struct dp_port *port) { (void)port;            return DP_RET_OK; }
     39 static int kernel_port_admin(const char *ifname, bool up) { (void)ifname; (void)up; return DP_RET_OK; }
     40 static int kernel_port_mtu(const char *ifname, uint32_t mtu) { (void)ifname; (void)mtu; return DP_RET_OK; }
     41 
     42 static int kernel_rif_add(const struct dp_rif *rif)       { (void)rif;   return DP_RET_OK; }
     43 static int kernel_rif_del(const struct dp_rif *rif)       { (void)rif;   return DP_RET_OK; }
     44 static int kernel_neigh_add(const struct dp_neigh *neigh) { (void)neigh; return DP_RET_OK; }
     45 static int kernel_neigh_del(const struct dp_neigh *neigh) { (void)neigh; return DP_RET_OK; }
     46 static int kernel_route_add(const struct dp_route *route) { (void)route; return DP_RET_OK; }
     47 static int kernel_route_del(const struct dp_route *route) { (void)route; return DP_RET_OK; }
     48 
     49 static int kernel_resync(void) {
     50   return DP_RET_OK;
     51 }
     52 
     53 static const struct dp_ops kernel_ops = {
     54   .abi        = LINKD_DATAPLANE_ABI,
     55   .name       = "kernel",
     56   .probe      = kernel_probe,
     57   .init       = kernel_init,
     58   .fini       = kernel_fini,
     59   .port_apply = kernel_port_apply,
     60   .port_admin = kernel_port_admin,
     61   .port_mtu   = kernel_port_mtu,
     62   .rif_add    = kernel_rif_add,
     63   .rif_del    = kernel_rif_del,
     64   .neigh_add  = kernel_neigh_add,
     65   .neigh_del  = kernel_neigh_del,
     66   .route_add  = kernel_route_add,
     67   .route_del  = kernel_route_del,
     68   .resync     = kernel_resync,
     69 };
     70 
     71 const struct dp_ops * dp_kernel_ops(void) {
     72   return &kernel_ops;
     73 }