rtnl.h (1622B)
1 #ifndef __LINKD_RTRNL_H__ 2 #define __LINKD_RTRNL_H__ 3 4 #include <stdbool.h> 5 6 // Netlink helpers that replace system("ip ..."). 7 // All return 0 on success, -1 on failure (and log via rxi/log). 8 9 int rtnl_link_up(const char *ifname); 10 int rtnl_link_down(const char *ifname); 11 int rtnl_link_set_mtu(const char *ifname, int mtu); 12 int rtnl_link_set_hwaddr(const char *ifname, const char *hwaddr); 13 14 // address may be "10.0.0.1/24" or "2001:db8::1/64"; netmask is optional second arg for compat 15 int rtnl_addr_add(const char *ifname, const char *address, const char *netmask); 16 int rtnl_addr_del(const char *ifname, const char *address, const char *netmask); 17 18 int rtnl_route_add_default(const char *gateway, const char *ifname); 19 int rtnl_route_del_default(const char *gateway, const char *ifname); 20 21 // VLAN: create name type vlan id vlan_id with link rawdev (raw may be inferred from dot) 22 int rtnl_vlan_create(const char *name, const char *rawdev, int vlan_id); 23 24 // Bridge: create br with stp/vlan_aware, and enslave ports (space-separated) 25 // VRF: create an L3 master device bound to a routing table, and enslave 26 // interfaces to it. `table` is mandatory -- it is what actually separates the 27 // VRF's routes from main. 28 int rtnl_vrf_create(const char *name, uint32_t table); 29 int rtnl_vrf_add_port(const char *vrf, const char *port); 30 31 int rtnl_bridge_create(const char *name); 32 int rtnl_bridge_set_stp(const char *name, bool on); 33 int rtnl_bridge_set_vlan_aware(const char *name, bool on); 34 int rtnl_bridge_add_port(const char *br, const char *port); 35 int rtnl_bridge_del_port(const char *br, const char *port); 36 37 #endif // __LINKD_RTRNL_H__