switchdev.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  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. #else
  146. static inline int switchdev_port_attr_get(struct net_device *dev,
  147. struct switchdev_attr *attr)
  148. {
  149. return -EOPNOTSUPP;
  150. }
  151. static inline int switchdev_port_attr_set(struct net_device *dev,
  152. struct switchdev_attr *attr)
  153. {
  154. return -EOPNOTSUPP;
  155. }
  156. static inline int switchdev_port_obj_add(struct net_device *dev,
  157. struct switchdev_obj *obj)
  158. {
  159. return -EOPNOTSUPP;
  160. }
  161. static inline int switchdev_port_obj_del(struct net_device *dev,
  162. struct switchdev_obj *obj)
  163. {
  164. return -EOPNOTSUPP;
  165. }
  166. static inline int switchdev_port_obj_dump(struct net_device *dev,
  167. struct switchdev_obj *obj)
  168. {
  169. return -EOPNOTSUPP;
  170. }
  171. static inline int register_switchdev_notifier(struct notifier_block *nb)
  172. {
  173. return 0;
  174. }
  175. static inline int unregister_switchdev_notifier(struct notifier_block *nb)
  176. {
  177. return 0;
  178. }
  179. static inline int call_switchdev_notifiers(unsigned long val,
  180. struct net_device *dev,
  181. struct switchdev_notifier_info *info)
  182. {
  183. return NOTIFY_DONE;
  184. }
  185. static inline int switchdev_port_bridge_getlink(struct sk_buff *skb, u32 pid,
  186. u32 seq, struct net_device *dev,
  187. u32 filter_mask, int nlflags)
  188. {
  189. return -EOPNOTSUPP;
  190. }
  191. static inline int switchdev_port_bridge_setlink(struct net_device *dev,
  192. struct nlmsghdr *nlh,
  193. u16 flags)
  194. {
  195. return -EOPNOTSUPP;
  196. }
  197. static inline int switchdev_port_bridge_dellink(struct net_device *dev,
  198. struct nlmsghdr *nlh,
  199. u16 flags)
  200. {
  201. return -EOPNOTSUPP;
  202. }
  203. static inline int switchdev_fib_ipv4_add(u32 dst, int dst_len,
  204. struct fib_info *fi,
  205. u8 tos, u8 type,
  206. u32 nlflags, u32 tb_id)
  207. {
  208. return 0;
  209. }
  210. static inline int switchdev_fib_ipv4_del(u32 dst, int dst_len,
  211. struct fib_info *fi,
  212. u8 tos, u8 type, u32 tb_id)
  213. {
  214. return 0;
  215. }
  216. static inline void switchdev_fib_ipv4_abort(struct fib_info *fi)
  217. {
  218. }
  219. static inline int switchdev_port_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
  220. struct net_device *dev,
  221. const unsigned char *addr,
  222. u16 vid, u16 nlm_flags)
  223. {
  224. return -EOPNOTSUPP;
  225. }
  226. static inline int switchdev_port_fdb_del(struct ndmsg *ndm, struct nlattr *tb[],
  227. struct net_device *dev,
  228. const unsigned char *addr, u16 vid)
  229. {
  230. return -EOPNOTSUPP;
  231. }
  232. static inline int switchdev_port_fdb_dump(struct sk_buff *skb,
  233. struct netlink_callback *cb,
  234. struct net_device *dev,
  235. struct net_device *filter_dev,
  236. int idx)
  237. {
  238. return -EOPNOTSUPP;
  239. }
  240. #endif
  241. #endif /* _LINUX_SWITCHDEV_H_ */