switchdev.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. /*
  2. * include/net/switchdev.h - Switch device API
  3. * Copyright (c) 2014 Jiri Pirko <jiri@resnulli.us>
  4. * Copyright (c) 2014-2015 Scott Feldman <sfeldma@gmail.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. */
  11. #ifndef _LINUX_SWITCHDEV_H_
  12. #define _LINUX_SWITCHDEV_H_
  13. #include <linux/netdevice.h>
  14. #include <linux/notifier.h>
  15. #define SWITCHDEV_F_NO_RECURSE BIT(0)
  16. enum switchdev_trans {
  17. SWITCHDEV_TRANS_NONE,
  18. SWITCHDEV_TRANS_PREPARE,
  19. SWITCHDEV_TRANS_ABORT,
  20. SWITCHDEV_TRANS_COMMIT,
  21. };
  22. enum switchdev_attr_id {
  23. SWITCHDEV_ATTR_UNDEFINED,
  24. SWITCHDEV_ATTR_PORT_PARENT_ID,
  25. SWITCHDEV_ATTR_PORT_STP_STATE,
  26. SWITCHDEV_ATTR_PORT_BRIDGE_FLAGS,
  27. };
  28. struct switchdev_attr {
  29. enum switchdev_attr_id id;
  30. enum switchdev_trans trans;
  31. u32 flags;
  32. union {
  33. struct netdev_phys_item_id ppid; /* PORT_PARENT_ID */
  34. u8 stp_state; /* PORT_STP_STATE */
  35. unsigned long brport_flags; /* PORT_BRIDGE_FLAGS */
  36. } u;
  37. };
  38. struct fib_info;
  39. enum switchdev_obj_id {
  40. SWITCHDEV_OBJ_UNDEFINED,
  41. SWITCHDEV_OBJ_PORT_VLAN,
  42. SWITCHDEV_OBJ_IPV4_FIB,
  43. SWITCHDEV_OBJ_PORT_FDB,
  44. };
  45. struct switchdev_obj {
  46. enum switchdev_obj_id id;
  47. enum switchdev_trans trans;
  48. int (*cb)(struct net_device *dev, struct switchdev_obj *obj);
  49. union {
  50. struct switchdev_obj_vlan { /* PORT_VLAN */
  51. u16 flags;
  52. u16 vid_begin;
  53. u16 vid_end;
  54. } vlan;
  55. struct switchdev_obj_ipv4_fib { /* IPV4_FIB */
  56. u32 dst;
  57. int dst_len;
  58. struct fib_info *fi;
  59. u8 tos;
  60. u8 type;
  61. u32 nlflags;
  62. u32 tb_id;
  63. } ipv4_fib;
  64. struct switchdev_obj_fdb { /* PORT_FDB */
  65. const unsigned char *addr;
  66. u16 vid;
  67. u16 ndm_state;
  68. } fdb;
  69. } u;
  70. };
  71. /**
  72. * struct switchdev_ops - switchdev operations
  73. *
  74. * @switchdev_port_attr_get: Get a port attribute (see switchdev_attr).
  75. *
  76. * @switchdev_port_attr_set: Set a port attribute (see switchdev_attr).
  77. *
  78. * @switchdev_port_obj_add: Add an object to port (see switchdev_obj).
  79. *
  80. * @switchdev_port_obj_del: Delete an object from port (see switchdev_obj).
  81. *
  82. * @switchdev_port_obj_dump: Dump port objects (see switchdev_obj).
  83. */
  84. struct switchdev_ops {
  85. int (*switchdev_port_attr_get)(struct net_device *dev,
  86. struct switchdev_attr *attr);
  87. int (*switchdev_port_attr_set)(struct net_device *dev,
  88. struct switchdev_attr *attr);
  89. int (*switchdev_port_obj_add)(struct net_device *dev,
  90. struct switchdev_obj *obj);
  91. int (*switchdev_port_obj_del)(struct net_device *dev,
  92. struct switchdev_obj *obj);
  93. int (*switchdev_port_obj_dump)(struct net_device *dev,
  94. struct switchdev_obj *obj);
  95. };
  96. enum switchdev_notifier_type {
  97. SWITCHDEV_FDB_ADD = 1,
  98. SWITCHDEV_FDB_DEL,
  99. };
  100. struct switchdev_notifier_info {
  101. struct net_device *dev;
  102. };
  103. struct switchdev_notifier_fdb_info {
  104. struct switchdev_notifier_info info; /* must be first */
  105. const unsigned char *addr;
  106. u16 vid;
  107. };
  108. static inline struct net_device *
  109. switchdev_notifier_info_to_dev(const struct switchdev_notifier_info *info)
  110. {
  111. return info->dev;
  112. }
  113. #ifdef CONFIG_NET_SWITCHDEV
  114. int switchdev_port_attr_get(struct net_device *dev,
  115. struct switchdev_attr *attr);
  116. int switchdev_port_attr_set(struct net_device *dev,
  117. struct switchdev_attr *attr);
  118. int switchdev_port_obj_add(struct net_device *dev, struct switchdev_obj *obj);
  119. int switchdev_port_obj_del(struct net_device *dev, struct switchdev_obj *obj);
  120. int switchdev_port_obj_dump(struct net_device *dev, struct switchdev_obj *obj);
  121. int register_switchdev_notifier(struct notifier_block *nb);
  122. int unregister_switchdev_notifier(struct notifier_block *nb);
  123. int call_switchdev_notifiers(unsigned long val, struct net_device *dev,
  124. struct switchdev_notifier_info *info);
  125. int switchdev_port_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq,
  126. struct net_device *dev, u32 filter_mask,
  127. int nlflags);
  128. int switchdev_port_bridge_setlink(struct net_device *dev,
  129. struct nlmsghdr *nlh, u16 flags);
  130. int switchdev_port_bridge_dellink(struct net_device *dev,
  131. struct nlmsghdr *nlh, u16 flags);
  132. int switchdev_fib_ipv4_add(u32 dst, int dst_len, struct fib_info *fi,
  133. u8 tos, u8 type, u32 nlflags, u32 tb_id);
  134. int switchdev_fib_ipv4_del(u32 dst, int dst_len, struct fib_info *fi,
  135. u8 tos, u8 type, u32 tb_id);
  136. void switchdev_fib_ipv4_abort(struct fib_info *fi);
  137. int switchdev_port_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
  138. struct net_device *dev, const unsigned char *addr,
  139. u16 vid, u16 nlm_flags);
  140. int switchdev_port_fdb_del(struct ndmsg *ndm, struct nlattr *tb[],
  141. struct net_device *dev, const unsigned char *addr,
  142. u16 vid);
  143. int switchdev_port_fdb_dump(struct sk_buff *skb, struct netlink_callback *cb,
  144. struct net_device *dev,
  145. struct net_device *filter_dev, int idx);
  146. void switchdev_port_fwd_mark_set(struct net_device *dev,
  147. struct net_device *group_dev,
  148. bool joining);
  149. #else
  150. static inline int switchdev_port_attr_get(struct net_device *dev,
  151. struct switchdev_attr *attr)
  152. {
  153. return -EOPNOTSUPP;
  154. }
  155. static inline int switchdev_port_attr_set(struct net_device *dev,
  156. struct switchdev_attr *attr)
  157. {
  158. return -EOPNOTSUPP;
  159. }
  160. static inline int switchdev_port_obj_add(struct net_device *dev,
  161. struct switchdev_obj *obj)
  162. {
  163. return -EOPNOTSUPP;
  164. }
  165. static inline int switchdev_port_obj_del(struct net_device *dev,
  166. struct switchdev_obj *obj)
  167. {
  168. return -EOPNOTSUPP;
  169. }
  170. static inline int switchdev_port_obj_dump(struct net_device *dev,
  171. struct switchdev_obj *obj)
  172. {
  173. return -EOPNOTSUPP;
  174. }
  175. static inline int register_switchdev_notifier(struct notifier_block *nb)
  176. {
  177. return 0;
  178. }
  179. static inline int unregister_switchdev_notifier(struct notifier_block *nb)
  180. {
  181. return 0;
  182. }
  183. static inline int call_switchdev_notifiers(unsigned long val,
  184. struct net_device *dev,
  185. struct switchdev_notifier_info *info)
  186. {
  187. return NOTIFY_DONE;
  188. }
  189. static inline int switchdev_port_bridge_getlink(struct sk_buff *skb, u32 pid,
  190. u32 seq, struct net_device *dev,
  191. u32 filter_mask, int nlflags)
  192. {
  193. return -EOPNOTSUPP;
  194. }
  195. static inline int switchdev_port_bridge_setlink(struct net_device *dev,
  196. struct nlmsghdr *nlh,
  197. u16 flags)
  198. {
  199. return -EOPNOTSUPP;
  200. }
  201. static inline int switchdev_port_bridge_dellink(struct net_device *dev,
  202. struct nlmsghdr *nlh,
  203. u16 flags)
  204. {
  205. return -EOPNOTSUPP;
  206. }
  207. static inline int switchdev_fib_ipv4_add(u32 dst, int dst_len,
  208. struct fib_info *fi,
  209. u8 tos, u8 type,
  210. u32 nlflags, u32 tb_id)
  211. {
  212. return 0;
  213. }
  214. static inline int switchdev_fib_ipv4_del(u32 dst, int dst_len,
  215. struct fib_info *fi,
  216. u8 tos, u8 type, u32 tb_id)
  217. {
  218. return 0;
  219. }
  220. static inline void switchdev_fib_ipv4_abort(struct fib_info *fi)
  221. {
  222. }
  223. static inline int switchdev_port_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
  224. struct net_device *dev,
  225. const unsigned char *addr,
  226. u16 vid, u16 nlm_flags)
  227. {
  228. return -EOPNOTSUPP;
  229. }
  230. static inline int switchdev_port_fdb_del(struct ndmsg *ndm, struct nlattr *tb[],
  231. struct net_device *dev,
  232. const unsigned char *addr, u16 vid)
  233. {
  234. return -EOPNOTSUPP;
  235. }
  236. static inline int switchdev_port_fdb_dump(struct sk_buff *skb,
  237. struct netlink_callback *cb,
  238. struct net_device *dev,
  239. struct net_device *filter_dev,
  240. int idx)
  241. {
  242. return -EOPNOTSUPP;
  243. }
  244. static inline void switchdev_port_fwd_mark_set(struct net_device *dev,
  245. struct net_device *group_dev,
  246. bool joining)
  247. {
  248. }
  249. #endif
  250. #endif /* _LINUX_SWITCHDEV_H_ */