forked from openvswitch/ovs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdp_sysfs_if.c
More file actions
333 lines (294 loc) · 7.81 KB
/
Copy pathdp_sysfs_if.c
File metadata and controls
333 lines (294 loc) · 7.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
/*
* Copyright (c) 2009, 2010 Nicira Networks.
* Distributed under the terms of the GNU GPL version 2.
*
* Significant portions of this file may be copied from parts of the Linux
* kernel, by Linus Torvalds and others.
*/
/*
* Sysfs attributes of bridge ports for Open vSwitch
*
* This has been shamelessly copied from the kernel sources.
*/
#include <linux/capability.h>
#include <linux/kernel.h>
#include <linux/netdevice.h>
#include <linux/if_bridge.h>
#include <linux/rtnetlink.h>
#include <linux/spinlock.h>
#include "datapath.h"
#include "dp_sysfs.h"
#include "vport.h"
#ifdef CONFIG_SYSFS
struct brport_attribute {
struct attribute attr;
ssize_t (*show)(struct dp_port *, char *);
ssize_t (*store)(struct dp_port *, unsigned long);
};
#define BRPORT_ATTR(_name,_mode,_show,_store) \
struct brport_attribute brport_attr_##_name = { \
.attr = {.name = __stringify(_name), \
.mode = _mode, \
.owner = THIS_MODULE, }, \
.show = _show, \
.store = _store, \
};
static ssize_t show_path_cost(struct dp_port *p, char *buf)
{
#if 0
return sprintf(buf, "%d\n", p->path_cost);
#else
return sprintf(buf, "%d\n", 0);
#endif
}
static ssize_t store_path_cost(struct dp_port *p, unsigned long v)
{
#if 0
br_stp_set_path_cost(p, v);
#endif
return 0;
}
static BRPORT_ATTR(path_cost, S_IRUGO | S_IWUSR,
show_path_cost, store_path_cost);
static ssize_t show_priority(struct dp_port *p, char *buf)
{
#if 0
return sprintf(buf, "%d\n", p->priority);
#else
return sprintf(buf, "%d\n", 0);
#endif
}
static ssize_t store_priority(struct dp_port *p, unsigned long v)
{
#if 0
if (v >= (1<<(16-BR_PORT_BITS)))
return -ERANGE;
br_stp_set_port_priority(p, v);
#endif
return 0;
}
static BRPORT_ATTR(priority, S_IRUGO | S_IWUSR,
show_priority, store_priority);
static ssize_t show_designated_root(struct dp_port *p, char *buf)
{
#if 0
return br_show_bridge_id(buf, &p->designated_root);
#else
return sprintf(buf, "0000.010203040506\n");
#endif
}
static BRPORT_ATTR(designated_root, S_IRUGO, show_designated_root, NULL);
static ssize_t show_designated_bridge(struct dp_port *p, char *buf)
{
#if 0
return br_show_bridge_id(buf, &p->designated_bridge);
#else
return sprintf(buf, "0000.060504030201\n");
#endif
}
static BRPORT_ATTR(designated_bridge, S_IRUGO, show_designated_bridge, NULL);
static ssize_t show_designated_port(struct dp_port *p, char *buf)
{
#if 0
return sprintf(buf, "%d\n", p->designated_port);
#else
return sprintf(buf, "%d\n", 0);
#endif
}
static BRPORT_ATTR(designated_port, S_IRUGO, show_designated_port, NULL);
static ssize_t show_designated_cost(struct dp_port *p, char *buf)
{
#if 0
return sprintf(buf, "%d\n", p->designated_cost);
#else
return sprintf(buf, "%d\n", 0);
#endif
}
static BRPORT_ATTR(designated_cost, S_IRUGO, show_designated_cost, NULL);
static ssize_t show_port_id(struct dp_port *p, char *buf)
{
#if 0
return sprintf(buf, "0x%x\n", p->port_id);
#else
return sprintf(buf, "0x%x\n", 0);
#endif
}
static BRPORT_ATTR(port_id, S_IRUGO, show_port_id, NULL);
static ssize_t show_port_no(struct dp_port *p, char *buf)
{
return sprintf(buf, "0x%x\n", p->port_no);
}
static BRPORT_ATTR(port_no, S_IRUGO, show_port_no, NULL);
static ssize_t show_change_ack(struct dp_port *p, char *buf)
{
#if 0
return sprintf(buf, "%d\n", p->topology_change_ack);
#else
return sprintf(buf, "%d\n", 0);
#endif
}
static BRPORT_ATTR(change_ack, S_IRUGO, show_change_ack, NULL);
static ssize_t show_config_pending(struct dp_port *p, char *buf)
{
#if 0
return sprintf(buf, "%d\n", p->config_pending);
#else
return sprintf(buf, "%d\n", 0);
#endif
}
static BRPORT_ATTR(config_pending, S_IRUGO, show_config_pending, NULL);
static ssize_t show_port_state(struct dp_port *p, char *buf)
{
#if 0
return sprintf(buf, "%d\n", p->state);
#else
return sprintf(buf, "%d\n", 0);
#endif
}
static BRPORT_ATTR(state, S_IRUGO, show_port_state, NULL);
static ssize_t show_message_age_timer(struct dp_port *p,
char *buf)
{
#if 0
return sprintf(buf, "%ld\n", br_timer_value(&p->message_age_timer));
#else
return sprintf(buf, "%d\n", 0);
#endif
}
static BRPORT_ATTR(message_age_timer, S_IRUGO, show_message_age_timer, NULL);
static ssize_t show_forward_delay_timer(struct dp_port *p,
char *buf)
{
#if 0
return sprintf(buf, "%ld\n", br_timer_value(&p->forward_delay_timer));
#else
return sprintf(buf, "%d\n", 0);
#endif
}
static BRPORT_ATTR(forward_delay_timer, S_IRUGO, show_forward_delay_timer, NULL);
static ssize_t show_hold_timer(struct dp_port *p,
char *buf)
{
#if 0
return sprintf(buf, "%ld\n", br_timer_value(&p->hold_timer));
#else
return sprintf(buf, "%d\n", 0);
#endif
}
static BRPORT_ATTR(hold_timer, S_IRUGO, show_hold_timer, NULL);
static struct brport_attribute *brport_attrs[] = {
&brport_attr_path_cost,
&brport_attr_priority,
&brport_attr_port_id,
&brport_attr_port_no,
&brport_attr_designated_root,
&brport_attr_designated_bridge,
&brport_attr_designated_port,
&brport_attr_designated_cost,
&brport_attr_state,
&brport_attr_change_ack,
&brport_attr_config_pending,
&brport_attr_message_age_timer,
&brport_attr_forward_delay_timer,
&brport_attr_hold_timer,
NULL
};
#define to_brport_attr(_at) container_of(_at, struct brport_attribute, attr)
#define to_brport(obj) container_of(obj, struct dp_port, kobj)
static ssize_t brport_show(struct kobject * kobj,
struct attribute * attr, char * buf)
{
struct brport_attribute * brport_attr = to_brport_attr(attr);
struct dp_port * p = to_brport(kobj);
return brport_attr->show(p, buf);
}
static ssize_t brport_store(struct kobject * kobj,
struct attribute * attr,
const char * buf, size_t count)
{
struct dp_port * p = to_brport(kobj);
#if 0
struct brport_attribute * brport_attr = to_brport_attr(attr);
char *endp;
unsigned long val;
#endif
ssize_t ret = -EINVAL;
if (!capable(CAP_NET_ADMIN))
return -EPERM;
#if 0
val = simple_strtoul(buf, &endp, 0);
if (endp != buf) {
rtnl_lock();
if (p->dev && p->br && brport_attr->store) {
spin_lock_bh(&p->br->lock);
ret = brport_attr->store(p, val);
spin_unlock_bh(&p->br->lock);
if (ret == 0)
ret = count;
}
rtnl_unlock();
}
#else
printk("%s: xxx writing port parms not supported yet!\n",
dp_name(p->dp));
#endif
return ret;
}
struct sysfs_ops brport_sysfs_ops = {
.show = brport_show,
.store = brport_store,
};
/*
* Add sysfs entries to ethernet device added to a bridge.
* Creates a brport subdirectory with bridge attributes.
* Puts symlink in bridge's brport subdirectory
*/
int dp_sysfs_add_if(struct dp_port *p)
{
struct kobject *kobj = vport_get_kobj(p->vport);
struct datapath *dp = p->dp;
struct brport_attribute **a;
int err;
/* Create /sys/class/net/<devname>/brport directory. */
if (!kobj)
return -ENOENT;
err = kobject_add(&p->kobj, kobj, SYSFS_BRIDGE_PORT_ATTR);
if (err)
goto err;
/* Create symlink from /sys/class/net/<devname>/brport/bridge to
* /sys/class/net/<bridgename>. */
err = sysfs_create_link(&p->kobj, vport_get_kobj(dp->ports[ODPP_LOCAL]->vport),
SYSFS_BRIDGE_PORT_LINK); /* "bridge" */
if (err)
goto err_del;
/* Populate /sys/class/net/<devname>/brport directory with files. */
for (a = brport_attrs; *a; ++a) {
err = sysfs_create_file(&p->kobj, &((*a)->attr));
if (err)
goto err_del;
}
/* Create symlink from /sys/class/net/<bridgename>/brif/<devname> to
* /sys/class/net/<devname>/brport. */
err = sysfs_create_link(&dp->ifobj, &p->kobj, vport_get_name(p->vport));
if (err)
goto err_del;
strcpy(p->linkname, vport_get_name(p->vport));
kobject_uevent(&p->kobj, KOBJ_ADD);
return 0;
err_del:
kobject_del(&p->kobj);
err:
p->linkname[0] = 0;
return err;
}
int dp_sysfs_del_if(struct dp_port *p)
{
if (p->linkname[0]) {
sysfs_remove_link(&p->dp->ifobj, p->linkname);
kobject_uevent(&p->kobj, KOBJ_REMOVE);
kobject_del(&p->kobj);
p->linkname[0] = '\0';
}
return 0;
}
#endif /* CONFIG_SYSFS */