]> git.proxmox.com Git - mirror_ubuntu-eoan-kernel.git/blame - include/net/switchdev.h
bridge: revert br_dellink change back to original
[mirror_ubuntu-eoan-kernel.git] / include / net / switchdev.h
CommitLineData
007f790c
JP
1/*
2 * include/net/switchdev.h - Switch device API
3 * Copyright (c) 2014 Jiri Pirko <jiri@resnulli.us>
f8f21471 4 * Copyright (c) 2014-2015 Scott Feldman <sfeldma@gmail.com>
007f790c
JP
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
14#include <linux/netdevice.h>
03bf0c28
JP
15#include <linux/notifier.h>
16
3094333d
SF
17#define SWITCHDEV_F_NO_RECURSE BIT(0)
18
19enum switchdev_trans {
20 SWITCHDEV_TRANS_NONE,
21 SWITCHDEV_TRANS_PREPARE,
22 SWITCHDEV_TRANS_ABORT,
23 SWITCHDEV_TRANS_COMMIT,
24};
25
26enum switchdev_attr_id {
27 SWITCHDEV_ATTR_UNDEFINED,
f8e20a9f 28 SWITCHDEV_ATTR_PORT_PARENT_ID,
35636062 29 SWITCHDEV_ATTR_PORT_STP_STATE,
6004c867 30 SWITCHDEV_ATTR_PORT_BRIDGE_FLAGS,
3094333d
SF
31};
32
33struct switchdev_attr {
34 enum switchdev_attr_id id;
35 enum switchdev_trans trans;
36 u32 flags;
f8e20a9f
SF
37 union {
38 struct netdev_phys_item_id ppid; /* PORT_PARENT_ID */
35636062 39 u8 stp_state; /* PORT_STP_STATE */
6004c867 40 unsigned long brport_flags; /* PORT_BRIDGE_FLAGS */
f8e20a9f 41 };
3094333d
SF
42};
43
4170604f
SF
44struct fib_info;
45
491d0f15
SF
46enum switchdev_obj_id {
47 SWITCHDEV_OBJ_UNDEFINED,
6fc3016d 48 SWITCHDEV_OBJ_PORT_VLAN,
491d0f15
SF
49};
50
51struct switchdev_obj {
52 enum switchdev_obj_id id;
53 enum switchdev_trans trans;
6fc3016d
SF
54 union {
55 struct switchdev_obj_vlan { /* PORT_VLAN */
56 u16 flags;
57 u16 vid_start;
58 u16 vid_end;
59 } vlan;
60 };
491d0f15
SF
61};
62
4170604f
SF
63/**
64 * struct switchdev_ops - switchdev operations
65 *
3094333d
SF
66 * @switchdev_port_attr_get: Get a port attribute (see switchdev_attr).
67 *
68 * @switchdev_port_attr_set: Set a port attribute (see switchdev_attr).
69 *
491d0f15
SF
70 * @switchdev_port_obj_add: Add an object to port (see switchdev_obj).
71 *
72 * @switchdev_port_obj_del: Delete an object from port (see switchdev_obj).
73 *
9d47c0a2 74 * @switchdev_fib_ipv4_add: Called to add/modify IPv4 route to switch device.
4170604f 75 *
9d47c0a2 76 * @switchdev_fib_ipv4_del: Called to delete IPv4 route from switch device.
4170604f 77 */
9d47c0a2 78struct switchdev_ops {
3094333d
SF
79 int (*switchdev_port_attr_get)(struct net_device *dev,
80 struct switchdev_attr *attr);
81 int (*switchdev_port_attr_set)(struct net_device *dev,
82 struct switchdev_attr *attr);
491d0f15
SF
83 int (*switchdev_port_obj_add)(struct net_device *dev,
84 struct switchdev_obj *obj);
85 int (*switchdev_port_obj_del)(struct net_device *dev,
86 struct switchdev_obj *obj);
9d47c0a2
JP
87 int (*switchdev_fib_ipv4_add)(struct net_device *dev, __be32 dst,
88 int dst_len, struct fib_info *fi,
89 u8 tos, u8 type, u32 nlflags,
90 u32 tb_id);
91 int (*switchdev_fib_ipv4_del)(struct net_device *dev, __be32 dst,
92 int dst_len, struct fib_info *fi,
93 u8 tos, u8 type, u32 tb_id);
4170604f
SF
94};
95
ebb9a03a
JP
96enum switchdev_notifier_type {
97 SWITCHDEV_FDB_ADD = 1,
98 SWITCHDEV_FDB_DEL,
3aeb6617
JP
99};
100
ebb9a03a 101struct switchdev_notifier_info {
03bf0c28
JP
102 struct net_device *dev;
103};
104
ebb9a03a
JP
105struct switchdev_notifier_fdb_info {
106 struct switchdev_notifier_info info; /* must be first */
3aeb6617
JP
107 const unsigned char *addr;
108 u16 vid;
109};
110
03bf0c28 111static inline struct net_device *
ebb9a03a 112switchdev_notifier_info_to_dev(const struct switchdev_notifier_info *info)
03bf0c28
JP
113{
114 return info->dev;
115}
007f790c
JP
116
117#ifdef CONFIG_NET_SWITCHDEV
118
3094333d
SF
119int switchdev_port_attr_get(struct net_device *dev,
120 struct switchdev_attr *attr);
121int switchdev_port_attr_set(struct net_device *dev,
122 struct switchdev_attr *attr);
491d0f15
SF
123int switchdev_port_obj_add(struct net_device *dev, struct switchdev_obj *obj);
124int switchdev_port_obj_del(struct net_device *dev, struct switchdev_obj *obj);
ebb9a03a
JP
125int register_switchdev_notifier(struct notifier_block *nb);
126int unregister_switchdev_notifier(struct notifier_block *nb);
127int call_switchdev_notifiers(unsigned long val, struct net_device *dev,
128 struct switchdev_notifier_info *info);
129int switchdev_port_bridge_setlink(struct net_device *dev,
130 struct nlmsghdr *nlh, u16 flags);
131int switchdev_port_bridge_dellink(struct net_device *dev,
132 struct nlmsghdr *nlh, u16 flags);
ebb9a03a
JP
133int switchdev_fib_ipv4_add(u32 dst, int dst_len, struct fib_info *fi,
134 u8 tos, u8 type, u32 nlflags, u32 tb_id);
135int switchdev_fib_ipv4_del(u32 dst, int dst_len, struct fib_info *fi,
136 u8 tos, u8 type, u32 tb_id);
137void switchdev_fib_ipv4_abort(struct fib_info *fi);
5e8d9049 138
007f790c
JP
139#else
140
3094333d
SF
141static inline int switchdev_port_attr_get(struct net_device *dev,
142 struct switchdev_attr *attr)
143{
144 return -EOPNOTSUPP;
145}
146
147static inline int switchdev_port_attr_set(struct net_device *dev,
148 struct switchdev_attr *attr)
149{
150 return -EOPNOTSUPP;
151}
152
491d0f15
SF
153static inline int switchdev_port_obj_add(struct net_device *dev,
154 struct switchdev_obj *obj)
155{
156 return -EOPNOTSUPP;
157}
158
159static inline int switchdev_port_obj_del(struct net_device *dev,
160 struct switchdev_obj *obj)
161{
162 return -EOPNOTSUPP;
163}
164
ebb9a03a 165static inline int register_switchdev_notifier(struct notifier_block *nb)
03bf0c28
JP
166{
167 return 0;
168}
169
ebb9a03a 170static inline int unregister_switchdev_notifier(struct notifier_block *nb)
03bf0c28
JP
171{
172 return 0;
173}
174
ebb9a03a
JP
175static inline int call_switchdev_notifiers(unsigned long val,
176 struct net_device *dev,
177 struct switchdev_notifier_info *info)
03bf0c28
JP
178{
179 return NOTIFY_DONE;
180}
181
ebb9a03a
JP
182static inline int switchdev_port_bridge_setlink(struct net_device *dev,
183 struct nlmsghdr *nlh,
184 u16 flags)
8a44dbb2
RP
185{
186 return -EOPNOTSUPP;
187}
188
ebb9a03a
JP
189static inline int switchdev_port_bridge_dellink(struct net_device *dev,
190 struct nlmsghdr *nlh,
191 u16 flags)
8a44dbb2
RP
192{
193 return -EOPNOTSUPP;
194}
195
ebb9a03a
JP
196static inline int switchdev_fib_ipv4_add(u32 dst, int dst_len,
197 struct fib_info *fi,
198 u8 tos, u8 type,
199 u32 nlflags, u32 tb_id)
5e8d9049
SF
200{
201 return 0;
202}
203
ebb9a03a
JP
204static inline int switchdev_fib_ipv4_del(u32 dst, int dst_len,
205 struct fib_info *fi,
206 u8 tos, u8 type, u32 tb_id)
5e8d9049
SF
207{
208 return 0;
209}
210
ebb9a03a 211static inline void switchdev_fib_ipv4_abort(struct fib_info *fi)
8e05fd71
SF
212{
213}
214
007f790c
JP
215#endif
216
217#endif /* _LINUX_SWITCHDEV_H_ */