system.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  1. /*
  2. * netifd - network interface daemon
  3. * Copyright (C) 2012 Felix Fietkau <nbd@openwrt.org>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License version 2
  7. * as published by the Free Software Foundation
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. */
  14. #ifndef __NETIFD_SYSTEM_H
  15. #define __NETIFD_SYSTEM_H
  16. #include <net/if.h>
  17. #include <sys/time.h>
  18. #include <sys/socket.h>
  19. #include <arpa/inet.h>
  20. #include "device.h"
  21. #include "interface-ip.h"
  22. #include "iprule.h"
  23. #include "utils.h"
  24. struct netdev_type {
  25. unsigned short id;
  26. const char *name;
  27. };
  28. static const struct netdev_type netdev_types[] = {
  29. {ARPHRD_NETROM, "netrom"},
  30. {ARPHRD_ETHER, "ethernet"},
  31. {ARPHRD_EETHER, "eethernet"},
  32. {ARPHRD_AX25, "ax25"},
  33. {ARPHRD_PRONET, "pronet"},
  34. {ARPHRD_CHAOS, "chaos"},
  35. {ARPHRD_IEEE802, "ieee802"},
  36. {ARPHRD_ARCNET, "arcnet"},
  37. {ARPHRD_APPLETLK, "appletlk"},
  38. {ARPHRD_DLCI, "dlci"},
  39. {ARPHRD_ATM, "atm"},
  40. {ARPHRD_METRICOM, "metricom"},
  41. {ARPHRD_IEEE1394, "ieee1394"},
  42. {ARPHRD_EUI64, "eui64"},
  43. {ARPHRD_INFINIBAND, "infiniband"},
  44. {ARPHRD_SLIP, "slip"},
  45. {ARPHRD_CSLIP, "cslip"},
  46. {ARPHRD_SLIP6, "slip6"},
  47. {ARPHRD_CSLIP6, "cslip6"},
  48. {ARPHRD_RSRVD, "rsrvd"},
  49. {ARPHRD_ADAPT, "adapt"},
  50. {ARPHRD_ROSE, "rose"},
  51. {ARPHRD_X25, "x25"},
  52. {ARPHRD_HWX25, "hwx25"},
  53. {ARPHRD_PPP, "ppp"},
  54. {ARPHRD_CISCO, "cisco"},
  55. {ARPHRD_LAPB, "lapb"},
  56. {ARPHRD_DDCMP, "ddcmp"},
  57. {ARPHRD_RAWHDLC, "rawhdlc"},
  58. {ARPHRD_TUNNEL, "tunnel"},
  59. {ARPHRD_TUNNEL6, "tunnel6"},
  60. {ARPHRD_FRAD, "frad"},
  61. {ARPHRD_SKIP, "skip"},
  62. {ARPHRD_LOOPBACK, "loopback"},
  63. {ARPHRD_LOCALTLK, "localtlk"},
  64. {ARPHRD_FDDI, "fddi"},
  65. {ARPHRD_BIF, "bif"},
  66. {ARPHRD_SIT, "sit"},
  67. {ARPHRD_IPDDP, "ipddp"},
  68. {ARPHRD_IPGRE, "ipgre"},
  69. {ARPHRD_PIMREG,"pimreg"},
  70. {ARPHRD_HIPPI, "hippi"},
  71. {ARPHRD_ASH, "ash"},
  72. {ARPHRD_ECONET, "econet"},
  73. {ARPHRD_IRDA, "irda"},
  74. {ARPHRD_FCPP, "fcpp"},
  75. {ARPHRD_FCAL, "fcal"},
  76. {ARPHRD_FCPL, "fcpl"},
  77. {ARPHRD_FCFABRIC, "fcfabric"},
  78. {ARPHRD_IEEE80211, "ieee80211"},
  79. {ARPHRD_IEEE80211_PRISM, "ie80211-prism"},
  80. {ARPHRD_IEEE80211_RADIOTAP, "ieee80211-radiotap"},
  81. #ifdef ARPHRD_PHONET
  82. {ARPHRD_PHONET, "phonet"},
  83. #endif
  84. #ifdef ARPHRD_PHONET_PIPE
  85. {ARPHRD_PHONET_PIPE, "phonet-pipe"},
  86. #endif
  87. {ARPHRD_IEEE802154, "ieee802154"},
  88. {ARPHRD_VOID, "void"},
  89. {ARPHRD_NONE, "none"}
  90. };
  91. enum tunnel_param {
  92. TUNNEL_ATTR_TYPE,
  93. TUNNEL_ATTR_REMOTE,
  94. TUNNEL_ATTR_LOCAL,
  95. TUNNEL_ATTR_MTU,
  96. TUNNEL_ATTR_DF,
  97. TUNNEL_ATTR_TTL,
  98. TUNNEL_ATTR_TOS,
  99. TUNNEL_ATTR_LINK,
  100. TUNNEL_ATTR_DATA,
  101. __TUNNEL_ATTR_MAX
  102. };
  103. extern const struct uci_blob_param_list tunnel_attr_list;
  104. enum vxlan_data {
  105. VXLAN_DATA_ATTR_ID,
  106. VXLAN_DATA_ATTR_PORT,
  107. VXLAN_DATA_ATTR_MACADDR,
  108. VXLAN_DATA_ATTR_RXCSUM,
  109. VXLAN_DATA_ATTR_TXCSUM,
  110. VXLAN_DATA_ATTR_SRCPORTMIN,
  111. VXLAN_DATA_ATTR_SRCPORTMAX,
  112. VXLAN_DATA_ATTR_LEARNING,
  113. VXLAN_DATA_ATTR_RSC,
  114. VXLAN_DATA_ATTR_PROXY,
  115. VXLAN_DATA_ATTR_L2MISS,
  116. VXLAN_DATA_ATTR_L3MISS,
  117. VXLAN_DATA_ATTR_GBP,
  118. VXLAN_DATA_ATTR_AGEING,
  119. VXLAN_DATA_ATTR_LIMIT,
  120. __VXLAN_DATA_ATTR_MAX
  121. };
  122. enum gre_data {
  123. GRE_DATA_IKEY,
  124. GRE_DATA_OKEY,
  125. GRE_DATA_ICSUM,
  126. GRE_DATA_OCSUM,
  127. GRE_DATA_ISEQNO,
  128. GRE_DATA_OSEQNO,
  129. GRE_DATA_ENCAPLIMIT,
  130. __GRE_DATA_ATTR_MAX
  131. };
  132. enum vti_data {
  133. VTI_DATA_IKEY,
  134. VTI_DATA_OKEY,
  135. __VTI_DATA_ATTR_MAX
  136. };
  137. enum xfrm_data {
  138. XFRM_DATA_IF_ID,
  139. __XFRM_DATA_ATTR_MAX
  140. };
  141. enum sixrd_data {
  142. SIXRD_DATA_PREFIX,
  143. SIXRD_DATA_RELAY_PREFIX,
  144. __SIXRD_DATA_ATTR_MAX
  145. };
  146. enum ipip6_data {
  147. IPIP6_DATA_ENCAPLIMIT,
  148. IPIP6_DATA_FMRS,
  149. __IPIP6_DATA_ATTR_MAX
  150. };
  151. enum fmr_data {
  152. FMR_DATA_PREFIX6,
  153. FMR_DATA_PREFIX4,
  154. FMR_DATA_EALEN,
  155. FMR_DATA_OFFSET,
  156. __FMR_DATA_ATTR_MAX
  157. };
  158. extern const struct uci_blob_param_list vxlan_data_attr_list;
  159. extern const struct uci_blob_param_list gre_data_attr_list;
  160. extern const struct uci_blob_param_list vti_data_attr_list;
  161. extern const struct uci_blob_param_list xfrm_data_attr_list;
  162. extern const struct uci_blob_param_list sixrd_data_attr_list;
  163. extern const struct uci_blob_param_list ipip6_data_attr_list;
  164. extern const struct uci_blob_param_list fmr_data_attr_list;
  165. enum bridge_opt {
  166. /* stp, forward delay, max age and hello time are always set */
  167. BRIDGE_OPT_AGEING_TIME = (1 << 0),
  168. BRIDGE_OPT_ROBUSTNESS = (1 << 1),
  169. BRIDGE_OPT_QUERY_INTERVAL = (1 << 2),
  170. BRIDGE_OPT_QUERY_RESPONSE_INTERVAL = (1 << 3),
  171. BRIDGE_OPT_LAST_MEMBER_INTERVAL = (1 << 4),
  172. };
  173. struct bridge_config {
  174. enum bridge_opt flags;
  175. bool stp;
  176. bool stp_kernel;
  177. const char *stp_proto;
  178. bool igmp_snoop;
  179. bool multicast_querier;
  180. int robustness;
  181. int query_interval;
  182. int query_response_interval;
  183. int last_member_interval;
  184. unsigned short priority;
  185. int forward_delay;
  186. bool bridge_empty;
  187. int ageing_time;
  188. int hello_time;
  189. int max_age;
  190. int hash_max;
  191. bool vlan_filtering;
  192. };
  193. enum macvlan_opt {
  194. MACVLAN_OPT_MACADDR = (1 << 0),
  195. };
  196. struct macvlan_config {
  197. const char *mode;
  198. enum macvlan_opt flags;
  199. unsigned char macaddr[6];
  200. };
  201. enum veth_opt {
  202. VETH_OPT_MACADDR = (1 << 0),
  203. VETH_OPT_PEER_NAME = (1 << 1),
  204. VETH_OPT_PEER_MACADDR = (1 << 2),
  205. };
  206. struct veth_config {
  207. enum veth_opt flags;
  208. unsigned char macaddr[6];
  209. char peer_name[IFNAMSIZ];
  210. unsigned char peer_macaddr[6];
  211. };
  212. enum vlan_proto {
  213. VLAN_PROTO_8021Q = 0x8100,
  214. VLAN_PROTO_8021AD = 0x88A8
  215. };
  216. struct vlan_qos_mapping {
  217. struct vlist_simple_node node; /* entry in vlandev_config->{e,in}gress_qos_mapping_list */
  218. uint32_t from;
  219. uint32_t to;
  220. };
  221. struct vlandev_config {
  222. enum vlan_proto proto;
  223. uint16_t vid;
  224. struct vlist_simple_tree ingress_qos_mapping_list; /* list of struct vlan_qos_mapping */
  225. struct vlist_simple_tree egress_qos_mapping_list; /* list of struct vlan_qos_mapping */
  226. };
  227. enum bonding_mode {
  228. BONDING_MODE_BALANCE_RR,
  229. BONDING_MODE_ACTIVE_BACKUP,
  230. BONDING_MODE_BALANCE_XOR,
  231. BONDING_MODE_BROADCAST,
  232. BONDING_MODE_8023AD,
  233. BONDING_MODE_BALANCE_TLB,
  234. BONDING_MODE_BALANCE_ALB,
  235. __BONDING_MODE_MAX,
  236. };
  237. struct bonding_config {
  238. enum bonding_mode policy;
  239. const char *xmit_hash_policy;
  240. bool all_ports_active;
  241. int min_links;
  242. const char *ad_actor_system;
  243. int ad_actor_sys_prio;
  244. const char *ad_select;
  245. const char *lacp_rate;
  246. int packets_per_port;
  247. int lp_interval;
  248. bool dynamic_lb;
  249. int resend_igmp;
  250. int num_peer_notif;
  251. const char *primary;
  252. const char *primary_reselect;
  253. const char *failover_mac;
  254. bool monitor_arp;
  255. int monitor_interval;
  256. struct blob_attr *arp_target;
  257. bool arp_all_targets;
  258. const char *arp_validate;
  259. bool use_carrier;
  260. int updelay;
  261. int downdelay;
  262. };
  263. static inline int system_get_addr_family(unsigned int flags)
  264. {
  265. if ((flags & DEVADDR_FAMILY) == DEVADDR_INET6)
  266. return AF_INET6;
  267. else
  268. return AF_INET;
  269. }
  270. static inline int system_get_addr_len(unsigned int flags)
  271. {
  272. if ((flags & DEVADDR_FAMILY) != DEVADDR_INET6)
  273. return sizeof(struct in_addr);
  274. else
  275. return sizeof(struct in6_addr);
  276. }
  277. extern const char * const bonding_policy_str[__BONDING_MODE_MAX];
  278. int system_init(void);
  279. int system_bridge_addbr(struct device *bridge, struct bridge_config *cfg);
  280. int system_bridge_delbr(struct device *bridge);
  281. int system_bridge_addif(struct device *bridge, struct device *dev);
  282. int system_bridge_delif(struct device *bridge, struct device *dev);
  283. int system_bridge_vlan(const char *iface, uint16_t vid, bool add, unsigned int vflags);
  284. int system_bridge_vlan_check(struct device *dev, char *ifname);
  285. void system_bridge_set_stp_state(struct device *dev, bool val);
  286. int system_bonding_set_device(struct device *dev, struct bonding_config *cfg);
  287. int system_bonding_set_port(struct device *dev, struct device *port, bool add, bool primary);
  288. int system_macvlan_add(struct device *macvlan, struct device *dev, struct macvlan_config *cfg);
  289. int system_macvlan_del(struct device *macvlan);
  290. int system_veth_add(struct device *veth, struct veth_config *cfg);
  291. int system_veth_del(struct device *veth);
  292. int system_vlan_add(struct device *dev, int id);
  293. int system_vlan_del(struct device *dev);
  294. int system_vlandev_add(struct device *vlandev, struct device *dev, struct vlandev_config *cfg);
  295. int system_vlandev_del(struct device *vlandev);
  296. void system_if_get_settings(struct device *dev, struct device_settings *s);
  297. void system_if_clear_state(struct device *dev);
  298. int system_if_up(struct device *dev);
  299. int system_if_down(struct device *dev);
  300. int system_if_check(struct device *dev);
  301. int system_if_resolve(struct device *dev);
  302. int system_if_dump_info(struct device *dev, struct blob_buf *b);
  303. int system_if_dump_stats(struct device *dev, struct blob_buf *b);
  304. struct device *system_if_get_parent(struct device *dev);
  305. bool system_if_force_external(const char *ifname);
  306. void system_if_apply_settings(struct device *dev, struct device_settings *s,
  307. uint64_t apply_mask);
  308. int system_add_address(struct device *dev, struct device_addr *addr);
  309. int system_del_address(struct device *dev, struct device_addr *addr);
  310. int system_add_route(struct device *dev, struct device_route *route);
  311. int system_del_route(struct device *dev, struct device_route *route);
  312. int system_flush_routes(void);
  313. int system_add_neighbor(struct device *dev, struct device_neighbor * neighbor);
  314. int system_del_neighbor(struct device *dev, struct device_neighbor * neighbor);
  315. bool system_resolve_rt_type(const char *type, unsigned int *id);
  316. bool system_resolve_rt_proto(const char *type, unsigned int *id);
  317. bool system_resolve_rt_table(const char *name, unsigned int *id);
  318. bool system_is_default_rt_table(unsigned int id);
  319. bool system_resolve_rpfilter(const char *filter, unsigned int *id);
  320. int system_del_ip_tunnel(const struct device *dev);
  321. int system_add_ip_tunnel(const struct device *dev, struct blob_attr *attr);
  322. int system_add_iprule(struct iprule *rule);
  323. int system_del_iprule(struct iprule *rule);
  324. int system_flush_iprules(void);
  325. bool system_resolve_iprule_action(const char *action, unsigned int *id);
  326. time_t system_get_rtime(void);
  327. void system_fd_set_cloexec(int fd);
  328. int system_update_ipv6_mtu(struct device *dev, int mtu);
  329. int system_link_netns_move(struct device *dev, const pid_t target_ns, const char *target_ifname);
  330. int system_netns_open(const pid_t target_ns);
  331. int system_netns_set(int netns_fd);
  332. #endif