aboutsummaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorStefan Rompf <stefan@loplof.de>2006-03-20 20:09:11 -0500
committerDavid S. Miller <davem@davemloft.net>2006-03-20 20:09:11 -0500
commitb00055aacdb172c05067612278ba27265fcd05ce (patch)
tree4dbbee11b02d54cc0978113dfb07c53fdce17aa8 /net
parente843b9e1bec4a953d848a319da6a18ca5c667f55 (diff)
[NET] core: add RFC2863 operstate
this patch adds a dormant flag to network devices, RFC2863 operstate derived from these flags and possibility for userspace interaction. It allows drivers to signal that a device is unusable for user traffic without disabling queueing (and therefore the possibility for protocol establishment traffic to flow) and a userspace supplicant (WPA, 802.1X) to mark a device unusable without changes to the driver. It is the result of our long discussion. However I must admit that it represents what Jamal and I agreed on with compromises towards Krzysztof, but Thomas and Krzysztof still disagree with some parts. Anyway I think it should be applied. Signed-off-by: Stefan Rompf <stefan@loplof.de> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net')
-rw-r--r--net/core/dev.c14
-rw-r--r--net/core/link_watch.c40
-rw-r--r--net/core/net-sysfs.c41
-rw-r--r--net/core/rtnetlink.c50
4 files changed, 142 insertions, 3 deletions
diff --git a/net/core/dev.c b/net/core/dev.c
index ef56c035d44e..8763c99fcb84 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -2174,12 +2174,20 @@ unsigned dev_get_flags(const struct net_device *dev)
2174 2174
2175 flags = (dev->flags & ~(IFF_PROMISC | 2175 flags = (dev->flags & ~(IFF_PROMISC |
2176 IFF_ALLMULTI | 2176 IFF_ALLMULTI |
2177 IFF_RUNNING)) | 2177 IFF_RUNNING |
2178 IFF_LOWER_UP |
2179 IFF_DORMANT)) |
2178 (dev->gflags & (IFF_PROMISC | 2180 (dev->gflags & (IFF_PROMISC |
2179 IFF_ALLMULTI)); 2181 IFF_ALLMULTI));
2180 2182
2181 if (netif_running(dev) && netif_carrier_ok(dev)) 2183 if (netif_running(dev)) {
2182 flags |= IFF_RUNNING; 2184 if (netif_oper_up(dev))
2185 flags |= IFF_RUNNING;
2186 if (netif_carrier_ok(dev))
2187 flags |= IFF_LOWER_UP;
2188 if (netif_dormant(dev))
2189 flags |= IFF_DORMANT;
2190 }
2183 2191
2184 return flags; 2192 return flags;
2185} 2193}
diff --git a/net/core/link_watch.c b/net/core/link_watch.c
index d43d1201275c..e82a451d330b 100644
--- a/net/core/link_watch.c
+++ b/net/core/link_watch.c
@@ -49,6 +49,45 @@ struct lw_event {
49/* Avoid kmalloc() for most systems */ 49/* Avoid kmalloc() for most systems */
50static struct lw_event singleevent; 50static struct lw_event singleevent;
51 51
52static unsigned char default_operstate(const struct net_device *dev)
53{
54 if (!netif_carrier_ok(dev))
55 return (dev->ifindex != dev->iflink ?
56 IF_OPER_LOWERLAYERDOWN : IF_OPER_DOWN);
57
58 if (netif_dormant(dev))
59 return IF_OPER_DORMANT;
60
61 return IF_OPER_UP;
62}
63
64
65static void rfc2863_policy(struct net_device *dev)
66{
67 unsigned char operstate = default_operstate(dev);
68
69 if (operstate == dev->operstate)
70 return;
71
72 write_lock_bh(&dev_base_lock);
73
74 switch(dev->link_mode) {
75 case IF_LINK_MODE_DORMANT:
76 if (operstate == IF_OPER_UP)
77 operstate = IF_OPER_DORMANT;
78 break;
79
80 case IF_LINK_MODE_DEFAULT:
81 default:
82 break;
83 };
84
85 dev->operstate = operstate;
86
87 write_unlock_bh(&dev_base_lock);
88}
89
90
52/* Must be called with the rtnl semaphore held */ 91/* Must be called with the rtnl semaphore held */
53void linkwatch_run_queue(void) 92void linkwatch_run_queue(void)
54{ 93{
@@ -74,6 +113,7 @@ void linkwatch_run_queue(void)
74 */ 113 */
75 clear_bit(__LINK_STATE_LINKWATCH_PENDING, &dev->state); 114 clear_bit(__LINK_STATE_LINKWATCH_PENDING, &dev->state);
76 115
116 rfc2863_policy(dev);
77 if (dev->flags & IFF_UP) { 117 if (dev->flags & IFF_UP) {
78 if (netif_carrier_ok(dev)) { 118 if (netif_carrier_ok(dev)) {
79 WARN_ON(dev->qdisc_sleeping == &noop_qdisc); 119 WARN_ON(dev->qdisc_sleeping == &noop_qdisc);
diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
index e8b2acbc8ea2..21b68464cabb 100644
--- a/net/core/net-sysfs.c
+++ b/net/core/net-sysfs.c
@@ -91,6 +91,7 @@ NETDEVICE_SHOW(iflink, fmt_dec);
91NETDEVICE_SHOW(ifindex, fmt_dec); 91NETDEVICE_SHOW(ifindex, fmt_dec);
92NETDEVICE_SHOW(features, fmt_long_hex); 92NETDEVICE_SHOW(features, fmt_long_hex);
93NETDEVICE_SHOW(type, fmt_dec); 93NETDEVICE_SHOW(type, fmt_dec);
94NETDEVICE_SHOW(link_mode, fmt_dec);
94 95
95/* use same locking rules as GIFHWADDR ioctl's */ 96/* use same locking rules as GIFHWADDR ioctl's */
96static ssize_t format_addr(char *buf, const unsigned char *addr, int len) 97static ssize_t format_addr(char *buf, const unsigned char *addr, int len)
@@ -133,6 +134,43 @@ static ssize_t show_carrier(struct class_device *dev, char *buf)
133 return -EINVAL; 134 return -EINVAL;
134} 135}
135 136
137static ssize_t show_dormant(struct class_device *dev, char *buf)
138{
139 struct net_device *netdev = to_net_dev(dev);
140
141 if (netif_running(netdev))
142 return sprintf(buf, fmt_dec, !!netif_dormant(netdev));
143
144 return -EINVAL;
145}
146
147static const char *operstates[] = {
148 "unknown",
149 "notpresent", /* currently unused */
150 "down",
151 "lowerlayerdown",
152 "testing", /* currently unused */
153 "dormant",
154 "up"
155};
156
157static ssize_t show_operstate(struct class_device *dev, char *buf)
158{
159 const struct net_device *netdev = to_net_dev(dev);
160 unsigned char operstate;
161
162 read_lock(&dev_base_lock);
163 operstate = netdev->operstate;
164 if (!netif_running(netdev))
165 operstate = IF_OPER_DOWN;
166 read_unlock(&dev_base_lock);
167
168 if (operstate >= sizeof(operstates))
169 return -EINVAL; /* should not happen */
170
171 return sprintf(buf, "%s\n", operstates[operstate]);
172}
173
136/* read-write attributes */ 174/* read-write attributes */
137NETDEVICE_SHOW(mtu, fmt_dec); 175NETDEVICE_SHOW(mtu, fmt_dec);
138 176
@@ -190,9 +228,12 @@ static struct class_device_attribute net_class_attributes[] = {
190 __ATTR(ifindex, S_IRUGO, show_ifindex, NULL), 228 __ATTR(ifindex, S_IRUGO, show_ifindex, NULL),
191 __ATTR(features, S_IRUGO, show_features, NULL), 229 __ATTR(features, S_IRUGO, show_features, NULL),
192 __ATTR(type, S_IRUGO, show_type, NULL), 230 __ATTR(type, S_IRUGO, show_type, NULL),
231 __ATTR(link_mode, S_IRUGO, show_link_mode, NULL),
193 __ATTR(address, S_IRUGO, show_address, NULL), 232 __ATTR(address, S_IRUGO, show_address, NULL),
194 __ATTR(broadcast, S_IRUGO, show_broadcast, NULL), 233 __ATTR(broadcast, S_IRUGO, show_broadcast, NULL),
195 __ATTR(carrier, S_IRUGO, show_carrier, NULL), 234 __ATTR(carrier, S_IRUGO, show_carrier, NULL),
235 __ATTR(dormant, S_IRUGO, show_dormant, NULL),
236 __ATTR(operstate, S_IRUGO, show_operstate, NULL),
196 __ATTR(mtu, S_IRUGO | S_IWUSR, show_mtu, store_mtu), 237 __ATTR(mtu, S_IRUGO | S_IWUSR, show_mtu, store_mtu),
197 __ATTR(flags, S_IRUGO | S_IWUSR, show_flags, store_flags), 238 __ATTR(flags, S_IRUGO | S_IWUSR, show_flags, store_flags),
198 __ATTR(tx_queue_len, S_IRUGO | S_IWUSR, show_tx_queue_len, 239 __ATTR(tx_queue_len, S_IRUGO | S_IWUSR, show_tx_queue_len,
diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
index eca2976abb25..1c15a907066f 100644
--- a/net/core/rtnetlink.c
+++ b/net/core/rtnetlink.c
@@ -179,6 +179,33 @@ rtattr_failure:
179} 179}
180 180
181 181
182static void set_operstate(struct net_device *dev, unsigned char transition)
183{
184 unsigned char operstate = dev->operstate;
185
186 switch(transition) {
187 case IF_OPER_UP:
188 if ((operstate == IF_OPER_DORMANT ||
189 operstate == IF_OPER_UNKNOWN) &&
190 !netif_dormant(dev))
191 operstate = IF_OPER_UP;
192 break;
193
194 case IF_OPER_DORMANT:
195 if (operstate == IF_OPER_UP ||
196 operstate == IF_OPER_UNKNOWN)
197 operstate = IF_OPER_DORMANT;
198 break;
199 };
200
201 if (dev->operstate != operstate) {
202 write_lock_bh(&dev_base_lock);
203 dev->operstate = operstate;
204 write_unlock_bh(&dev_base_lock);
205 netdev_state_change(dev);
206 }
207}
208
182static int rtnetlink_fill_ifinfo(struct sk_buff *skb, struct net_device *dev, 209static int rtnetlink_fill_ifinfo(struct sk_buff *skb, struct net_device *dev,
183 int type, u32 pid, u32 seq, u32 change, 210 int type, u32 pid, u32 seq, u32 change,
184 unsigned int flags) 211 unsigned int flags)
@@ -209,6 +236,13 @@ static int rtnetlink_fill_ifinfo(struct sk_buff *skb, struct net_device *dev,
209 } 236 }
210 237
211 if (1) { 238 if (1) {
239 u8 operstate = netif_running(dev)?dev->operstate:IF_OPER_DOWN;
240 u8 link_mode = dev->link_mode;
241 RTA_PUT(skb, IFLA_OPERSTATE, sizeof(operstate), &operstate);
242 RTA_PUT(skb, IFLA_LINKMODE, sizeof(link_mode), &link_mode);
243 }
244
245 if (1) {
212 struct rtnl_link_ifmap map = { 246 struct rtnl_link_ifmap map = {
213 .mem_start = dev->mem_start, 247 .mem_start = dev->mem_start,
214 .mem_end = dev->mem_end, 248 .mem_end = dev->mem_end,
@@ -399,6 +433,22 @@ static int do_setlink(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
399 dev->weight = *((u32 *) RTA_DATA(ida[IFLA_WEIGHT - 1])); 433 dev->weight = *((u32 *) RTA_DATA(ida[IFLA_WEIGHT - 1]));
400 } 434 }
401 435
436 if (ida[IFLA_OPERSTATE - 1]) {
437 if (ida[IFLA_OPERSTATE - 1]->rta_len != RTA_LENGTH(sizeof(u8)))
438 goto out;
439
440 set_operstate(dev, *((u8 *) RTA_DATA(ida[IFLA_OPERSTATE - 1])));
441 }
442
443 if (ida[IFLA_LINKMODE - 1]) {
444 if (ida[IFLA_LINKMODE - 1]->rta_len != RTA_LENGTH(sizeof(u8)))
445 goto out;
446
447 write_lock_bh(&dev_base_lock);
448 dev->link_mode = *((u8 *) RTA_DATA(ida[IFLA_LINKMODE - 1]));
449 write_unlock_bh(&dev_base_lock);
450 }
451
402 if (ifm->ifi_index >= 0 && ida[IFLA_IFNAME - 1]) { 452 if (ifm->ifi_index >= 0 && ida[IFLA_IFNAME - 1]) {
403 char ifname[IFNAMSIZ]; 453 char ifname[IFNAMSIZ];
404 454