switchdev.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  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. } fdb;
  68. } u;
  69. };
  70. /**
  71. * struct switchdev_ops - switchdev operations
  72. *
  73. * @switchdev_port_attr_get: Get a port attribute (see switchdev_attr).
  74. *
  75. * @switchdev_port_attr_set: Set a port attribute (see switchdev_attr).
  76. *
  77. * @switchdev_port_obj_add: Add an object to port (see switchdev_obj).
  78. *
  79. * @switchdev_port_obj_del: Delete an object from port (see switchdev_obj).
  80. *
  81. * @switchdev_port_obj_dump: Dump port objects (see switchdev_obj).
  82. */
  83. struct switchdev_ops {
  84. int (*switchdev_port_attr_get)(struct net_device *dev,
  85. struct switchdev_attr *attr);
  86. int (*switchdev_port_attr_set)(struct net_device *dev,
  87. struct switchdev_attr *attr);
  88. int (*switchdev_port_obj_add)(struct net_device *dev,
  89. struct switchdev_obj *obj);
  90. int (*switchdev_port_obj_del)(struct net_device *dev,
  91. struct switchdev_obj *obj);
  92. int (*switchdev_port_obj_dump)(struct net_device *dev,
  93. struct switchdev_obj *obj);
  94. };
  95. enum switchdev_notifier_type {
  96. SWITCHDEV_FDB_ADD = 1,
  97. SWITCHDEV_FDB_DEL,
  98. };
  99. struct switchdev_notifier_info {
  100. struct net_device *dev;
  101. };
  102. struct switchdev_notifier_fdb_info {
  103. struct switchdev_notifier_info info; /* must be first */
  104. const unsigned char *addr;
  105. u16 vid;
  106. };
  107. static inline struct net_device *
  108. switchdev_notifier_info_to_dev(const struct switchdev_notifier_info *info)
  109. {
  110. return info->dev;
  111. }
  112. #ifdef CONFIG_NET_SWITCHDEV
  113. int switchdev_port_attr_get(struct net_device *dev,
  114. struct switchdev_attr *attr);
  115. int switchdev_port_attr_set(struct net_device *dev,
  116. struct switchdev_attr *attr);
  117. int switchdev_port_obj_add(struct net_device *dev, struct switchdev_obj *obj);
  118. int switchdev_port_obj_del(struct net_device *dev, struct switchdev_obj *obj);
  119. int switchdev_port_obj_dump(struct net_device *dev, struct switchdev_obj *obj);
  120. int register_switchdev_notifier(struct notifier_block *nb);
  121. int unregister_switchdev_notifier(struct notifier_block *nb);
  122. int call_switchdev_notifiers(unsigned long val, struct net_device *dev,
  123. struct switchdev_notifier_info *info);
  124. int switchdev_port_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq,
  125. struct net_device *dev, u32 filter_mask,
  126. int nlflags);
  127. int switchdev_port_bridge_setlink(struct net_device *dev,
  128. struct nlmsghdr *nlh, u16 flags);
  129. int switchdev_port_bridge_dellink(struct net_device *dev,
  130. struct nlmsghdr *nlh, u16 flags);
  131. int switchdev_fib_ipv4_add(u32 dst, int dst_len, struct fib_info *fi,
  132. u8 tos, u8 type, u32 nlflags, u32 tb_id);
  133. int switchdev_fib_ipv4_del(u32 dst, int dst_len, struct fib_info *fi,
  134. u8 tos, u8 type, u32 tb_id);
  135. void switchdev_fib_ipv4_abort(struct fib_info *fi);
  136. int switchdev_port_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
  137. struct net_device *dev, const unsigned char *addr,
  138. u16 vid, u16 nlm_flags);
  139. int switchdev_port_fdb_del(struct ndmsg *ndm, struct nlattr *tb[],
  140. struct net_device *dev, const unsigned char *addr,
  141. u16 vid);
  142. int switchdev_port_fdb_dump(struct sk_buff *skb, struct netlink_callback *cb,
  143. struct net_device *dev,
  144. struct net_device *filter_dev, int idx);
  145. void switchdev_port_fwd_mark_set(struct net_device *dev,
  146. struct net_device *group_dev,
  147. bool joining);
  148. #else
  149. static inline int switchdev_port_attr_get(struct net_device *dev,
  150. struct switchdev_attr *attr)
  151. {
  152. return -EOPNOTSUPP;
  153. }
  154. static inline int switchdev_port_attr_set(struct net_device *dev,
  155. struct switchdev_attr *attr)
  156. {
  157. return -EOPNOTSUPP;
  158. }
  159. static inline int switchdev_port_obj_add(struct net_device *dev,
  160. struct switchdev_obj *obj)
  161. {
  162. return -EOPNOTSUPP;
  163. }
  164. static inline int switchdev_port_obj_del(struct net_device *dev,
  165. struct switchdev_obj *obj)
  166. {
  167. return -EOPNOTSUPP;
  168. }
  169. static inline int switchdev_port_obj_dump(struct net_device *dev,
  170. struct switchdev_obj *obj)
  171. {
  172. return -EOPNOTSUPP;
  173. }
  174. static inline int register_switchdev_notifier(struct notifier_block *nb)
  175. {
  176. return 0;
  177. }
  178. static inline int unregister_switchdev_notifier(struct notifier_block *nb)
  179. {
  180. return 0;
  181. }
  182. static inline int call_switchdev_notifiers(unsigned long val,
  183. struct net_device *dev,
  184. struct switchdev_notifier_info *info)
  185. {
  186. return NOTIFY_DONE;
  187. }
  188. static inline int switchdev_port_bridge_getlink(struct sk_buff *skb, u32 pid,
  189. u32 seq, struct net_device *dev,
  190. u32 filter_mask, int nlflags)
  191. {
  192. return -EOPNOTSUPP;
  193. }
  194. static inline int switchdev_port_bridge_setlink(struct net_device *dev,
  195. struct nlmsghdr *nlh,
  196. u16 flags)
  197. {
  198. return -EOPNOTSUPP;
  199. }
  200. static inline int switchdev_port_bridge_dellink(struct net_device *dev,
  201. struct nlmsghdr *nlh,
  202. u16 flags)
  203. {
  204. return -EOPNOTSUPP;
  205. }
  206. static inline int switchdev_fib_ipv4_add(u32 dst, int dst_len,
  207. struct fib_info *fi,
  208. u8 tos, u8 type,
  209. u32 nlflags, u32 tb_id)
  210. {
  211. return 0;
  212. }
  213. static inline int switchdev_fib_ipv4_del(u32 dst, int dst_len,
  214. struct fib_info *fi,
  215. u8 tos, u8 type, u32 tb_id)
  216. {
  217. return 0;
  218. }
  219. static inline void switchdev_fib_ipv4_abort(struct fib_info *fi)
  220. {
  221. }
  222. static inline int switchdev_port_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
  223. struct net_device *dev,
  224. const unsigned char *addr,
  225. u16 vid, u16 nlm_flags)
  226. {
  227. return -EOPNOTSUPP;
  228. }
  229. static inline int switchdev_port_fdb_del(struct ndmsg *ndm, struct nlattr *tb[],
  230. struct net_device *dev,
  231. const unsigned char *addr, u16 vid)
  232. {
  233. return -EOPNOTSUPP;
  234. }
  235. static inline int switchdev_port_fdb_dump(struct sk_buff *skb,
  236. struct netlink_callback *cb,
  237. struct net_device *dev,
  238. struct net_device *filter_dev,
  239. int idx)
  240. {
  241. return -EOPNOTSUPP;
  242. }
  243. static inline void switchdev_port_fwd_mark_set(struct net_device *dev,
  244. struct net_device *group_dev,
  245. bool joining)
  246. {
  247. }
  248. #endif
  249. #endif /* _LINUX_SWITCHDEV_H_ */