Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
L
linux
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
linux
Commits
8a9fd6e0
Commit
8a9fd6e0
authored
May 22, 2002
by
David S. Miller
Browse files
Options
Browse Files
Download
Plain Diff
Merge
http://kernel-acme.bkbits.net:8080/net-cleanups-2.5-core-dev
into nuts.ninka.net:/home/davem/src/BK/net-2.5
parents
0ac5b42d
f8128c1b
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
411 additions
and
403 deletions
+411
-403
net/core/dev.c
net/core/dev.c
+411
-403
No files found.
net/core/dev.c
View file @
8a9fd6e0
...
@@ -20,17 +20,18 @@
...
@@ -20,17 +20,18 @@
* Pekka Riikonen <priikone@poesidon.pspt.fi>
* Pekka Riikonen <priikone@poesidon.pspt.fi>
*
*
* Changes:
* Changes:
* D.J. Barrow : Fixed bug where dev->refcnt gets set
to 2
* D.J. Barrow : Fixed bug where dev->refcnt gets set
*
if register_netdev gets called before
*
to 2 if register_netdev gets called
*
net_dev_init & also removed a few lines
*
before net_dev_init & also removed a
*
of code in the process.
*
few lines
of code in the process.
* Alan Cox : device private ioctl copies fields back.
* Alan Cox : device private ioctl copies fields back.
* Alan Cox : Transmit queue code does relevant
stunts to
* Alan Cox : Transmit queue code does relevant
* keep the queue safe.
*
stunts to
keep the queue safe.
* Alan Cox : Fixed double lock.
* Alan Cox : Fixed double lock.
* Alan Cox : Fixed promisc NULL pointer trap
* Alan Cox : Fixed promisc NULL pointer trap
* ???????? : Support the full private ioctl range
* ???????? : Support the full private ioctl range
* Alan Cox : Moved ioctl permission check into drivers
* Alan Cox : Moved ioctl permission check into
* drivers
* Tim Kordas : SIOCADDMULTI/SIOCDELMULTI
* Tim Kordas : SIOCADDMULTI/SIOCDELMULTI
* Alan Cox : 100 backlog just doesn't cut it when
* Alan Cox : 100 backlog just doesn't cut it when
* you start doing multicast video 8)
* you start doing multicast video 8)
...
@@ -38,16 +39,19 @@
...
@@ -38,16 +39,19 @@
* Alan Cox : Fix ETH_P_ALL echoback lengths.
* Alan Cox : Fix ETH_P_ALL echoback lengths.
* Alan Cox : Took out transmit every packet pass
* Alan Cox : Took out transmit every packet pass
* Saved a few bytes in the ioctl handler
* Saved a few bytes in the ioctl handler
* Alan Cox : Network driver sets packet type before calling netif_rx. Saves
* Alan Cox : Network driver sets packet type before
* a function call a packet.
* calling netif_rx. Saves a function
* call a packet.
* Alan Cox : Hashed net_bh()
* Alan Cox : Hashed net_bh()
* Richard Kooijman: Timestamp fixes.
* Richard Kooijman: Timestamp fixes.
* Alan Cox : Wrong field in SIOCGIFDSTADDR
* Alan Cox : Wrong field in SIOCGIFDSTADDR
* Alan Cox : Device lock protection.
* Alan Cox : Device lock protection.
* Alan Cox : Fixed nasty side effect of device close changes.
* Alan Cox : Fixed nasty side effect of device close
* Rudi Cilibrasi : Pass the right thing to set_mac_address()
* changes.
* Dave Miller : 32bit quantity for the device lock to make it work out
* Rudi Cilibrasi : Pass the right thing to
* on a Sparc.
* set_mac_address()
* Dave Miller : 32bit quantity for the device lock to
* make it work out on a Sparc.
* Bjorn Ekwall : Added KERNELD hack.
* Bjorn Ekwall : Added KERNELD hack.
* Alan Cox : Cleaned up the backlog initialise.
* Alan Cox : Cleaned up the backlog initialise.
* Craig Metz : SIOCGIFCONF fix if space for under
* Craig Metz : SIOCGIFCONF fix if space for under
...
@@ -62,7 +66,8 @@
...
@@ -62,7 +66,8 @@
* the backlog queue.
* the backlog queue.
* Paul Rusty Russell : SIOCSIFNAME
* Paul Rusty Russell : SIOCSIFNAME
* Pekka Riikonen : Netdev boot-time settings code
* Pekka Riikonen : Netdev boot-time settings code
* Andrew Morton : Make unregister_netdevice wait indefinitely on dev->refcnt
* Andrew Morton : Make unregister_netdevice wait
* indefinitely on dev->refcnt
* J Hadi Salim : - Backlog queue sampling
* J Hadi Salim : - Backlog queue sampling
* - netif_rx() feedback
* - netif_rx() feedback
*/
*/
...
@@ -163,7 +168,7 @@ const char *if_port_text[] = {
...
@@ -163,7 +168,7 @@ const char *if_port_text[] = {
*/
*/
static
struct
packet_type
*
ptype_base
[
16
];
/* 16 way hashed list */
static
struct
packet_type
*
ptype_base
[
16
];
/* 16 way hashed list */
static
struct
packet_type
*
ptype_all
=
NULL
;
/* Taps */
static
struct
packet_type
*
ptype_all
;
/* Taps */
#ifdef OFFLINE_SAMPLE
#ifdef OFFLINE_SAMPLE
static
void
sample_queue
(
unsigned
long
dummy
);
static
void
sample_queue
(
unsigned
long
dummy
);
...
@@ -180,7 +185,7 @@ static int net_run_sbin_hotplug(struct net_device *dev, char *action);
...
@@ -180,7 +185,7 @@ static int net_run_sbin_hotplug(struct net_device *dev, char *action);
* Our notifier list
* Our notifier list
*/
*/
static
struct
notifier_block
*
netdev_chain
=
NULL
;
static
struct
notifier_block
*
netdev_chain
;
/*
/*
* Device drivers call our routines to queue packets here. We empty the
* Device drivers call our routines to queue packets here. We empty the
...
@@ -194,17 +199,17 @@ int netdev_fastroute_obstacles;
...
@@ -194,17 +199,17 @@ int netdev_fastroute_obstacles;
#endif
#endif
/*******************************************************************************
***********
/*******************************************************************************
Protocol management and registration routines
Protocol management and registration routines
*******************************************************************************
************
/
*******************************************************************************/
/*
/*
* For efficiency
* For efficiency
*/
*/
int
netdev_nit
=
0
;
int
netdev_nit
;
/*
/*
* Add a protocol ID to the list. Now that the input handler is
* Add a protocol ID to the list. Now that the input handler is
...
@@ -239,17 +244,17 @@ void dev_add_pack(struct packet_type *pt)
...
@@ -239,17 +244,17 @@ void dev_add_pack(struct packet_type *pt)
#ifdef CONFIG_NET_FASTROUTE
#ifdef CONFIG_NET_FASTROUTE
/* Hack to detect packet socket */
/* Hack to detect packet socket */
if
(
(
pt
->
data
)
&&
((
int
)(
pt
->
data
)
!=
1
)
)
{
if
(
pt
->
data
&&
(
int
)(
pt
->
data
)
!=
1
)
{
netdev_fastroute_obstacles
++
;
netdev_fastroute_obstacles
++
;
dev_clear_fastroute
(
pt
->
dev
);
dev_clear_fastroute
(
pt
->
dev
);
}
}
#endif
#endif
if
(
pt
->
type
==
htons
(
ETH_P_ALL
))
{
if
(
pt
->
type
==
htons
(
ETH_P_ALL
))
{
netdev_nit
++
;
netdev_nit
++
;
pt
->
next
=
ptype_all
;
pt
->
next
=
ptype_all
;
ptype_all
=
pt
;
ptype_all
=
pt
;
}
else
{
}
else
{
hash
=
ntohs
(
pt
->
type
)
&
15
;
hash
=
ntohs
(
pt
->
type
)
&
15
;
pt
->
next
=
ptype_base
[
hash
];
pt
->
next
=
ptype_base
[
hash
];
ptype_base
[
hash
]
=
pt
;
ptype_base
[
hash
]
=
pt
;
}
}
...
@@ -266,7 +271,6 @@ void dev_add_pack(struct packet_type *pt)
...
@@ -266,7 +271,6 @@ void dev_add_pack(struct packet_type *pt)
* from the kernel lists and can be freed or reused once this function
* from the kernel lists and can be freed or reused once this function
* returns.
* returns.
*/
*/
void
dev_remove_pack
(
struct
packet_type
*
pt
)
void
dev_remove_pack
(
struct
packet_type
*
pt
)
{
{
struct
packet_type
**
pt1
;
struct
packet_type
**
pt1
;
...
@@ -275,24 +279,23 @@ void dev_remove_pack(struct packet_type *pt)
...
@@ -275,24 +279,23 @@ void dev_remove_pack(struct packet_type *pt)
if
(
pt
->
type
==
htons
(
ETH_P_ALL
))
{
if
(
pt
->
type
==
htons
(
ETH_P_ALL
))
{
netdev_nit
--
;
netdev_nit
--
;
pt1
=&
ptype_all
;
pt1
=
&
ptype_all
;
}
else
{
}
else
pt1
=&
ptype_base
[
ntohs
(
pt
->
type
)
&
15
];
pt1
=
&
ptype_base
[
ntohs
(
pt
->
type
)
&
15
];
}
for
(;
(
*
pt1
)
!=
NULL
;
pt1
=
&
((
*
pt1
)
->
next
))
{
for
(;
*
pt1
;
pt1
=
&
((
*
pt1
)
->
next
))
{
if
(
pt
==
(
*
pt1
)
)
{
if
(
pt
==
*
pt1
)
{
*
pt1
=
pt
->
next
;
*
pt1
=
pt
->
next
;
#ifdef CONFIG_NET_FASTROUTE
#ifdef CONFIG_NET_FASTROUTE
if
(
pt
->
data
)
if
(
pt
->
data
)
netdev_fastroute_obstacles
--
;
netdev_fastroute_obstacles
--
;
#endif
#endif
br_write_unlock_bh
(
BR_NETPROTO_LOCK
);
goto
out
;
return
;
}
}
}
}
br_write_unlock_bh
(
BR_NETPROTO_LOCK
);
printk
(
KERN_WARNING
"dev_remove_pack: %p not found.
\n
"
,
pt
);
printk
(
KERN_WARNING
"dev_remove_pack: %p not found.
\n
"
,
pt
);
out:
br_write_unlock_bh
(
BR_NETPROTO_LOCK
);
}
}
/******************************************************************************
/******************************************************************************
...
@@ -328,10 +331,7 @@ int netdev_boot_setup_add(char *name, struct ifmap *map)
...
@@ -328,10 +331,7 @@ int netdev_boot_setup_add(char *name, struct ifmap *map)
}
}
}
}
if
(
i
>=
NETDEV_BOOT_SETUP_MAX
)
return
i
>=
NETDEV_BOOT_SETUP_MAX
?
0
:
1
;
return
0
;
return
1
;
}
}
/**
/**
...
@@ -345,10 +345,9 @@ int netdev_boot_setup_add(char *name, struct ifmap *map)
...
@@ -345,10 +345,9 @@ int netdev_boot_setup_add(char *name, struct ifmap *map)
*/
*/
int
netdev_boot_setup_check
(
struct
net_device
*
dev
)
int
netdev_boot_setup_check
(
struct
net_device
*
dev
)
{
{
struct
netdev_boot_setup
*
s
;
struct
netdev_boot_setup
*
s
=
dev_boot_setup
;
int
i
;
int
i
;
s
=
dev_boot_setup
;
for
(
i
=
0
;
i
<
NETDEV_BOOT_SETUP_MAX
;
i
++
)
{
for
(
i
=
0
;
i
<
NETDEV_BOOT_SETUP_MAX
;
i
++
)
{
if
(
s
[
i
].
name
[
0
]
!=
'\0'
&&
s
[
i
].
name
[
0
]
!=
' '
&&
if
(
s
[
i
].
name
[
0
]
!=
'\0'
&&
s
[
i
].
name
[
0
]
!=
' '
&&
!
strncmp
(
dev
->
name
,
s
[
i
].
name
,
strlen
(
s
[
i
].
name
)))
{
!
strncmp
(
dev
->
name
,
s
[
i
].
name
,
strlen
(
s
[
i
].
name
)))
{
...
@@ -391,11 +390,11 @@ int __init netdev_boot_setup(char *str)
...
@@ -391,11 +390,11 @@ int __init netdev_boot_setup(char *str)
__setup
(
"netdev="
,
netdev_boot_setup
);
__setup
(
"netdev="
,
netdev_boot_setup
);
/*******************************************************************************
**********
/*******************************************************************************
Device Interface Subroutines
Device Interface Subroutines
*******************************************************************************
***********
/
*******************************************************************************/
/**
/**
* __dev_get_by_name - find a device by its name
* __dev_get_by_name - find a device by its name
...
@@ -408,16 +407,14 @@ __setup("netdev=", netdev_boot_setup);
...
@@ -408,16 +407,14 @@ __setup("netdev=", netdev_boot_setup);
* careful with locks.
* careful with locks.
*/
*/
struct
net_device
*
__dev_get_by_name
(
const
char
*
name
)
struct
net_device
*
__dev_get_by_name
(
const
char
*
name
)
{
{
struct
net_device
*
dev
;
struct
net_device
*
dev
;
for
(
dev
=
dev_base
;
dev
!=
NULL
;
dev
=
dev
->
next
)
{
for
(
dev
=
dev_base
;
dev
;
dev
=
dev
->
next
)
if
(
strncmp
(
dev
->
name
,
name
,
IFNAMSIZ
)
==
0
)
if
(
!
strncmp
(
dev
->
name
,
name
,
IFNAMSIZ
))
break
;
return
dev
;
return
dev
;
}
return
NULL
;
}
}
/**
/**
...
@@ -462,7 +459,6 @@ struct net_device *dev_get_by_name(const char *name)
...
@@ -462,7 +459,6 @@ struct net_device *dev_get_by_name(const char *name)
* This function primarily exists for back compatibility with older
* This function primarily exists for back compatibility with older
* drivers.
* drivers.
*/
*/
int
dev_get
(
const
char
*
name
)
int
dev_get
(
const
char
*
name
)
{
{
struct
net_device
*
dev
;
struct
net_device
*
dev
;
...
@@ -484,15 +480,14 @@ int dev_get(const char *name)
...
@@ -484,15 +480,14 @@ int dev_get(const char *name)
* or @dev_base_lock.
* or @dev_base_lock.
*/
*/
struct
net_device
*
__dev_get_by_index
(
int
ifindex
)
struct
net_device
*
__dev_get_by_index
(
int
ifindex
)
{
{
struct
net_device
*
dev
;
struct
net_device
*
dev
;
for
(
dev
=
dev_base
;
dev
!=
NULL
;
dev
=
dev
->
next
)
{
for
(
dev
=
dev_base
;
dev
;
dev
=
dev
->
next
)
if
(
dev
->
ifindex
==
ifindex
)
if
(
dev
->
ifindex
==
ifindex
)
break
;
return
dev
;
return
dev
;
}
return
NULL
;
}
}
...
@@ -506,7 +501,7 @@ struct net_device * __dev_get_by_index(int ifindex)
...
@@ -506,7 +501,7 @@ struct net_device * __dev_get_by_index(int ifindex)
* dev_put to indicate they have finished with it.
* dev_put to indicate they have finished with it.
*/
*/
struct
net_device
*
dev_get_by_index
(
int
ifindex
)
struct
net_device
*
dev_get_by_index
(
int
ifindex
)
{
{
struct
net_device
*
dev
;
struct
net_device
*
dev
;
...
@@ -538,12 +533,11 @@ struct net_device *dev_getbyhwaddr(unsigned short type, char *ha)
...
@@ -538,12 +533,11 @@ struct net_device *dev_getbyhwaddr(unsigned short type, char *ha)
ASSERT_RTNL
();
ASSERT_RTNL
();
for
(
dev
=
dev_base
;
dev
!=
NULL
;
dev
=
dev
->
next
)
{
for
(
dev
=
dev_base
;
dev
;
dev
=
dev
->
next
)
if
(
dev
->
type
==
type
&&
if
(
dev
->
type
==
type
&&
memcmp
(
dev
->
dev_addr
,
ha
,
dev
->
addr_len
)
==
0
)
!
memcmp
(
dev
->
dev_addr
,
ha
,
dev
->
addr_len
))
break
;
return
dev
;
return
dev
;
}
return
NULL
;
}
}
/**
/**
...
@@ -570,15 +564,15 @@ int dev_alloc_name(struct net_device *dev, const char *name)
...
@@ -570,15 +564,15 @@ int dev_alloc_name(struct net_device *dev, const char *name)
* characters, or no "%" characters at all.
* characters, or no "%" characters at all.
*/
*/
p
=
strchr
(
name
,
'%'
);
p
=
strchr
(
name
,
'%'
);
if
(
p
&&
(
p
[
1
]
!=
'd'
||
strchr
(
p
+
2
,
'%'
)))
if
(
p
&&
(
p
[
1
]
!=
'd'
||
strchr
(
p
+
2
,
'%'
)))
return
-
EINVAL
;
return
-
EINVAL
;
/*
/*
* If you need over 100 please also fix the algorithm...
* If you need over 100 please also fix the algorithm...
*/
*/
for
(
i
=
0
;
i
<
100
;
i
++
)
{
for
(
i
=
0
;
i
<
100
;
i
++
)
{
snprintf
(
buf
,
sizeof
(
buf
),
name
,
i
);
snprintf
(
buf
,
sizeof
(
buf
),
name
,
i
);
if
(
__dev_get_by_name
(
buf
)
==
NULL
)
{
if
(
!
__dev_get_by_name
(
buf
)
)
{
strcpy
(
dev
->
name
,
buf
);
strcpy
(
dev
->
name
,
buf
);
return
i
;
return
i
;
}
}
...
@@ -604,16 +598,17 @@ int dev_alloc_name(struct net_device *dev, const char *name)
...
@@ -604,16 +598,17 @@ int dev_alloc_name(struct net_device *dev, const char *name)
struct
net_device
*
dev_alloc
(
const
char
*
name
,
int
*
err
)
struct
net_device
*
dev_alloc
(
const
char
*
name
,
int
*
err
)
{
{
struct
net_device
*
dev
=
kmalloc
(
sizeof
(
struct
net_device
),
GFP_KERNEL
);
struct
net_device
*
dev
=
kmalloc
(
sizeof
(
*
dev
),
GFP_KERNEL
);
if
(
dev
==
NULL
)
{
if
(
!
dev
)
*
err
=
-
ENOBUFS
;
*
err
=
-
ENOBUFS
;
return
NULL
;
else
{
}
memset
(
dev
,
0
,
sizeof
(
*
dev
));
memset
(
dev
,
0
,
sizeof
(
struct
net_device
));
*
err
=
dev_alloc_name
(
dev
,
name
);
*
err
=
dev_alloc_name
(
dev
,
name
);
if
(
*
err
<
0
)
{
if
(
*
err
<
0
)
{
kfree
(
dev
);
kfree
(
dev
);
return
NULL
;
dev
=
NULL
;
}
}
}
return
dev
;
return
dev
;
}
}
...
@@ -626,10 +621,9 @@ struct net_device *dev_alloc(const char *name, int *err)
...
@@ -626,10 +621,9 @@ struct net_device *dev_alloc(const char *name, int *err)
* the notifier chains for netdev_chain and sends a NEWLINK message
* the notifier chains for netdev_chain and sends a NEWLINK message
* to the routing socket.
* to the routing socket.
*/
*/
void
netdev_state_change
(
struct
net_device
*
dev
)
void
netdev_state_change
(
struct
net_device
*
dev
)
{
{
if
(
dev
->
flags
&
IFF_UP
)
{
if
(
dev
->
flags
&
IFF_UP
)
{
notifier_call_chain
(
&
netdev_chain
,
NETDEV_CHANGE
,
dev
);
notifier_call_chain
(
&
netdev_chain
,
NETDEV_CHANGE
,
dev
);
rtmsg_ifinfo
(
RTM_NEWLINK
,
dev
,
0
);
rtmsg_ifinfo
(
RTM_NEWLINK
,
dev
,
0
);
}
}
...
@@ -661,7 +655,8 @@ extern inline void dev_load(const char *unused){;}
...
@@ -661,7 +655,8 @@ extern inline void dev_load(const char *unused){;}
static
int
default_rebuild_header
(
struct
sk_buff
*
skb
)
static
int
default_rebuild_header
(
struct
sk_buff
*
skb
)
{
{
printk
(
KERN_DEBUG
"%s: default_rebuild_header called -- BUG!
\n
"
,
skb
->
dev
?
skb
->
dev
->
name
:
"NULL!!!"
);
printk
(
KERN_DEBUG
"%s: default_rebuild_header called -- BUG!
\n
"
,
skb
->
dev
?
skb
->
dev
->
name
:
"NULL!!!"
);
kfree_skb
(
skb
);
kfree_skb
(
skb
);
return
1
;
return
1
;
}
}
...
@@ -678,7 +673,6 @@ static int default_rebuild_header(struct sk_buff *skb)
...
@@ -678,7 +673,6 @@ static int default_rebuild_header(struct sk_buff *skb)
* Calling this function on an active interface is a nop. On a failure
* Calling this function on an active interface is a nop. On a failure
* a negative errno code is returned.
* a negative errno code is returned.
*/
*/
int
dev_open
(
struct
net_device
*
dev
)
int
dev_open
(
struct
net_device
*
dev
)
{
{
int
ret
=
0
;
int
ret
=
0
;
...
@@ -687,7 +681,7 @@ int dev_open(struct net_device *dev)
...
@@ -687,7 +681,7 @@ int dev_open(struct net_device *dev)
* Is it already up?
* Is it already up?
*/
*/
if
(
dev
->
flags
&
IFF_UP
)
if
(
dev
->
flags
&
IFF_UP
)
return
0
;
return
0
;
/*
/*
...
@@ -702,7 +696,7 @@ int dev_open(struct net_device *dev)
...
@@ -702,7 +696,7 @@ int dev_open(struct net_device *dev)
if
(
try_inc_mod_count
(
dev
->
owner
))
{
if
(
try_inc_mod_count
(
dev
->
owner
))
{
if
(
dev
->
open
)
{
if
(
dev
->
open
)
{
ret
=
dev
->
open
(
dev
);
ret
=
dev
->
open
(
dev
);
if
(
ret
!=
0
&&
dev
->
owner
)
if
(
ret
&&
dev
->
owner
)
__MOD_DEC_USE_COUNT
(
dev
->
owner
);
__MOD_DEC_USE_COUNT
(
dev
->
owner
);
}
}
}
else
{
}
else
{
...
@@ -713,8 +707,7 @@ int dev_open(struct net_device *dev)
...
@@ -713,8 +707,7 @@ int dev_open(struct net_device *dev)
* If it went open OK then:
* If it went open OK then:
*/
*/
if
(
ret
==
0
)
if
(
!
ret
)
{
{
/*
/*
* Set the flags.
* Set the flags.
*/
*/
...
@@ -737,7 +730,7 @@ int dev_open(struct net_device *dev)
...
@@ -737,7 +730,7 @@ int dev_open(struct net_device *dev)
*/
*/
notifier_call_chain
(
&
netdev_chain
,
NETDEV_UP
,
dev
);
notifier_call_chain
(
&
netdev_chain
,
NETDEV_UP
,
dev
);
}
}
return
(
ret
)
;
return
ret
;
}
}
#ifdef CONFIG_NET_FASTROUTE
#ifdef CONFIG_NET_FASTROUTE
...
@@ -747,7 +740,7 @@ static void dev_do_clear_fastroute(struct net_device *dev)
...
@@ -747,7 +740,7 @@ static void dev_do_clear_fastroute(struct net_device *dev)
if
(
dev
->
accept_fastpath
)
{
if
(
dev
->
accept_fastpath
)
{
int
i
;
int
i
;
for
(
i
=
0
;
i
<=
NETDEV_FASTROUTE_HMASK
;
i
++
)
{
for
(
i
=
0
;
i
<=
NETDEV_FASTROUTE_HMASK
;
i
++
)
{
struct
dst_entry
*
dst
;
struct
dst_entry
*
dst
;
write_lock_irq
(
&
dev
->
fastpath_lock
);
write_lock_irq
(
&
dev
->
fastpath_lock
);
...
@@ -782,10 +775,9 @@ void dev_clear_fastroute(struct net_device *dev)
...
@@ -782,10 +775,9 @@ void dev_clear_fastroute(struct net_device *dev)
* is then deactivated and finally a %NETDEV_DOWN is sent to the notifier
* is then deactivated and finally a %NETDEV_DOWN is sent to the notifier
* chain.
* chain.
*/
*/
int
dev_close
(
struct
net_device
*
dev
)
int
dev_close
(
struct
net_device
*
dev
)
{
{
if
(
!
(
dev
->
flags
&
IFF_UP
))
if
(
!
(
dev
->
flags
&
IFF_UP
))
return
0
;
return
0
;
/*
/*
...
@@ -818,7 +810,6 @@ int dev_close(struct net_device *dev)
...
@@ -818,7 +810,6 @@ int dev_close(struct net_device *dev)
* We allow it to be called even after a DETACH hot-plug
* We allow it to be called even after a DETACH hot-plug
* event.
* event.
*/
*/
if
(
dev
->
stop
)
if
(
dev
->
stop
)
dev
->
stop
(
dev
);
dev
->
stop
(
dev
);
...
@@ -842,7 +833,7 @@ int dev_close(struct net_device *dev)
...
@@ -842,7 +833,7 @@ int dev_close(struct net_device *dev)
if
(
dev
->
owner
)
if
(
dev
->
owner
)
__MOD_DEC_USE_COUNT
(
dev
->
owner
);
__MOD_DEC_USE_COUNT
(
dev
->
owner
);
return
(
0
)
;
return
0
;
}
}
...
@@ -878,7 +869,7 @@ int register_netdevice_notifier(struct notifier_block *nb)
...
@@ -878,7 +869,7 @@ int register_netdevice_notifier(struct notifier_block *nb)
int
unregister_netdevice_notifier
(
struct
notifier_block
*
nb
)
int
unregister_netdevice_notifier
(
struct
notifier_block
*
nb
)
{
{
return
notifier_chain_unregister
(
&
netdev_chain
,
nb
);
return
notifier_chain_unregister
(
&
netdev_chain
,
nb
);
}
}
/*
/*
...
@@ -892,16 +883,14 @@ void dev_queue_xmit_nit(struct sk_buff *skb, struct net_device *dev)
...
@@ -892,16 +883,14 @@ void dev_queue_xmit_nit(struct sk_buff *skb, struct net_device *dev)
do_gettimeofday
(
&
skb
->
stamp
);
do_gettimeofday
(
&
skb
->
stamp
);
br_read_lock
(
BR_NETPROTO_LOCK
);
br_read_lock
(
BR_NETPROTO_LOCK
);
for
(
ptype
=
ptype_all
;
ptype
!=
NULL
;
ptype
=
ptype
->
next
)
for
(
ptype
=
ptype_all
;
ptype
;
ptype
=
ptype
->
next
)
{
{
/* Never send packets back to the socket
/* Never send packets back to the socket
* they originated from - MvS (miquels@drinkel.ow.org)
* they originated from - MvS (miquels@drinkel.ow.org)
*/
*/
if
((
ptype
->
dev
==
dev
||
!
ptype
->
dev
)
&&
if
((
ptype
->
dev
==
dev
||
!
ptype
->
dev
)
&&
((
struct
sock
*
)
ptype
->
data
!=
skb
->
sk
))
(
struct
sock
*
)
ptype
->
data
!=
skb
->
sk
)
{
{
struct
sk_buff
*
skb2
=
skb_clone
(
skb
,
GFP_ATOMIC
);
struct
sk_buff
*
skb2
;
if
(
!
skb2
)
if
((
skb2
=
skb_clone
(
skb
,
GFP_ATOMIC
))
==
NULL
)
break
;
break
;
/* skb->nh should be correctly
/* skb->nh should be correctly
...
@@ -910,9 +899,12 @@ void dev_queue_xmit_nit(struct sk_buff *skb, struct net_device *dev)
...
@@ -910,9 +899,12 @@ void dev_queue_xmit_nit(struct sk_buff *skb, struct net_device *dev)
*/
*/
skb2
->
mac
.
raw
=
skb2
->
data
;
skb2
->
mac
.
raw
=
skb2
->
data
;
if
(
skb2
->
nh
.
raw
<
skb2
->
data
||
skb2
->
nh
.
raw
>
skb2
->
tail
)
{
if
(
skb2
->
nh
.
raw
<
skb2
->
data
||
skb2
->
nh
.
raw
>
skb2
->
tail
)
{
if
(
net_ratelimit
())
if
(
net_ratelimit
())
printk
(
KERN_DEBUG
"protocol %04x is buggy, dev %s
\n
"
,
skb2
->
protocol
,
dev
->
name
);
printk
(
KERN_DEBUG
"protocol %04x is "
"buggy, dev %s
\n
"
,
skb2
->
protocol
,
dev
->
name
);
skb2
->
nh
.
raw
=
skb2
->
data
;
skb2
->
nh
.
raw
=
skb2
->
data
;
}
}
...
@@ -928,12 +920,11 @@ void dev_queue_xmit_nit(struct sk_buff *skb, struct net_device *dev)
...
@@ -928,12 +920,11 @@ void dev_queue_xmit_nit(struct sk_buff *skb, struct net_device *dev)
* If it failed by some reason, ignore and send skb with wrong
* If it failed by some reason, ignore and send skb with wrong
* checksum.
* checksum.
*/
*/
struct
sk_buff
*
skb_checksum_help
(
struct
sk_buff
*
skb
)
struct
sk_buff
*
skb_checksum_help
(
struct
sk_buff
*
skb
)
{
{
int
offset
;
unsigned
int
csum
;
unsigned
int
csum
;
int
offset
=
skb
->
h
.
raw
-
skb
->
data
;
offset
=
skb
->
h
.
raw
-
skb
->
data
;
if
(
offset
>
(
int
)
skb
->
len
)
if
(
offset
>
(
int
)
skb
->
len
)
BUG
();
BUG
();
csum
=
skb_checksum
(
skb
,
offset
,
skb
->
len
-
offset
,
0
);
csum
=
skb_checksum
(
skb
,
offset
,
skb
->
len
-
offset
,
0
);
...
@@ -941,7 +932,7 @@ struct sk_buff * skb_checksum_help(struct sk_buff *skb)
...
@@ -941,7 +932,7 @@ struct sk_buff * skb_checksum_help(struct sk_buff *skb)
offset
=
skb
->
tail
-
skb
->
h
.
raw
;
offset
=
skb
->
tail
-
skb
->
h
.
raw
;
if
(
offset
<=
0
)
if
(
offset
<=
0
)
BUG
();
BUG
();
if
(
skb
->
csum
+
2
>
offset
)
if
(
skb
->
csum
+
2
>
offset
)
BUG
();
BUG
();
*
(
u16
*
)(
skb
->
h
.
raw
+
skb
->
csum
)
=
csum_fold
(
csum
);
*
(
u16
*
)(
skb
->
h
.
raw
+
skb
->
csum
)
=
csum_fold
(
csum
);
...
@@ -955,15 +946,14 @@ struct sk_buff * skb_checksum_help(struct sk_buff *skb)
...
@@ -955,15 +946,14 @@ struct sk_buff * skb_checksum_help(struct sk_buff *skb)
* 2. No high memory really exists on this machine.
* 2. No high memory really exists on this machine.
*/
*/
static
inline
int
static
inline
int
illegal_highdma
(
struct
net_device
*
dev
,
struct
sk_buff
*
skb
)
illegal_highdma
(
struct
net_device
*
dev
,
struct
sk_buff
*
skb
)
{
{
int
i
;
int
i
;
if
(
dev
->
features
&
NETIF_F_HIGHDMA
)
if
(
dev
->
features
&
NETIF_F_HIGHDMA
)
return
0
;
return
0
;
for
(
i
=
0
;
i
<
skb_shinfo
(
skb
)
->
nr_frags
;
i
++
)
for
(
i
=
0
;
i
<
skb_shinfo
(
skb
)
->
nr_frags
;
i
++
)
if
(
skb_shinfo
(
skb
)
->
frags
[
i
].
page
>=
highmem_start_page
)
if
(
skb_shinfo
(
skb
)
->
frags
[
i
].
page
>=
highmem_start_page
)
return
1
;
return
1
;
...
@@ -978,8 +968,8 @@ illegal_highdma(struct net_device *dev, struct sk_buff *skb)
...
@@ -978,8 +968,8 @@ illegal_highdma(struct net_device *dev, struct sk_buff *skb)
* @skb: buffer to transmit
* @skb: buffer to transmit
*
*
* Queue a buffer for transmission to a network device. The caller must
* Queue a buffer for transmission to a network device. The caller must
* have set the device and priority and built the buffer before calling
this
* have set the device and priority and built the buffer before calling
* function. The function can be called from an interrupt.
*
this
function. The function can be called from an interrupt.
*
*
* A negative errno code is returned on a failure. A success does not
* A negative errno code is returned on a failure. A success does not
* guarantee the frame will be transmitted as it may be dropped due
* guarantee the frame will be transmitted as it may be dropped due
...
@@ -990,60 +980,59 @@ int dev_queue_xmit(struct sk_buff *skb)
...
@@ -990,60 +980,59 @@ int dev_queue_xmit(struct sk_buff *skb)
{
{
struct
net_device
*
dev
=
skb
->
dev
;
struct
net_device
*
dev
=
skb
->
dev
;
struct
Qdisc
*
q
;
struct
Qdisc
*
q
;
int
rc
=
-
ENOMEM
;
if
(
skb_shinfo
(
skb
)
->
frag_list
&&
if
(
skb_shinfo
(
skb
)
->
frag_list
&&
!
(
dev
->
features
&
NETIF_F_FRAGLIST
)
&&
!
(
dev
->
features
&
NETIF_F_FRAGLIST
)
&&
skb_linearize
(
skb
,
GFP_ATOMIC
)
!=
0
)
{
skb_linearize
(
skb
,
GFP_ATOMIC
))
kfree_skb
(
skb
);
goto
out_kfree_skb
;
return
-
ENOMEM
;
}
/* Fragmented skb is linearized if device does not support SG,
/* Fragmented skb is linearized if device does not support SG,
* or if at least one of fragments is in highmem and device
* or if at least one of fragments is in highmem and device
* does not support DMA from it.
* does not support DMA from it.
*/
*/
if
(
skb_shinfo
(
skb
)
->
nr_frags
&&
if
(
skb_shinfo
(
skb
)
->
nr_frags
&&
(
!
(
dev
->
features
&
NETIF_F_SG
)
||
illegal_highdma
(
dev
,
skb
))
&&
(
!
(
dev
->
features
&
NETIF_F_SG
)
||
illegal_highdma
(
dev
,
skb
))
&&
skb_linearize
(
skb
,
GFP_ATOMIC
)
!=
0
)
{
skb_linearize
(
skb
,
GFP_ATOMIC
))
kfree_skb
(
skb
);
goto
out_kfree_skb
;
return
-
ENOMEM
;
}
/* If packet is not checksummed and device does not support
/* If packet is not checksummed and device does not support
* checksumming for this protocol, complete checksumming here.
* checksumming for this protocol, complete checksumming here.
*/
*/
if
(
skb
->
ip_summed
==
CHECKSUM_HW
&&
if
(
skb
->
ip_summed
==
CHECKSUM_HW
&&
(
!
(
dev
->
features
&
(
NETIF_F_HW_CSUM
|
NETIF_F_NO_CSUM
))
&&
(
!
(
dev
->
features
&
(
NETIF_F_HW_CSUM
|
NETIF_F_NO_CSUM
))
&&
(
!
(
dev
->
features
&
NETIF_F_IP_CSUM
)
||
(
!
(
dev
->
features
&
NETIF_F_IP_CSUM
)
||
skb
->
protocol
!=
htons
(
ETH_P_IP
))))
{
skb
->
protocol
!=
htons
(
ETH_P_IP
))))
{
if
((
skb
=
skb_checksum_help
(
skb
))
==
NULL
)
if
((
skb
=
skb_checksum_help
(
skb
))
==
NULL
)
return
-
ENOMEM
;
goto
out
;
}
}
/* Grab device queue */
/* Grab device queue */
spin_lock_bh
(
&
dev
->
queue_lock
);
spin_lock_bh
(
&
dev
->
queue_lock
);
q
=
dev
->
qdisc
;
q
=
dev
->
qdisc
;
if
(
q
->
enqueue
)
{
if
(
q
->
enqueue
)
{
int
ret
=
q
->
enqueue
(
skb
,
q
);
rc
=
q
->
enqueue
(
skb
,
q
);
qdisc_run
(
dev
);
qdisc_run
(
dev
);
spin_unlock_bh
(
&
dev
->
queue_lock
);
spin_unlock_bh
(
&
dev
->
queue_lock
);
return
ret
==
NET_XMIT_BYPASS
?
NET_XMIT_SUCCESS
:
ret
;
rc
=
rc
==
NET_XMIT_BYPASS
?
NET_XMIT_SUCCESS
:
rc
;
goto
out
;
}
}
/* The device has no queue. Common case for software devices:
/* The device has no queue. Common case for software devices:
loopback, all the sorts of tunnels...
loopback, all the sorts of tunnels...
Really, it is unlikely that xmit_lock protection is necessary here.
Really, it is unlikely that xmit_lock protection is necessary here.
(f.e. loopback and IP tunnels are clean ignoring statistics counters.)
(f.e. loopback and IP tunnels are clean ignoring statistics
counters.)
However, it is possible, that they rely on protection
However, it is possible, that they rely on protection
made by us here.
made by us here.
Check this and shot the lock. It is not prone from deadlocks.
Check this and shot the lock. It is not prone from deadlocks.
Either shot noqueue qdisc, it is even simpler 8)
Either shot noqueue qdisc, it is even simpler 8)
*/
*/
if
(
dev
->
flags
&
IFF_UP
)
{
if
(
dev
->
flags
&
IFF_UP
)
{
int
cpu
=
smp_processor_id
();
int
cpu
=
smp_processor_id
();
if
(
dev
->
xmit_lock_owner
!=
cpu
)
{
if
(
dev
->
xmit_lock_owner
!=
cpu
)
{
...
@@ -1053,30 +1042,36 @@ int dev_queue_xmit(struct sk_buff *skb)
...
@@ -1053,30 +1042,36 @@ int dev_queue_xmit(struct sk_buff *skb)
if
(
!
netif_queue_stopped
(
dev
))
{
if
(
!
netif_queue_stopped
(
dev
))
{
if
(
netdev_nit
)
if
(
netdev_nit
)
dev_queue_xmit_nit
(
skb
,
dev
);
dev_queue_xmit_nit
(
skb
,
dev
);
if
(
dev
->
hard_start_xmit
(
skb
,
dev
)
==
0
)
{
rc
=
0
;
if
(
!
dev
->
hard_start_xmit
(
skb
,
dev
))
{
dev
->
xmit_lock_owner
=
-
1
;
dev
->
xmit_lock_owner
=
-
1
;
spin_unlock_bh
(
&
dev
->
xmit_lock
);
spin_unlock_bh
(
&
dev
->
xmit_lock
);
return
0
;
goto
out
;
}
}
}
}
dev
->
xmit_lock_owner
=
-
1
;
dev
->
xmit_lock_owner
=
-
1
;
spin_unlock_bh
(
&
dev
->
xmit_lock
);
spin_unlock_bh
(
&
dev
->
xmit_lock
);
if
(
net_ratelimit
())
if
(
net_ratelimit
())
printk
(
KERN_DEBUG
"Virtual device %s asks to
queue packet!
\n
"
,
dev
->
name
);
printk
(
KERN_DEBUG
"Virtual device %s asks to
"
kfree_skb
(
skb
);
"queue packet!
\n
"
,
dev
->
name
);
return
-
ENETDOWN
;
goto
out_enetdown
;
}
else
{
}
else
{
/* Recursion is detected! It is possible, unfortunately */
/* Recursion is detected! It is possible,
* unfortunately */
if
(
net_ratelimit
())
if
(
net_ratelimit
())
printk
(
KERN_DEBUG
"Dead loop on virtual device %s, fix it urgently!
\n
"
,
dev
->
name
);
printk
(
KERN_DEBUG
"Dead loop on virtual device "
"%s, fix it urgently!
\n
"
,
dev
->
name
);
}
}
}
}
spin_unlock_bh
(
&
dev
->
queue_lock
);
spin_unlock_bh
(
&
dev
->
queue_lock
);
out_enetdown:
rc
=
-
ENETDOWN
;
out_kfree_skb:
kfree_skb
(
skb
);
kfree_skb
(
skb
);
return
-
ENETDOWN
;
out:
return
rc
;
}
}
...
@@ -1101,7 +1096,7 @@ struct netif_rx_stats netdev_rx_stat[NR_CPUS];
...
@@ -1101,7 +1096,7 @@ struct netif_rx_stats netdev_rx_stat[NR_CPUS];
#ifdef CONFIG_NET_HW_FLOWCONTROL
#ifdef CONFIG_NET_HW_FLOWCONTROL
atomic_t
netdev_dropping
=
ATOMIC_INIT
(
0
);
atomic_t
netdev_dropping
=
ATOMIC_INIT
(
0
);
static
unsigned
long
netdev_fc_mask
=
1
;
static
unsigned
long
netdev_fc_mask
=
1
;
unsigned
long
netdev_fc_xoff
=
0
;
unsigned
long
netdev_fc_xoff
;
spinlock_t
netdev_fc_lock
=
SPIN_LOCK_UNLOCKED
;
spinlock_t
netdev_fc_lock
=
SPIN_LOCK_UNLOCKED
;
static
struct
static
struct
...
@@ -1110,7 +1105,8 @@ static struct
...
@@ -1110,7 +1105,8 @@ static struct
struct
net_device
*
dev
;
struct
net_device
*
dev
;
}
netdev_fc_slots
[
BITS_PER_LONG
];
}
netdev_fc_slots
[
BITS_PER_LONG
];
int
netdev_register_fc
(
struct
net_device
*
dev
,
void
(
*
stimul
)(
struct
net_device
*
dev
))
int
netdev_register_fc
(
struct
net_device
*
dev
,
void
(
*
stimul
)(
struct
net_device
*
dev
))
{
{
int
bit
=
0
;
int
bit
=
0
;
unsigned
long
flags
;
unsigned
long
flags
;
...
@@ -1150,7 +1146,7 @@ static void netdev_wakeup(void)
...
@@ -1150,7 +1146,7 @@ static void netdev_wakeup(void)
netdev_fc_xoff
=
0
;
netdev_fc_xoff
=
0
;
while
(
xoff
)
{
while
(
xoff
)
{
int
i
=
ffz
(
~
xoff
);
int
i
=
ffz
(
~
xoff
);
xoff
&=
~
(
1
<<
i
);
xoff
&=
~
(
1
<<
i
);
netdev_fc_slots
[
i
].
stimul
(
netdev_fc_slots
[
i
].
dev
);
netdev_fc_slots
[
i
].
stimul
(
netdev_fc_slots
[
i
].
dev
);
}
}
spin_unlock
(
&
netdev_fc_lock
);
spin_unlock
(
&
netdev_fc_lock
);
...
@@ -1166,7 +1162,7 @@ static void get_sample_stats(int cpu)
...
@@ -1166,7 +1162,7 @@ static void get_sample_stats(int cpu)
int
blog
=
softnet_data
[
cpu
].
input_pkt_queue
.
qlen
;
int
blog
=
softnet_data
[
cpu
].
input_pkt_queue
.
qlen
;
int
avg_blog
=
softnet_data
[
cpu
].
avg_blog
;
int
avg_blog
=
softnet_data
[
cpu
].
avg_blog
;
avg_blog
=
(
avg_blog
>>
1
)
+
(
blog
>>
1
);
avg_blog
=
(
avg_blog
>>
1
)
+
(
blog
>>
1
);
if
(
avg_blog
>
mod_cong
)
{
if
(
avg_blog
>
mod_cong
)
{
/* Above moderate congestion levels. */
/* Above moderate congestion levels. */
...
@@ -1223,7 +1219,6 @@ static void sample_queue(unsigned long dummy)
...
@@ -1223,7 +1219,6 @@ static void sample_queue(unsigned long dummy)
* NET_RX_CN_HIGH (high congestion)
* NET_RX_CN_HIGH (high congestion)
* NET_RX_DROP (packet was dropped)
* NET_RX_DROP (packet was dropped)
*
*
*
*/
*/
int
netif_rx
(
struct
sk_buff
*
skb
)
int
netif_rx
(
struct
sk_buff
*
skb
)
...
@@ -1232,7 +1227,7 @@ int netif_rx(struct sk_buff *skb)
...
@@ -1232,7 +1227,7 @@ int netif_rx(struct sk_buff *skb)
struct
softnet_data
*
queue
;
struct
softnet_data
*
queue
;
unsigned
long
flags
;
unsigned
long
flags
;
if
(
skb
->
stamp
.
tv_sec
==
0
)
if
(
!
skb
->
stamp
.
tv_sec
)
do_gettimeofday
(
&
skb
->
stamp
);
do_gettimeofday
(
&
skb
->
stamp
);
/* The code is rearranged so that the path is the most
/* The code is rearranged so that the path is the most
...
@@ -1250,7 +1245,7 @@ int netif_rx(struct sk_buff *skb)
...
@@ -1250,7 +1245,7 @@ int netif_rx(struct sk_buff *skb)
enqueue:
enqueue:
dev_hold
(
skb
->
dev
);
dev_hold
(
skb
->
dev
);
__skb_queue_tail
(
&
queue
->
input_pkt_queue
,
skb
);
__skb_queue_tail
(
&
queue
->
input_pkt_queue
,
skb
);
local_irq_restore
(
flags
);
local_irq_restore
(
flags
);
#ifndef OFFLINE_SAMPLE
#ifndef OFFLINE_SAMPLE
get_sample_stats
(
this_cpu
);
get_sample_stats
(
this_cpu
);
...
@@ -1270,7 +1265,7 @@ int netif_rx(struct sk_buff *skb)
...
@@ -1270,7 +1265,7 @@ int netif_rx(struct sk_buff *skb)
goto
enqueue
;
goto
enqueue
;
}
}
if
(
queue
->
throttle
==
0
)
{
if
(
!
queue
->
throttle
)
{
queue
->
throttle
=
1
;
queue
->
throttle
=
1
;
netdev_rx_stat
[
this_cpu
].
throttled
++
;
netdev_rx_stat
[
this_cpu
].
throttled
++
;
#ifdef CONFIG_NET_HW_FLOWCONTROL
#ifdef CONFIG_NET_HW_FLOWCONTROL
...
@@ -1289,21 +1284,19 @@ int netif_rx(struct sk_buff *skb)
...
@@ -1289,21 +1284,19 @@ int netif_rx(struct sk_buff *skb)
/* Deliver skb to an old protocol, which is not threaded well
/* Deliver skb to an old protocol, which is not threaded well
or which do not understand shared skbs.
or which do not understand shared skbs.
*/
*/
static
int
deliver_to_old_ones
(
struct
packet_type
*
pt
,
struct
sk_buff
*
skb
,
int
last
)
static
int
deliver_to_old_ones
(
struct
packet_type
*
pt
,
struct
sk_buff
*
skb
,
int
last
)
{
{
static
spinlock_t
net_bh_lock
=
SPIN_LOCK_UNLOCKED
;
static
spinlock_t
net_bh_lock
=
SPIN_LOCK_UNLOCKED
;
int
ret
=
NET_RX_DROP
;
int
ret
=
NET_RX_DROP
;
if
(
!
last
)
{
if
(
!
last
)
{
skb
=
skb_clone
(
skb
,
GFP_ATOMIC
);
skb
=
skb_clone
(
skb
,
GFP_ATOMIC
);
if
(
skb
==
NULL
)
if
(
!
skb
)
return
ret
;
goto
out
;
}
if
(
skb_is_nonlinear
(
skb
)
&&
skb_linearize
(
skb
,
GFP_ATOMIC
)
!=
0
)
{
kfree_skb
(
skb
);
return
ret
;
}
}
if
(
skb_is_nonlinear
(
skb
)
&&
skb_linearize
(
skb
,
GFP_ATOMIC
))
goto
out_kfree
;
/* The assumption (correct one) is that old protocols
/* The assumption (correct one) is that old protocols
did not depened on BHs different of NET_BH and TIMER_BH.
did not depened on BHs different of NET_BH and TIMER_BH.
...
@@ -1319,7 +1312,11 @@ static int deliver_to_old_ones(struct packet_type *pt, struct sk_buff *skb, int
...
@@ -1319,7 +1312,11 @@ static int deliver_to_old_ones(struct packet_type *pt, struct sk_buff *skb, int
tasklet_hi_enable
(
bh_task_vec
+
TIMER_BH
);
tasklet_hi_enable
(
bh_task_vec
+
TIMER_BH
);
spin_unlock
(
&
net_bh_lock
);
spin_unlock
(
&
net_bh_lock
);
out:
return
ret
;
return
ret
;
out_kfree:
kfree_skb
(
skb
);
goto
out
;
}
}
static
__inline__
void
skb_bond
(
struct
sk_buff
*
skb
)
static
__inline__
void
skb_bond
(
struct
sk_buff
*
skb
)
...
@@ -1342,11 +1339,11 @@ static void net_tx_action(struct softirq_action *h)
...
@@ -1342,11 +1339,11 @@ static void net_tx_action(struct softirq_action *h)
softnet_data
[
cpu
].
completion_queue
=
NULL
;
softnet_data
[
cpu
].
completion_queue
=
NULL
;
local_irq_enable
();
local_irq_enable
();
while
(
clist
!=
NULL
)
{
while
(
clist
)
{
struct
sk_buff
*
skb
=
clist
;
struct
sk_buff
*
skb
=
clist
;
clist
=
clist
->
next
;
clist
=
clist
->
next
;
BUG_TRAP
(
atomic_read
(
&
skb
->
users
)
==
0
);
BUG_TRAP
(
!
atomic_read
(
&
skb
->
users
)
);
__kfree_skb
(
skb
);
__kfree_skb
(
skb
);
}
}
}
}
...
@@ -1359,7 +1356,7 @@ static void net_tx_action(struct softirq_action *h)
...
@@ -1359,7 +1356,7 @@ static void net_tx_action(struct softirq_action *h)
softnet_data
[
cpu
].
output_queue
=
NULL
;
softnet_data
[
cpu
].
output_queue
=
NULL
;
local_irq_enable
();
local_irq_enable
();
while
(
head
!=
NULL
)
{
while
(
head
)
{
struct
net_device
*
dev
=
head
;
struct
net_device
*
dev
=
head
;
head
=
head
->
next_sched
;
head
=
head
->
next_sched
;
...
@@ -1383,7 +1380,6 @@ static void net_tx_action(struct softirq_action *h)
...
@@ -1383,7 +1380,6 @@ static void net_tx_action(struct softirq_action *h)
* Make a function call that is atomic with respect to the protocol
* Make a function call that is atomic with respect to the protocol
* layers.
* layers.
*/
*/
void
net_call_rx_atomic
(
void
(
*
fn
)(
void
))
void
net_call_rx_atomic
(
void
(
*
fn
)(
void
))
{
{
br_write_lock_bh
(
BR_NETPROTO_LOCK
);
br_write_lock_bh
(
BR_NETPROTO_LOCK
);
...
@@ -1429,7 +1425,7 @@ int netif_receive_skb(struct sk_buff *skb)
...
@@ -1429,7 +1425,7 @@ int netif_receive_skb(struct sk_buff *skb)
int
ret
=
NET_RX_DROP
;
int
ret
=
NET_RX_DROP
;
unsigned
short
type
=
skb
->
protocol
;
unsigned
short
type
=
skb
->
protocol
;
if
(
skb
->
stamp
.
tv_sec
==
0
)
if
(
!
skb
->
stamp
.
tv_sec
)
do_gettimeofday
(
&
skb
->
stamp
);
do_gettimeofday
(
&
skb
->
stamp
);
skb_bond
(
skb
);
skb_bond
(
skb
);
...
@@ -1450,10 +1446,12 @@ int netif_receive_skb(struct sk_buff *skb)
...
@@ -1450,10 +1446,12 @@ int netif_receive_skb(struct sk_buff *skb)
if
(
!
ptype
->
dev
||
ptype
->
dev
==
skb
->
dev
)
{
if
(
!
ptype
->
dev
||
ptype
->
dev
==
skb
->
dev
)
{
if
(
pt_prev
)
{
if
(
pt_prev
)
{
if
(
!
pt_prev
->
data
)
{
if
(
!
pt_prev
->
data
)
{
ret
=
deliver_to_old_ones
(
pt_prev
,
skb
,
0
);
ret
=
deliver_to_old_ones
(
pt_prev
,
skb
,
0
);
}
else
{
}
else
{
atomic_inc
(
&
skb
->
users
);
atomic_inc
(
&
skb
->
users
);
ret
=
pt_prev
->
func
(
skb
,
skb
->
dev
,
pt_prev
);
ret
=
pt_prev
->
func
(
skb
,
skb
->
dev
,
pt_prev
);
}
}
}
}
pt_prev
=
ptype
;
pt_prev
=
ptype
;
...
@@ -1466,21 +1464,22 @@ int netif_receive_skb(struct sk_buff *skb)
...
@@ -1466,21 +1464,22 @@ int netif_receive_skb(struct sk_buff *skb)
#endif
/* CONFIG_NET_DIVERT */
#endif
/* CONFIG_NET_DIVERT */
#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
if
(
skb
->
dev
->
br_port
!=
NULL
&&
if
(
skb
->
dev
->
br_port
&&
br_handle_frame_hook
)
{
br_handle_frame_hook
!=
NULL
)
{
return
handle_bridge
(
skb
,
pt_prev
);
return
handle_bridge
(
skb
,
pt_prev
);
}
}
#endif
#endif
for
(
ptype
=
ptype_base
[
ntohs
(
type
)
&
15
];
ptype
;
ptype
=
ptype
->
next
)
{
for
(
ptype
=
ptype_base
[
ntohs
(
type
)
&
15
];
ptype
;
ptype
=
ptype
->
next
)
{
if
(
ptype
->
type
==
type
&&
if
(
ptype
->
type
==
type
&&
(
!
ptype
->
dev
||
ptype
->
dev
==
skb
->
dev
))
{
(
!
ptype
->
dev
||
ptype
->
dev
==
skb
->
dev
))
{
if
(
pt_prev
)
{
if
(
pt_prev
)
{
if
(
!
pt_prev
->
data
)
{
if
(
!
pt_prev
->
data
)
{
ret
=
deliver_to_old_ones
(
pt_prev
,
skb
,
0
);
ret
=
deliver_to_old_ones
(
pt_prev
,
skb
,
0
);
}
else
{
}
else
{
atomic_inc
(
&
skb
->
users
);
atomic_inc
(
&
skb
->
users
);
ret
=
pt_prev
->
func
(
skb
,
skb
->
dev
,
pt_prev
);
ret
=
pt_prev
->
func
(
skb
,
skb
->
dev
,
pt_prev
);
}
}
}
}
pt_prev
=
ptype
;
pt_prev
=
ptype
;
...
@@ -1518,7 +1517,7 @@ static int process_backlog(struct net_device *backlog_dev, int *budget)
...
@@ -1518,7 +1517,7 @@ static int process_backlog(struct net_device *backlog_dev, int *budget)
local_irq_disable
();
local_irq_disable
();
skb
=
__skb_dequeue
(
&
queue
->
input_pkt_queue
);
skb
=
__skb_dequeue
(
&
queue
->
input_pkt_queue
);
if
(
skb
==
NULL
)
if
(
!
skb
)
goto
job_done
;
goto
job_done
;
local_irq_enable
();
local_irq_enable
();
...
@@ -1534,7 +1533,8 @@ static int process_backlog(struct net_device *backlog_dev, int *budget)
...
@@ -1534,7 +1533,8 @@ static int process_backlog(struct net_device *backlog_dev, int *budget)
break
;
break
;
#ifdef CONFIG_NET_HW_FLOWCONTROL
#ifdef CONFIG_NET_HW_FLOWCONTROL
if
(
queue
->
throttle
&&
queue
->
input_pkt_queue
.
qlen
<
no_cong_thresh
)
{
if
(
queue
->
throttle
&&
queue
->
input_pkt_queue
.
qlen
<
no_cong_thresh
)
{
if
(
atomic_dec_and_test
(
&
netdev_dropping
))
{
if
(
atomic_dec_and_test
(
&
netdev_dropping
))
{
queue
->
throttle
=
0
;
queue
->
throttle
=
0
;
netdev_wakeup
();
netdev_wakeup
();
...
@@ -1584,7 +1584,8 @@ static void net_rx_action(struct softirq_action *h)
...
@@ -1584,7 +1584,8 @@ static void net_rx_action(struct softirq_action *h)
local_irq_enable
();
local_irq_enable
();
dev
=
list_entry
(
queue
->
poll_list
.
next
,
struct
net_device
,
poll_list
);
dev
=
list_entry
(
queue
->
poll_list
.
next
,
struct
net_device
,
poll_list
);
if
(
dev
->
quota
<=
0
||
dev
->
poll
(
dev
,
&
budget
))
{
if
(
dev
->
quota
<=
0
||
dev
->
poll
(
dev
,
&
budget
))
{
local_irq_disable
();
local_irq_disable
();
...
@@ -1599,7 +1600,7 @@ static void net_rx_action(struct softirq_action *h)
...
@@ -1599,7 +1600,7 @@ static void net_rx_action(struct softirq_action *h)
local_irq_disable
();
local_irq_disable
();
}
}
}
}
out:
local_irq_enable
();
local_irq_enable
();
br_read_unlock
(
BR_NETPROTO_LOCK
);
br_read_unlock
(
BR_NETPROTO_LOCK
);
return
;
return
;
...
@@ -1607,9 +1608,7 @@ static void net_rx_action(struct softirq_action *h)
...
@@ -1607,9 +1608,7 @@ static void net_rx_action(struct softirq_action *h)
softnet_break:
softnet_break:
netdev_rx_stat
[
this_cpu
].
time_squeeze
++
;
netdev_rx_stat
[
this_cpu
].
time_squeeze
++
;
__cpu_raise_softirq
(
this_cpu
,
NET_RX_SOFTIRQ
);
__cpu_raise_softirq
(
this_cpu
,
NET_RX_SOFTIRQ
);
goto
out
;
local_irq_enable
();
br_read_unlock
(
BR_NETPROTO_LOCK
);
}
}
static
gifconf_func_t
*
gifconf_list
[
NPROTO
];
static
gifconf_func_t
*
gifconf_list
[
NPROTO
];
...
@@ -1623,10 +1622,9 @@ static gifconf_func_t * gifconf_list [NPROTO];
...
@@ -1623,10 +1622,9 @@ static gifconf_func_t * gifconf_list [NPROTO];
* that is passed must not be freed or reused until it has been replaced
* that is passed must not be freed or reused until it has been replaced
* by another handler.
* by another handler.
*/
*/
int
register_gifconf
(
unsigned
int
family
,
gifconf_func_t
*
gifconf
)
int
register_gifconf
(
unsigned
int
family
,
gifconf_func_t
*
gifconf
)
{
{
if
(
family
>=
NPROTO
)
if
(
family
>=
NPROTO
)
return
-
EINVAL
;
return
-
EINVAL
;
gifconf_list
[
family
]
=
gifconf
;
gifconf_list
[
family
]
=
gifconf
;
return
0
;
return
0
;
...
@@ -1701,18 +1699,17 @@ static int dev_ifconf(char *arg)
...
@@ -1701,18 +1699,17 @@ static int dev_ifconf(char *arg)
*/
*/
total
=
0
;
total
=
0
;
for
(
dev
=
dev_base
;
dev
!=
NULL
;
dev
=
dev
->
next
)
{
for
(
dev
=
dev_base
;
dev
;
dev
=
dev
->
next
)
{
for
(
i
=
0
;
i
<
NPROTO
;
i
++
)
{
for
(
i
=
0
;
i
<
NPROTO
;
i
++
)
{
if
(
gifconf_list
[
i
])
{
if
(
gifconf_list
[
i
])
{
int
done
;
int
done
;
if
(
pos
==
NULL
)
{
if
(
!
pos
)
done
=
gifconf_list
[
i
](
dev
,
NULL
,
0
);
done
=
gifconf_list
[
i
](
dev
,
NULL
,
0
);
}
else
{
else
done
=
gifconf_list
[
i
](
dev
,
pos
+
total
,
len
-
total
);
done
=
gifconf_list
[
i
](
dev
,
pos
+
total
,
}
len
-
total
);
if
(
done
<
0
)
{
if
(
done
<
0
)
return
-
EFAULT
;
return
-
EFAULT
;
}
total
+=
done
;
total
+=
done
;
}
}
}
}
...
@@ -1723,13 +1720,10 @@ static int dev_ifconf(char *arg)
...
@@ -1723,13 +1720,10 @@ static int dev_ifconf(char *arg)
*/
*/
ifc
.
ifc_len
=
total
;
ifc
.
ifc_len
=
total
;
if
(
copy_to_user
(
arg
,
&
ifc
,
sizeof
(
struct
ifconf
)))
return
-
EFAULT
;
/*
/*
* Both BSD and Solaris return 0 here, so we do too.
* Both BSD and Solaris return 0 here, so we do too.
*/
*/
return
0
;
return
copy_to_user
(
arg
,
&
ifc
,
sizeof
(
struct
ifconf
))
?
-
EFAULT
:
0
;
}
}
/*
/*
...
@@ -1741,36 +1735,39 @@ static int dev_ifconf(char *arg)
...
@@ -1741,36 +1735,39 @@ static int dev_ifconf(char *arg)
static
int
sprintf_stats
(
char
*
buffer
,
struct
net_device
*
dev
)
static
int
sprintf_stats
(
char
*
buffer
,
struct
net_device
*
dev
)
{
{
struct
net_device_stats
*
stats
=
(
dev
->
get_stats
?
dev
->
get_stats
(
dev
)
:
NULL
);
struct
net_device_stats
*
stats
=
dev
->
get_stats
?
dev
->
get_stats
(
dev
)
:
NULL
;
int
size
;
int
size
;
if
(
stats
)
if
(
stats
)
size
=
sprintf
(
buffer
,
"%6s:%8lu %7lu %4lu %4lu %4lu %5lu %10lu %9lu %8lu %7lu %4lu %4lu %4lu %5lu %7lu %10lu
\n
"
,
size
=
sprintf
(
buffer
,
"%6s:%8lu %7lu %4lu %4lu %4lu %5lu "
"%10lu %9lu %8lu %7lu %4lu %4lu %4lu "
"%5lu %7lu %10lu
\n
"
,
dev
->
name
,
dev
->
name
,
stats
->
rx_bytes
,
stats
->
rx_bytes
,
stats
->
rx_packets
,
stats
->
rx_errors
,
stats
->
rx_packets
,
stats
->
rx_errors
,
stats
->
rx_dropped
+
stats
->
rx_missed_errors
,
stats
->
rx_dropped
+
stats
->
rx_missed_errors
,
stats
->
rx_fifo_errors
,
stats
->
rx_fifo_errors
,
stats
->
rx_length_errors
+
stats
->
rx_over_errors
stats
->
rx_length_errors
+
stats
->
rx_over_errors
+
+
stats
->
rx_crc_errors
+
stats
->
rx_frame_errors
,
stats
->
rx_crc_errors
+
stats
->
rx_frame_errors
,
stats
->
rx_compressed
,
stats
->
multicast
,
stats
->
rx_compressed
,
stats
->
multicast
,
stats
->
tx_bytes
,
stats
->
tx_bytes
,
stats
->
tx_packets
,
stats
->
tx_errors
,
stats
->
tx_dropped
,
stats
->
tx_packets
,
stats
->
tx_errors
,
stats
->
tx_dropped
,
stats
->
tx_fifo_errors
,
stats
->
collisions
,
stats
->
tx_fifo_errors
,
stats
->
collisions
,
stats
->
tx_carrier_errors
+
stats
->
tx_aborted_errors
stats
->
tx_carrier_errors
+
stats
->
tx_aborted_errors
+
+
stats
->
tx_window_errors
+
stats
->
tx_heartbeat_errors
,
stats
->
tx_window_errors
+
stats
->
tx_heartbeat_errors
,
stats
->
tx_compressed
);
stats
->
tx_compressed
);
else
else
size
=
sprintf
(
buffer
,
"%6s: No statistics available.
\n
"
,
dev
->
name
);
size
=
sprintf
(
buffer
,
"%6s: No statistics available.
\n
"
,
dev
->
name
);
return
size
;
return
size
;
}
}
/*
/*
* Called from the PROCfs module. This now uses the new arbitrary sized
/proc/net interface
* Called from the PROCfs module. This now uses the new arbitrary sized
* to create /proc/net/dev
*
/proc/net interface
to create /proc/net/dev
*/
*/
static
int
dev_get_info
(
char
*
buffer
,
char
**
start
,
off_t
offset
,
int
length
)
static
int
dev_get_info
(
char
*
buffer
,
char
**
start
,
off_t
offset
,
int
length
)
{
{
int
len
=
0
;
int
len
=
0
;
...
@@ -1779,7 +1776,6 @@ static int dev_get_info(char *buffer, char **start, off_t offset, int length)
...
@@ -1779,7 +1776,6 @@ static int dev_get_info(char *buffer, char **start, off_t offset, int length)
int
size
;
int
size
;
struct
net_device
*
dev
;
struct
net_device
*
dev
;
size
=
sprintf
(
buffer
,
size
=
sprintf
(
buffer
,
"Inter-| Receive | Transmit
\n
"
"Inter-| Receive | Transmit
\n
"
" face |bytes packets errs drop fifo frame compressed multicast|bytes packets errs drop fifo colls carrier compressed
\n
"
);
" face |bytes packets errs drop fifo frame compressed multicast|bytes packets errs drop fifo colls carrier compressed
\n
"
);
...
@@ -1787,9 +1783,8 @@ static int dev_get_info(char *buffer, char **start, off_t offset, int length)
...
@@ -1787,9 +1783,8 @@ static int dev_get_info(char *buffer, char **start, off_t offset, int length)
pos
+=
size
;
pos
+=
size
;
len
+=
size
;
len
+=
size
;
read_lock
(
&
dev_base_lock
);
read_lock
(
&
dev_base_lock
);
for
(
dev
=
dev_base
;
dev
!=
NULL
;
dev
=
dev
->
next
)
{
for
(
dev
=
dev_base
;
dev
;
dev
=
dev
->
next
)
{
size
=
sprintf_stats
(
buffer
+
len
,
dev
);
size
=
sprintf_stats
(
buffer
+
len
,
dev
);
len
+=
size
;
len
+=
size
;
pos
=
begin
+
len
;
pos
=
begin
+
len
;
...
@@ -1804,7 +1799,7 @@ static int dev_get_info(char *buffer, char **start, off_t offset, int length)
...
@@ -1804,7 +1799,7 @@ static int dev_get_info(char *buffer, char **start, off_t offset, int length)
read_unlock
(
&
dev_base_lock
);
read_unlock
(
&
dev_base_lock
);
*
start
=
buffer
+
(
offset
-
begin
);
/* Start of wanted data */
*
start
=
buffer
+
(
offset
-
begin
);
/* Start of wanted data */
len
-=
(
offset
-
begin
);
/* Start slop */
len
-=
offset
-
begin
;
/* Start slop */
if
(
len
>
length
)
if
(
len
>
length
)
len
=
length
;
/* Ending slop */
len
=
length
;
/* Ending slop */
if
(
len
<
0
)
if
(
len
<
0
)
...
@@ -1816,11 +1811,12 @@ static int dev_proc_stats(char *buffer, char **start, off_t offset,
...
@@ -1816,11 +1811,12 @@ static int dev_proc_stats(char *buffer, char **start, off_t offset,
int
length
,
int
*
eof
,
void
*
data
)
int
length
,
int
*
eof
,
void
*
data
)
{
{
int
i
,
lcpu
;
int
i
,
lcpu
;
int
len
=
0
;
int
len
=
0
;
for
(
lcpu
=
0
;
lcpu
<
smp_num_cpus
;
lcpu
++
)
{
for
(
lcpu
=
0
;
lcpu
<
smp_num_cpus
;
lcpu
++
)
{
i
=
cpu_logical_map
(
lcpu
);
i
=
cpu_logical_map
(
lcpu
);
len
+=
sprintf
(
buffer
+
len
,
"%08x %08x %08x %08x %08x %08x %08x %08x %08x
\n
"
,
len
+=
sprintf
(
buffer
+
len
,
"%08x %08x %08x %08x %08x %08x "
"%08x %08x %08x
\n
"
,
netdev_rx_stat
[
i
].
total
,
netdev_rx_stat
[
i
].
total
,
netdev_rx_stat
[
i
].
dropped
,
netdev_rx_stat
[
i
].
dropped
,
netdev_rx_stat
[
i
].
time_squeeze
,
netdev_rx_stat
[
i
].
time_squeeze
,
...
@@ -1864,7 +1860,6 @@ static int dev_proc_stats(char *buffer, char **start, off_t offset,
...
@@ -1864,7 +1860,6 @@ static int dev_proc_stats(char *buffer, char **start, off_t offset,
* are adjusted, %RTM_NEWLINK is sent to the routing socket and the
* are adjusted, %RTM_NEWLINK is sent to the routing socket and the
* function returns zero.
* function returns zero.
*/
*/
int
netdev_set_master
(
struct
net_device
*
slave
,
struct
net_device
*
master
)
int
netdev_set_master
(
struct
net_device
*
slave
,
struct
net_device
*
master
)
{
{
struct
net_device
*
old
=
slave
->
master
;
struct
net_device
*
old
=
slave
->
master
;
...
@@ -1903,7 +1898,6 @@ int netdev_set_master(struct net_device *slave, struct net_device *master)
...
@@ -1903,7 +1898,6 @@ int netdev_set_master(struct net_device *slave, struct net_device *master)
* the device reverts back to normal filtering operation. A negative inc
* the device reverts back to normal filtering operation. A negative inc
* value is used to drop promiscuity on the device.
* value is used to drop promiscuity on the device.
*/
*/
void
dev_set_promiscuity
(
struct
net_device
*
dev
,
int
inc
)
void
dev_set_promiscuity
(
struct
net_device
*
dev
,
int
inc
)
{
{
unsigned
short
old_flags
=
dev
->
flags
;
unsigned
short
old_flags
=
dev
->
flags
;
...
@@ -1911,9 +1905,9 @@ void dev_set_promiscuity(struct net_device *dev, int inc)
...
@@ -1911,9 +1905,9 @@ void dev_set_promiscuity(struct net_device *dev, int inc)
dev
->
flags
|=
IFF_PROMISC
;
dev
->
flags
|=
IFF_PROMISC
;
if
((
dev
->
promiscuity
+=
inc
)
==
0
)
if
((
dev
->
promiscuity
+=
inc
)
==
0
)
dev
->
flags
&=
~
IFF_PROMISC
;
dev
->
flags
&=
~
IFF_PROMISC
;
if
(
dev
->
flags
^
old_flags
)
{
if
(
dev
->
flags
^
old_flags
)
{
#ifdef CONFIG_NET_FASTROUTE
#ifdef CONFIG_NET_FASTROUTE
if
(
dev
->
flags
&
IFF_PROMISC
)
{
if
(
dev
->
flags
&
IFF_PROMISC
)
{
netdev_fastroute_obstacles
++
;
netdev_fastroute_obstacles
++
;
dev_clear_fastroute
(
dev
);
dev_clear_fastroute
(
dev
);
}
else
}
else
...
@@ -1921,7 +1915,8 @@ void dev_set_promiscuity(struct net_device *dev, int inc)
...
@@ -1921,7 +1915,8 @@ void dev_set_promiscuity(struct net_device *dev, int inc)
#endif
#endif
dev_mc_upload
(
dev
);
dev_mc_upload
(
dev
);
printk
(
KERN_INFO
"device %s %s promiscuous mode
\n
"
,
printk
(
KERN_INFO
"device %s %s promiscuous mode
\n
"
,
dev
->
name
,
(
dev
->
flags
&
IFF_PROMISC
)
?
"entered"
:
"left"
);
dev
->
name
,
(
dev
->
flags
&
IFF_PROMISC
)
?
"entered"
:
"left"
);
}
}
}
}
...
@@ -1944,7 +1939,7 @@ void dev_set_allmulti(struct net_device *dev, int inc)
...
@@ -1944,7 +1939,7 @@ void dev_set_allmulti(struct net_device *dev, int inc)
dev
->
flags
|=
IFF_ALLMULTI
;
dev
->
flags
|=
IFF_ALLMULTI
;
if
((
dev
->
allmulti
+=
inc
)
==
0
)
if
((
dev
->
allmulti
+=
inc
)
==
0
)
dev
->
flags
&=
~
IFF_ALLMULTI
;
dev
->
flags
&=
~
IFF_ALLMULTI
;
if
(
dev
->
flags
^
old_flags
)
if
(
dev
->
flags
^
old_flags
)
dev_mc_upload
(
dev
);
dev_mc_upload
(
dev
);
}
}
...
@@ -1957,9 +1952,11 @@ int dev_change_flags(struct net_device *dev, unsigned flags)
...
@@ -1957,9 +1952,11 @@ int dev_change_flags(struct net_device *dev, unsigned flags)
* Set the flags on our device.
* Set the flags on our device.
*/
*/
dev
->
flags
=
(
flags
&
(
IFF_DEBUG
|
IFF_NOTRAILERS
|
IFF_NOARP
|
IFF_DYNAMIC
|
dev
->
flags
=
(
flags
&
(
IFF_DEBUG
|
IFF_NOTRAILERS
|
IFF_NOARP
|
IFF_MULTICAST
|
IFF_PORTSEL
|
IFF_AUTOMEDIA
))
|
IFF_DYNAMIC
|
IFF_MULTICAST
|
IFF_PORTSEL
|
(
dev
->
flags
&
(
IFF_UP
|
IFF_VOLATILE
|
IFF_PROMISC
|
IFF_ALLMULTI
));
IFF_AUTOMEDIA
))
|
(
dev
->
flags
&
(
IFF_UP
|
IFF_VOLATILE
|
IFF_PROMISC
|
IFF_ALLMULTI
));
/*
/*
* Load in the correct multicast list now the flags have changed.
* Load in the correct multicast list now the flags have changed.
...
@@ -1974,20 +1971,20 @@ int dev_change_flags(struct net_device *dev, unsigned flags)
...
@@ -1974,20 +1971,20 @@ int dev_change_flags(struct net_device *dev, unsigned flags)
*/
*/
ret
=
0
;
ret
=
0
;
if
((
old_flags
^
flags
)
&
IFF_UP
)
/* Bit is different ? */
if
((
old_flags
^
flags
)
&
IFF_UP
)
{
/* Bit is different ? */
{
ret
=
((
old_flags
&
IFF_UP
)
?
dev_close
:
dev_open
)(
dev
);
ret
=
((
old_flags
&
IFF_UP
)
?
dev_close
:
dev_open
)(
dev
);
if
(
ret
==
0
)
if
(
!
ret
)
dev_mc_upload
(
dev
);
dev_mc_upload
(
dev
);
}
}
if
(
dev
->
flags
&
IFF_UP
&&
if
(
dev
->
flags
&
IFF_UP
&&
((
old_flags
^
dev
->
flags
)
&~
(
IFF_UP
|
IFF_PROMISC
|
IFF_ALLMULTI
|
IFF_VOLATILE
)))
((
old_flags
^
dev
->
flags
)
&~
(
IFF_UP
|
IFF_PROMISC
|
IFF_ALLMULTI
|
IFF_VOLATILE
)))
notifier_call_chain
(
&
netdev_chain
,
NETDEV_CHANGE
,
dev
);
notifier_call_chain
(
&
netdev_chain
,
NETDEV_CHANGE
,
dev
);
if
((
flags
^
dev
->
gflags
)
&
IFF_PROMISC
)
{
if
((
flags
^
dev
->
gflags
)
&
IFF_PROMISC
)
{
int
inc
=
(
flags
&
IFF_PROMISC
)
?
+
1
:
-
1
;
int
inc
=
(
flags
&
IFF_PROMISC
)
?
+
1
:
-
1
;
dev
->
gflags
^=
IFF_PROMISC
;
dev
->
gflags
^=
IFF_PROMISC
;
dev_set_promiscuity
(
dev
,
inc
);
dev_set_promiscuity
(
dev
,
inc
);
}
}
...
@@ -1996,14 +1993,14 @@ int dev_change_flags(struct net_device *dev, unsigned flags)
...
@@ -1996,14 +1993,14 @@ int dev_change_flags(struct net_device *dev, unsigned flags)
is important. Some (broken) drivers set IFF_PROMISC, when
is important. Some (broken) drivers set IFF_PROMISC, when
IFF_ALLMULTI is requested not asking us and not reporting.
IFF_ALLMULTI is requested not asking us and not reporting.
*/
*/
if
((
flags
^
dev
->
gflags
)
&
IFF_ALLMULTI
)
{
if
((
flags
^
dev
->
gflags
)
&
IFF_ALLMULTI
)
{
int
inc
=
(
flags
&
IFF_ALLMULTI
)
?
+
1
:
-
1
;
int
inc
=
(
flags
&
IFF_ALLMULTI
)
?
+
1
:
-
1
;
dev
->
gflags
^=
IFF_ALLMULTI
;
dev
->
gflags
^=
IFF_ALLMULTI
;
dev_set_allmulti
(
dev
,
inc
);
dev_set_allmulti
(
dev
,
inc
);
}
}
if
(
old_flags
^
dev
->
flags
)
if
(
old_flags
^
dev
->
flags
)
rtmsg_ifinfo
(
RTM_NEWLINK
,
dev
,
old_flags
^
dev
->
flags
);
rtmsg_ifinfo
(
RTM_NEWLINK
,
dev
,
old_flags
^
dev
->
flags
);
return
ret
;
return
ret
;
}
}
...
@@ -2011,20 +2008,21 @@ int dev_change_flags(struct net_device *dev, unsigned flags)
...
@@ -2011,20 +2008,21 @@ int dev_change_flags(struct net_device *dev, unsigned flags)
/*
/*
* Perform the SIOCxIFxxx calls.
* Perform the SIOCxIFxxx calls.
*/
*/
static
int
dev_ifsioc
(
struct
ifreq
*
ifr
,
unsigned
int
cmd
)
static
int
dev_ifsioc
(
struct
ifreq
*
ifr
,
unsigned
int
cmd
)
{
{
struct
net_device
*
dev
;
int
err
;
int
err
;
struct
net_device
*
dev
=
__dev_get_by_name
(
ifr
->
ifr_name
);
if
(
(
dev
=
__dev_get_by_name
(
ifr
->
ifr_name
))
==
NULL
)
if
(
!
dev
)
return
-
ENODEV
;
return
-
ENODEV
;
switch
(
cmd
)
switch
(
cmd
)
{
{
case
SIOCGIFFLAGS
:
/* Get interface flags */
case
SIOCGIFFLAGS
:
/* Get interface flags */
ifr
->
ifr_flags
=
(
dev
->
flags
&~
(
IFF_PROMISC
|
IFF_ALLMULTI
|
IFF_RUNNING
))
ifr
->
ifr_flags
=
(
dev
->
flags
&
~
(
IFF_PROMISC
|
|
(
dev
->
gflags
&
(
IFF_PROMISC
|
IFF_ALLMULTI
));
IFF_ALLMULTI
|
IFF_RUNNING
))
|
(
dev
->
gflags
&
(
IFF_PROMISC
|
IFF_ALLMULTI
));
if
(
netif_running
(
dev
)
&&
netif_carrier_ok
(
dev
))
if
(
netif_running
(
dev
)
&&
netif_carrier_ok
(
dev
))
ifr
->
ifr_flags
|=
IFF_RUNNING
;
ifr
->
ifr_flags
|=
IFF_RUNNING
;
return
0
;
return
0
;
...
@@ -2032,11 +2030,13 @@ static int dev_ifsioc(struct ifreq *ifr, unsigned int cmd)
...
@@ -2032,11 +2030,13 @@ static int dev_ifsioc(struct ifreq *ifr, unsigned int cmd)
case
SIOCSIFFLAGS
:
/* Set interface flags */
case
SIOCSIFFLAGS
:
/* Set interface flags */
return
dev_change_flags
(
dev
,
ifr
->
ifr_flags
);
return
dev_change_flags
(
dev
,
ifr
->
ifr_flags
);
case
SIOCGIFMETRIC
:
/* Get the metric on the interface (currently unused) */
case
SIOCGIFMETRIC
:
/* Get the metric on the interface
(currently unused) */
ifr
->
ifr_metric
=
0
;
ifr
->
ifr_metric
=
0
;
return
0
;
return
0
;
case
SIOCSIFMETRIC
:
/* Set the metric on the interface (currently unused) */
case
SIOCSIFMETRIC
:
/* Set the metric on the interface
(currently unused) */
return
-
EOPNOTSUPP
;
return
-
EOPNOTSUPP
;
case
SIOCGIFMTU
:
/* Get the MTU of a device */
case
SIOCGIFMTU
:
/* Get the MTU of a device */
...
@@ -2050,80 +2050,85 @@ static int dev_ifsioc(struct ifreq *ifr, unsigned int cmd)
...
@@ -2050,80 +2050,85 @@ static int dev_ifsioc(struct ifreq *ifr, unsigned int cmd)
/*
/*
* MTU must be positive.
* MTU must be positive.
*/
*/
if
(
ifr
->
ifr_mtu
<
0
)
if
(
ifr
->
ifr_mtu
<
0
)
return
-
EINVAL
;
return
-
EINVAL
;
if
(
!
netif_device_present
(
dev
))
if
(
!
netif_device_present
(
dev
))
return
-
ENODEV
;
return
-
ENODEV
;
err
=
0
;
if
(
dev
->
change_mtu
)
if
(
dev
->
change_mtu
)
err
=
dev
->
change_mtu
(
dev
,
ifr
->
ifr_mtu
);
err
=
dev
->
change_mtu
(
dev
,
ifr
->
ifr_mtu
);
else
{
else
dev
->
mtu
=
ifr
->
ifr_mtu
;
dev
->
mtu
=
ifr
->
ifr_mtu
;
err
=
0
;
if
(
!
err
&&
dev
->
flags
&
IFF_UP
)
}
notifier_call_chain
(
&
netdev_chain
,
if
(
!
err
&&
dev
->
flags
&
IFF_UP
)
NETDEV_CHANGEMTU
,
dev
);
notifier_call_chain
(
&
netdev_chain
,
NETDEV_CHANGEMTU
,
dev
);
return
err
;
return
err
;
case
SIOCGIFHWADDR
:
case
SIOCGIFHWADDR
:
memcpy
(
ifr
->
ifr_hwaddr
.
sa_data
,
dev
->
dev_addr
,
MAX_ADDR_LEN
);
memcpy
(
ifr
->
ifr_hwaddr
.
sa_data
,
dev
->
dev_addr
,
ifr
->
ifr_hwaddr
.
sa_family
=
dev
->
type
;
MAX_ADDR_LEN
);
ifr
->
ifr_hwaddr
.
sa_family
=
dev
->
type
;
return
0
;
return
0
;
case
SIOCSIFHWADDR
:
case
SIOCSIFHWADDR
:
if
(
dev
->
set_mac_address
==
NULL
)
if
(
!
dev
->
set_mac_address
)
return
-
EOPNOTSUPP
;
return
-
EOPNOTSUPP
;
if
(
ifr
->
ifr_hwaddr
.
sa_family
!=
dev
->
type
)
if
(
ifr
->
ifr_hwaddr
.
sa_family
!=
dev
->
type
)
return
-
EINVAL
;
return
-
EINVAL
;
if
(
!
netif_device_present
(
dev
))
if
(
!
netif_device_present
(
dev
))
return
-
ENODEV
;
return
-
ENODEV
;
err
=
dev
->
set_mac_address
(
dev
,
&
ifr
->
ifr_hwaddr
);
err
=
dev
->
set_mac_address
(
dev
,
&
ifr
->
ifr_hwaddr
);
if
(
!
err
)
if
(
!
err
)
notifier_call_chain
(
&
netdev_chain
,
NETDEV_CHANGEADDR
,
dev
);
notifier_call_chain
(
&
netdev_chain
,
NETDEV_CHANGEADDR
,
dev
);
return
err
;
return
err
;
case
SIOCSIFHWBROADCAST
:
case
SIOCSIFHWBROADCAST
:
if
(
ifr
->
ifr_hwaddr
.
sa_family
!=
dev
->
type
)
if
(
ifr
->
ifr_hwaddr
.
sa_family
!=
dev
->
type
)
return
-
EINVAL
;
return
-
EINVAL
;
memcpy
(
dev
->
broadcast
,
ifr
->
ifr_hwaddr
.
sa_data
,
MAX_ADDR_LEN
);
memcpy
(
dev
->
broadcast
,
ifr
->
ifr_hwaddr
.
sa_data
,
notifier_call_chain
(
&
netdev_chain
,
NETDEV_CHANGEADDR
,
dev
);
MAX_ADDR_LEN
);
notifier_call_chain
(
&
netdev_chain
,
NETDEV_CHANGEADDR
,
dev
);
return
0
;
return
0
;
case
SIOCGIFMAP
:
case
SIOCGIFMAP
:
ifr
->
ifr_map
.
mem_start
=
dev
->
mem_start
;
ifr
->
ifr_map
.
mem_start
=
dev
->
mem_start
;
ifr
->
ifr_map
.
mem_end
=
dev
->
mem_end
;
ifr
->
ifr_map
.
mem_end
=
dev
->
mem_end
;
ifr
->
ifr_map
.
base_addr
=
dev
->
base_addr
;
ifr
->
ifr_map
.
base_addr
=
dev
->
base_addr
;
ifr
->
ifr_map
.
irq
=
dev
->
irq
;
ifr
->
ifr_map
.
irq
=
dev
->
irq
;
ifr
->
ifr_map
.
dma
=
dev
->
dma
;
ifr
->
ifr_map
.
dma
=
dev
->
dma
;
ifr
->
ifr_map
.
port
=
dev
->
if_port
;
ifr
->
ifr_map
.
port
=
dev
->
if_port
;
return
0
;
return
0
;
case
SIOCSIFMAP
:
case
SIOCSIFMAP
:
if
(
dev
->
set_config
)
{
if
(
dev
->
set_config
)
{
if
(
!
netif_device_present
(
dev
))
if
(
!
netif_device_present
(
dev
))
return
-
ENODEV
;
return
-
ENODEV
;
return
dev
->
set_config
(
dev
,
&
ifr
->
ifr_map
);
return
dev
->
set_config
(
dev
,
&
ifr
->
ifr_map
);
}
}
return
-
EOPNOTSUPP
;
return
-
EOPNOTSUPP
;
case
SIOCADDMULTI
:
case
SIOCADDMULTI
:
if
(
dev
->
set_multicast_list
==
NULL
||
if
(
!
dev
->
set_multicast_list
||
ifr
->
ifr_hwaddr
.
sa_family
!=
AF_UNSPEC
)
ifr
->
ifr_hwaddr
.
sa_family
!=
AF_UNSPEC
)
return
-
EINVAL
;
return
-
EINVAL
;
if
(
!
netif_device_present
(
dev
))
if
(
!
netif_device_present
(
dev
))
return
-
ENODEV
;
return
-
ENODEV
;
dev_mc_add
(
dev
,
ifr
->
ifr_hwaddr
.
sa_data
,
dev
->
addr_len
,
1
);
dev_mc_add
(
dev
,
ifr
->
ifr_hwaddr
.
sa_data
,
dev
->
addr_len
,
1
);
return
0
;
return
0
;
case
SIOCDELMULTI
:
case
SIOCDELMULTI
:
if
(
dev
->
set_multicast_list
==
NULL
||
if
(
!
dev
->
set_multicast_list
||
ifr
->
ifr_hwaddr
.
sa_family
!=
AF_UNSPEC
)
ifr
->
ifr_hwaddr
.
sa_family
!=
AF_UNSPEC
)
return
-
EINVAL
;
return
-
EINVAL
;
if
(
!
netif_device_present
(
dev
))
if
(
!
netif_device_present
(
dev
))
return
-
ENODEV
;
return
-
ENODEV
;
dev_mc_delete
(
dev
,
ifr
->
ifr_hwaddr
.
sa_data
,
dev
->
addr_len
,
1
);
dev_mc_delete
(
dev
,
ifr
->
ifr_hwaddr
.
sa_data
,
dev
->
addr_len
,
1
);
return
0
;
return
0
;
case
SIOCGIFINDEX
:
case
SIOCGIFINDEX
:
...
@@ -2135,19 +2140,20 @@ static int dev_ifsioc(struct ifreq *ifr, unsigned int cmd)
...
@@ -2135,19 +2140,20 @@ static int dev_ifsioc(struct ifreq *ifr, unsigned int cmd)
return
0
;
return
0
;
case
SIOCSIFTXQLEN
:
case
SIOCSIFTXQLEN
:
if
(
ifr
->
ifr_qlen
<
0
)
if
(
ifr
->
ifr_qlen
<
0
)
return
-
EINVAL
;
return
-
EINVAL
;
dev
->
tx_queue_len
=
ifr
->
ifr_qlen
;
dev
->
tx_queue_len
=
ifr
->
ifr_qlen
;
return
0
;
return
0
;
case
SIOCSIFNAME
:
case
SIOCSIFNAME
:
if
(
dev
->
flags
&
IFF_UP
)
if
(
dev
->
flags
&
IFF_UP
)
return
-
EBUSY
;
return
-
EBUSY
;
if
(
__dev_get_by_name
(
ifr
->
ifr_newname
))
if
(
__dev_get_by_name
(
ifr
->
ifr_newname
))
return
-
EEXIST
;
return
-
EEXIST
;
memcpy
(
dev
->
name
,
ifr
->
ifr_newname
,
IFNAMSIZ
);
memcpy
(
dev
->
name
,
ifr
->
ifr_newname
,
IFNAMSIZ
);
dev
->
name
[
IFNAMSIZ
-
1
]
=
0
;
dev
->
name
[
IFNAMSIZ
-
1
]
=
0
;
notifier_call_chain
(
&
netdev_chain
,
NETDEV_CHANGENAME
,
dev
);
notifier_call_chain
(
&
netdev_chain
,
NETDEV_CHANGENAME
,
dev
);
return
0
;
return
0
;
/*
/*
...
@@ -2168,16 +2174,19 @@ static int dev_ifsioc(struct ifreq *ifr, unsigned int cmd)
...
@@ -2168,16 +2174,19 @@ static int dev_ifsioc(struct ifreq *ifr, unsigned int cmd)
cmd
==
SIOCGMIIREG
||
cmd
==
SIOCGMIIREG
||
cmd
==
SIOCSMIIREG
||
cmd
==
SIOCSMIIREG
||
cmd
==
SIOCWANDEV
)
{
cmd
==
SIOCWANDEV
)
{
err
=
-
EOPNOTSUPP
;
if
(
dev
->
do_ioctl
)
{
if
(
dev
->
do_ioctl
)
{
if
(
!
netif_device_present
(
dev
))
if
(
netif_device_present
(
dev
))
return
-
ENODEV
;
err
=
dev
->
do_ioctl
(
dev
,
ifr
,
return
dev
->
do_ioctl
(
dev
,
ifr
,
cmd
);
cmd
);
}
else
return
-
EOPNOTSUPP
;
err
=
-
ENODEV
;
}
}
}
else
err
=
-
EINVAL
;
}
}
return
-
EINVAL
;
return
err
;
}
}
/*
/*
...
@@ -2213,9 +2222,8 @@ int dev_ioctl(unsigned int cmd, void *arg)
...
@@ -2213,9 +2222,8 @@ int dev_ioctl(unsigned int cmd, void *arg)
rtnl_shunlock
();
rtnl_shunlock
();
return
ret
;
return
ret
;
}
}
if
(
cmd
==
SIOCGIFNAME
)
{
if
(
cmd
==
SIOCGIFNAME
)
return
dev_ifname
((
struct
ifreq
*
)
arg
);
return
dev_ifname
((
struct
ifreq
*
)
arg
);
}
if
(
copy_from_user
(
&
ifr
,
arg
,
sizeof
(
struct
ifreq
)))
if
(
copy_from_user
(
&
ifr
,
arg
,
sizeof
(
struct
ifreq
)))
return
-
EFAULT
;
return
-
EFAULT
;
...
@@ -2230,15 +2238,13 @@ int dev_ioctl(unsigned int cmd, void *arg)
...
@@ -2230,15 +2238,13 @@ int dev_ioctl(unsigned int cmd, void *arg)
* See which interface the caller is talking about.
* See which interface the caller is talking about.
*/
*/
switch
(
cmd
)
switch
(
cmd
)
{
{
/*
/*
* These ioctl calls:
* These ioctl calls:
* - can be done by all.
* - can be done by all.
* - atomic and do not require locking.
* - atomic and do not require locking.
* - return a value
* - return a value
*/
*/
case
SIOCGIFFLAGS
:
case
SIOCGIFFLAGS
:
case
SIOCGIFMETRIC
:
case
SIOCGIFMETRIC
:
case
SIOCGIFMTU
:
case
SIOCGIFMTU
:
...
@@ -2254,8 +2260,9 @@ int dev_ioctl(unsigned int cmd, void *arg)
...
@@ -2254,8 +2260,9 @@ int dev_ioctl(unsigned int cmd, void *arg)
if
(
!
ret
)
{
if
(
!
ret
)
{
if
(
colon
)
if
(
colon
)
*
colon
=
':'
;
*
colon
=
':'
;
if
(
copy_to_user
(
arg
,
&
ifr
,
sizeof
(
struct
ifreq
)))
if
(
copy_to_user
(
arg
,
&
ifr
,
return
-
EFAULT
;
sizeof
(
struct
ifreq
)))
ret
=
-
EFAULT
;
}
}
return
ret
;
return
ret
;
...
@@ -2265,7 +2272,6 @@ int dev_ioctl(unsigned int cmd, void *arg)
...
@@ -2265,7 +2272,6 @@ int dev_ioctl(unsigned int cmd, void *arg)
* - require strict serialization.
* - require strict serialization.
* - return a value
* - return a value
*/
*/
case
SIOCETHTOOL
:
case
SIOCETHTOOL
:
case
SIOCGMIIPHY
:
case
SIOCGMIIPHY
:
case
SIOCGMIIREG
:
case
SIOCGMIIREG
:
...
@@ -2280,8 +2286,9 @@ int dev_ioctl(unsigned int cmd, void *arg)
...
@@ -2280,8 +2286,9 @@ int dev_ioctl(unsigned int cmd, void *arg)
if
(
!
ret
)
{
if
(
!
ret
)
{
if
(
colon
)
if
(
colon
)
*
colon
=
':'
;
*
colon
=
':'
;
if
(
copy_to_user
(
arg
,
&
ifr
,
sizeof
(
struct
ifreq
)))
if
(
copy_to_user
(
arg
,
&
ifr
,
return
-
EFAULT
;
sizeof
(
struct
ifreq
)))
ret
=
-
EFAULT
;
}
}
return
ret
;
return
ret
;
...
@@ -2291,7 +2298,6 @@ int dev_ioctl(unsigned int cmd, void *arg)
...
@@ -2291,7 +2298,6 @@ int dev_ioctl(unsigned int cmd, void *arg)
* - require strict serialization.
* - require strict serialization.
* - do not return a value
* - do not return a value
*/
*/
case
SIOCSIFFLAGS
:
case
SIOCSIFFLAGS
:
case
SIOCSIFMETRIC
:
case
SIOCSIFMETRIC
:
case
SIOCSIFMTU
:
case
SIOCSIFMTU
:
...
@@ -2321,17 +2327,17 @@ int dev_ioctl(unsigned int cmd, void *arg)
...
@@ -2321,17 +2327,17 @@ int dev_ioctl(unsigned int cmd, void *arg)
return
ret
;
return
ret
;
case
SIOCGIFMEM
:
case
SIOCGIFMEM
:
/* Get the per device memory space. We can add this but
currently
/* Get the per device memory space. We can add this but
do not support it */
* currently
do not support it */
case
SIOCSIFMEM
:
case
SIOCSIFMEM
:
/* Set the per device memory buffer space. Not applicable in our case */
/* Set the per device memory buffer space.
* Not applicable in our case */
case
SIOCSIFLINK
:
case
SIOCSIFLINK
:
return
-
EINVAL
;
return
-
EINVAL
;
/*
/*
* Unknown or private ioctl.
* Unknown or private ioctl.
*/
*/
default:
default:
if
(
cmd
==
SIOCWANDEV
||
if
(
cmd
==
SIOCWANDEV
||
(
cmd
>=
SIOCDEVPRIVATE
&&
(
cmd
>=
SIOCDEVPRIVATE
&&
...
@@ -2342,8 +2348,9 @@ int dev_ioctl(unsigned int cmd, void *arg)
...
@@ -2342,8 +2348,9 @@ int dev_ioctl(unsigned int cmd, void *arg)
ret
=
dev_ifsioc
(
&
ifr
,
cmd
);
ret
=
dev_ifsioc
(
&
ifr
,
cmd
);
rtnl_unlock
();
rtnl_unlock
();
dev_probe_unlock
();
dev_probe_unlock
();
if
(
!
ret
&&
copy_to_user
(
arg
,
&
ifr
,
sizeof
(
struct
ifreq
)))
if
(
!
ret
&&
copy_to_user
(
arg
,
&
ifr
,
return
-
EFAULT
;
sizeof
(
struct
ifreq
)))
ret
=
-
EFAULT
;
return
ret
;
return
ret
;
}
}
#ifdef WIRELESS_EXT
#ifdef WIRELESS_EXT
...
@@ -2352,8 +2359,8 @@ int dev_ioctl(unsigned int cmd, void *arg)
...
@@ -2352,8 +2359,8 @@ int dev_ioctl(unsigned int cmd, void *arg)
/* If command is `set a parameter', or
/* If command is `set a parameter', or
* `get the encoding parameters', check if
* `get the encoding parameters', check if
* the user has the right to do it */
* the user has the right to do it */
if
(
IW_IS_SET
(
cmd
)
||
(
cmd
==
SIOCGIWENCODE
)
)
{
if
(
IW_IS_SET
(
cmd
)
||
cmd
==
SIOCGIWENCODE
)
{
if
(
!
capable
(
CAP_NET_ADMIN
))
if
(
!
capable
(
CAP_NET_ADMIN
))
return
-
EPERM
;
return
-
EPERM
;
}
}
dev_load
(
ifr
.
ifr_name
);
dev_load
(
ifr
.
ifr_name
);
...
@@ -2362,8 +2369,9 @@ int dev_ioctl(unsigned int cmd, void *arg)
...
@@ -2362,8 +2369,9 @@ int dev_ioctl(unsigned int cmd, void *arg)
ret
=
wireless_process_ioctl
(
&
ifr
,
cmd
);
ret
=
wireless_process_ioctl
(
&
ifr
,
cmd
);
rtnl_unlock
();
rtnl_unlock
();
if
(
!
ret
&&
IW_IS_GET
(
cmd
)
&&
if
(
!
ret
&&
IW_IS_GET
(
cmd
)
&&
copy_to_user
(
arg
,
&
ifr
,
sizeof
(
struct
ifreq
)))
copy_to_user
(
arg
,
&
ifr
,
return
-
EFAULT
;
sizeof
(
struct
ifreq
)))
ret
=
-
EFAULT
;
return
ret
;
return
ret
;
}
}
#endif
/* WIRELESS_EXT */
#endif
/* WIRELESS_EXT */
...
@@ -2379,14 +2387,13 @@ int dev_ioctl(unsigned int cmd, void *arg)
...
@@ -2379,14 +2387,13 @@ int dev_ioctl(unsigned int cmd, void *arg)
* number. The caller must hold the rtnl semaphore or the
* number. The caller must hold the rtnl semaphore or the
* dev_base_lock to be sure it remains unique.
* dev_base_lock to be sure it remains unique.
*/
*/
int
dev_new_index
(
void
)
int
dev_new_index
(
void
)
{
{
static
int
ifindex
;
static
int
ifindex
;
for
(;;)
{
for
(;;)
{
if
(
++
ifindex
<=
0
)
if
(
++
ifindex
<=
0
)
ifindex
=
1
;
ifindex
=
1
;
if
(
__dev_get_by_index
(
ifindex
)
==
NULL
)
if
(
!
__dev_get_by_index
(
ifindex
)
)
return
ifindex
;
return
ifindex
;
}
}
}
}
...
@@ -2416,15 +2423,13 @@ int net_dev_init(void);
...
@@ -2416,15 +2423,13 @@ int net_dev_init(void);
int
register_netdevice
(
struct
net_device
*
dev
)
int
register_netdevice
(
struct
net_device
*
dev
)
{
{
struct
net_device
*
d
,
**
dp
;
struct
net_device
*
d
,
**
dp
;
#ifdef CONFIG_NET_DIVERT
int
ret
;
int
ret
;
#endif
spin_lock_init
(
&
dev
->
queue_lock
);
spin_lock_init
(
&
dev
->
queue_lock
);
spin_lock_init
(
&
dev
->
xmit_lock
);
spin_lock_init
(
&
dev
->
xmit_lock
);
dev
->
xmit_lock_owner
=
-
1
;
dev
->
xmit_lock_owner
=
-
1
;
#ifdef CONFIG_NET_FASTROUTE
#ifdef CONFIG_NET_FASTROUTE
dev
->
fastpath_lock
=
RW_LOCK_UNLOCKED
;
dev
->
fastpath_lock
=
RW_LOCK_UNLOCKED
;
#endif
#endif
if
(
dev_boot_phase
)
if
(
dev_boot_phase
)
...
@@ -2433,38 +2438,32 @@ int register_netdevice(struct net_device *dev)
...
@@ -2433,38 +2438,32 @@ int register_netdevice(struct net_device *dev)
#ifdef CONFIG_NET_DIVERT
#ifdef CONFIG_NET_DIVERT
ret
=
alloc_divert_blk
(
dev
);
ret
=
alloc_divert_blk
(
dev
);
if
(
ret
)
if
(
ret
)
return
re
t
;
goto
ou
t
;
#endif
/* CONFIG_NET_DIVERT */
#endif
/* CONFIG_NET_DIVERT */
dev
->
iflink
=
-
1
;
dev
->
iflink
=
-
1
;
/* Init, if this function is available */
/* Init, if this function is available */
if
(
dev
->
init
&&
dev
->
init
(
dev
)
!=
0
)
{
ret
=
-
EIO
;
#ifdef CONFIG_NET_DIVERT
if
(
dev
->
init
&&
dev
->
init
(
dev
))
free_divert_blk
(
dev
);
goto
out_err
;
#endif
return
-
EIO
;
}
dev
->
ifindex
=
dev_new_index
();
dev
->
ifindex
=
dev_new_index
();
if
(
dev
->
iflink
==
-
1
)
if
(
dev
->
iflink
==
-
1
)
dev
->
iflink
=
dev
->
ifindex
;
dev
->
iflink
=
dev
->
ifindex
;
/* Check for existence, and append to tail of chain */
/* Check for existence, and append to tail of chain */
for
(
dp
=&
dev_base
;
(
d
=*
dp
)
!=
NULL
;
dp
=&
d
->
next
)
{
ret
=
-
EEXIST
;
if
(
d
==
dev
||
strcmp
(
d
->
name
,
dev
->
name
)
==
0
)
{
for
(
dp
=
&
dev_base
;
(
d
=
*
dp
)
!=
NULL
;
dp
=
&
d
->
next
)
{
#ifdef CONFIG_NET_DIVERT
if
(
d
==
dev
||
!
strcmp
(
d
->
name
,
dev
->
name
))
free_divert_blk
(
dev
);
goto
out_err
;
#endif
return
-
EEXIST
;
}
}
}
/*
/*
* nil rebuild_header routine,
* nil rebuild_header routine,
* that should be never called and used as just bug trap.
* that should be never called and used as just bug trap.
*/
*/
if
(
dev
->
rebuild_header
==
NULL
)
if
(
!
dev
->
rebuild_header
)
dev
->
rebuild_header
=
default_rebuild_header
;
dev
->
rebuild_header
=
default_rebuild_header
;
/*
/*
...
@@ -2486,8 +2485,13 @@ int register_netdevice(struct net_device *dev)
...
@@ -2486,8 +2485,13 @@ int register_netdevice(struct net_device *dev)
notifier_call_chain
(
&
netdev_chain
,
NETDEV_REGISTER
,
dev
);
notifier_call_chain
(
&
netdev_chain
,
NETDEV_REGISTER
,
dev
);
net_run_sbin_hotplug
(
dev
,
"register"
);
net_run_sbin_hotplug
(
dev
,
"register"
);
out:
return
0
;
return
ret
;
out_err:
#ifdef CONFIG_NET_DIVERT
free_divert_blk
(
dev
);
#endif
goto
out
;
}
}
/**
/**
...
@@ -2497,15 +2501,15 @@ int register_netdevice(struct net_device *dev)
...
@@ -2497,15 +2501,15 @@ int register_netdevice(struct net_device *dev)
* Destroy and free a dead device. A value of zero is returned on
* Destroy and free a dead device. A value of zero is returned on
* success.
* success.
*/
*/
int
netdev_finish_unregister
(
struct
net_device
*
dev
)
int
netdev_finish_unregister
(
struct
net_device
*
dev
)
{
{
BUG_TRAP
(
dev
->
ip_ptr
==
NULL
);
BUG_TRAP
(
!
dev
->
ip_ptr
);
BUG_TRAP
(
dev
->
ip6_ptr
==
NULL
);
BUG_TRAP
(
!
dev
->
ip6_ptr
);
BUG_TRAP
(
dev
->
dn_ptr
==
NULL
);
BUG_TRAP
(
!
dev
->
dn_ptr
);
if
(
!
dev
->
deadbeaf
)
{
if
(
!
dev
->
deadbeaf
)
{
printk
(
KERN_ERR
"Freeing alive device %p, %s
\n
"
,
dev
,
dev
->
name
);
printk
(
KERN_ERR
"Freeing alive device %p, %s
\n
"
,
dev
,
dev
->
name
);
return
0
;
return
0
;
}
}
#ifdef NET_REFCNT_DEBUG
#ifdef NET_REFCNT_DEBUG
...
@@ -2541,11 +2545,11 @@ int unregister_netdevice(struct net_device *dev)
...
@@ -2541,11 +2545,11 @@ int unregister_netdevice(struct net_device *dev)
if
(
dev
->
flags
&
IFF_UP
)
if
(
dev
->
flags
&
IFF_UP
)
dev_close
(
dev
);
dev_close
(
dev
);
BUG_TRAP
(
dev
->
deadbeaf
==
0
);
BUG_TRAP
(
!
dev
->
deadbeaf
);
dev
->
deadbeaf
=
1
;
dev
->
deadbeaf
=
1
;
/* And unlink it from device chain. */
/* And unlink it from device chain. */
for
(
dp
=
&
dev_base
;
(
d
=*
dp
)
!=
NULL
;
dp
=
&
d
->
next
)
{
for
(
dp
=
&
dev_base
;
(
d
=
*
dp
)
!=
NULL
;
dp
=
&
d
->
next
)
{
if
(
d
==
dev
)
{
if
(
d
==
dev
)
{
write_lock_bh
(
&
dev_base_lock
);
write_lock_bh
(
&
dev_base_lock
);
*
dp
=
d
->
next
;
*
dp
=
d
->
next
;
...
@@ -2553,8 +2557,9 @@ int unregister_netdevice(struct net_device *dev)
...
@@ -2553,8 +2557,9 @@ int unregister_netdevice(struct net_device *dev)
break
;
break
;
}
}
}
}
if
(
d
==
NULL
)
{
if
(
!
d
)
{
printk
(
KERN_DEBUG
"unregister_netdevice: device %s/%p never was registered
\n
"
,
dev
->
name
,
dev
);
printk
(
KERN_DEBUG
"unregister_netdevice: device %s/%p never "
"was registered
\n
"
,
dev
->
name
,
dev
);
return
-
ENODEV
;
return
-
ENODEV
;
}
}
...
@@ -2562,7 +2567,7 @@ int unregister_netdevice(struct net_device *dev)
...
@@ -2562,7 +2567,7 @@ int unregister_netdevice(struct net_device *dev)
br_write_lock_bh
(
BR_NETPROTO_LOCK
);
br_write_lock_bh
(
BR_NETPROTO_LOCK
);
br_write_unlock_bh
(
BR_NETPROTO_LOCK
);
br_write_unlock_bh
(
BR_NETPROTO_LOCK
);
if
(
dev_boot_phase
==
0
)
{
if
(
!
dev_boot_phase
)
{
#ifdef CONFIG_NET_FASTROUTE
#ifdef CONFIG_NET_FASTROUTE
dev_clear_fastroute
(
dev
);
dev_clear_fastroute
(
dev
);
#endif
#endif
...
@@ -2587,7 +2592,7 @@ int unregister_netdevice(struct net_device *dev)
...
@@ -2587,7 +2592,7 @@ int unregister_netdevice(struct net_device *dev)
dev
->
uninit
(
dev
);
dev
->
uninit
(
dev
);
/* Notifier chain MUST detach us from master device. */
/* Notifier chain MUST detach us from master device. */
BUG_TRAP
(
dev
->
master
==
NULL
);
BUG_TRAP
(
!
dev
->
master
);
#ifdef CONFIG_NET_DIVERT
#ifdef CONFIG_NET_DIVERT
free_divert_blk
(
dev
);
free_divert_blk
(
dev
);
...
@@ -2596,20 +2601,20 @@ int unregister_netdevice(struct net_device *dev)
...
@@ -2596,20 +2601,20 @@ int unregister_netdevice(struct net_device *dev)
if
(
dev
->
features
&
NETIF_F_DYNALLOC
)
{
if
(
dev
->
features
&
NETIF_F_DYNALLOC
)
{
#ifdef NET_REFCNT_DEBUG
#ifdef NET_REFCNT_DEBUG
if
(
atomic_read
(
&
dev
->
refcnt
)
!=
1
)
if
(
atomic_read
(
&
dev
->
refcnt
)
!=
1
)
printk
(
KERN_DEBUG
"unregister_netdevice: holding %s refcnt=%d
\n
"
,
dev
->
name
,
atomic_read
(
&
dev
->
refcnt
)
-
1
);
printk
(
KERN_DEBUG
"unregister_netdevice: holding %s "
"refcnt=%d
\n
"
,
dev
->
name
,
atomic_read
(
&
dev
->
refcnt
)
-
1
);
#endif
#endif
dev_put
(
dev
);
goto
out
;
return
0
;
}
}
/* Last reference is our one */
/* Last reference is our one */
if
(
atomic_read
(
&
dev
->
refcnt
)
==
1
)
{
if
(
atomic_read
(
&
dev
->
refcnt
)
==
1
)
dev_put
(
dev
);
goto
out
;
return
0
;
}
#ifdef NET_REFCNT_DEBUG
#ifdef NET_REFCNT_DEBUG
printk
(
"unregister_netdevice: waiting %s refcnt=%d
\n
"
,
dev
->
name
,
atomic_read
(
&
dev
->
refcnt
));
printk
(
KERN_DEBUG
"unregister_netdevice: waiting %s refcnt=%d
\n
"
,
dev
->
name
,
atomic_read
(
&
dev
->
refcnt
));
#endif
#endif
/* EXPLANATION. If dev->refcnt is not now 1 (our own reference)
/* EXPLANATION. If dev->refcnt is not now 1 (our own reference)
...
@@ -2617,14 +2622,15 @@ int unregister_netdevice(struct net_device *dev)
...
@@ -2617,14 +2622,15 @@ int unregister_netdevice(struct net_device *dev)
to this device and we cannot release it.
to this device and we cannot release it.
"New style" devices have destructors, hence we can return from this
"New style" devices have destructors, hence we can return from this
function and destructor will do all the work later.
As of kernel 2.4.0
function and destructor will do all the work later.
As of kernel
there are very few "New Style" devices.
2.4.0
there are very few "New Style" devices.
"Old style" devices expect that the device is free of any references
"Old style" devices expect that the device is free of any references
upon exit from this function.
upon exit from this function.
We cannot return from this function until all such references have
We cannot return from this function until all such references have
fallen away. This is because the caller of this function will probably
fallen away. This is because the caller of this function will
immediately kfree(*dev) and then be unloaded via sys_delete_module.
probably immediately kfree(*dev) and then be unloaded via
sys_delete_module.
So, we linger until all references fall away. The duration of the
So, we linger until all references fall away. The duration of the
linger is basically unbounded! It is driven by, for example, the
linger is basically unbounded! It is driven by, for example, the
...
@@ -2637,20 +2643,22 @@ int unregister_netdevice(struct net_device *dev)
...
@@ -2637,20 +2643,22 @@ int unregister_netdevice(struct net_device *dev)
now
=
warning_time
=
jiffies
;
now
=
warning_time
=
jiffies
;
while
(
atomic_read
(
&
dev
->
refcnt
)
!=
1
)
{
while
(
atomic_read
(
&
dev
->
refcnt
)
!=
1
)
{
if
((
jiffies
-
now
)
>
1
*
HZ
)
{
if
((
jiffies
-
now
)
>
1
*
HZ
)
{
/* Rebroadcast unregister notification */
/* Rebroadcast unregister notification */
notifier_call_chain
(
&
netdev_chain
,
NETDEV_UNREGISTER
,
dev
);
notifier_call_chain
(
&
netdev_chain
,
NETDEV_UNREGISTER
,
dev
);
}
}
current
->
state
=
TASK_INTERRUPTIBLE
;
current
->
state
=
TASK_INTERRUPTIBLE
;
schedule_timeout
(
HZ
/
4
);
schedule_timeout
(
HZ
/
4
);
current
->
state
=
TASK_RUNNING
;
current
->
state
=
TASK_RUNNING
;
if
((
jiffies
-
warning_time
)
>
10
*
HZ
)
{
if
((
jiffies
-
warning_time
)
>
10
*
HZ
)
{
printk
(
KERN_EMERG
"unregister_netdevice: waiting for
%s to
"
printk
(
KERN_EMERG
"unregister_netdevice: waiting for "
"
become free. Usage count = %d
\n
"
,
"%s to
become free. Usage count = %d
\n
"
,
dev
->
name
,
atomic_read
(
&
dev
->
refcnt
));
dev
->
name
,
atomic_read
(
&
dev
->
refcnt
));
warning_time
=
jiffies
;
warning_time
=
jiffies
;
}
}
}
}
out:
dev_put
(
dev
);
dev_put
(
dev
);
return
0
;
return
0
;
}
}
...
@@ -2764,7 +2772,7 @@ int __init net_dev_init(void)
...
@@ -2764,7 +2772,7 @@ int __init net_dev_init(void)
dev
->
ifindex
=
dev_new_index
();
dev
->
ifindex
=
dev_new_index
();
if
(
dev
->
iflink
==
-
1
)
if
(
dev
->
iflink
==
-
1
)
dev
->
iflink
=
dev
->
ifindex
;
dev
->
iflink
=
dev
->
ifindex
;
if
(
dev
->
rebuild_header
==
NULL
)
if
(
!
dev
->
rebuild_header
)
dev
->
rebuild_header
=
default_rebuild_header
;
dev
->
rebuild_header
=
default_rebuild_header
;
dev_init_scheduler
(
dev
);
dev_init_scheduler
(
dev
);
set_bit
(
__LINK_STATE_PRESENT
,
&
dev
->
state
);
set_bit
(
__LINK_STATE_PRESENT
,
&
dev
->
state
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment