mbox series

[iproute2-next,0/4] ip: Introduce and use helper to read /proc/net/dev

Message ID 1517428189-29279-1-git-send-email-serhe.popovych@gmail.com
Headers show
Series ip: Introduce and use helper to read /proc/net/dev | expand

Message

Serhey Popovych Jan. 31, 2018, 7:49 p.m. UTC
Currently there is two places in ip(8) where /proc/net/dev is read line
by line with nearly identical steps: iptunnel.c and ip6tunnel.c

On the other hand we have iptuntap.c that uses /sys/class/net that could
be problematic in case of unshare(1)d network namespace without sysfs
being mounted.

Introduce and use do_each_proc_net_dev() helper to read data from
/proc/net/dev line by line and pass this information to implementation
specific callback function.

See individual patch description message for more details.

Series is open for reviews and comments.

Tested only by compiling and executing ip [-46] [-s] [-d] tunnel in
various combinations: no problem so far. More can be done by request.

Thanks,
Serhii

Serhey Popovych (4):
  utils: Introduce do_each_proc_net_dev() helper
  iptunnel: Use do_each_proc_net_dev()
  ip6tunnel: Use do_each_proc_net_dev()
  tuntap: Use do_each_proc_net_dev()

 include/utils.h |   10 ++++++
 ip/ip6tunnel.c  |   94 ++++++++++++++++++++------------------------------
 ip/iptunnel.c   |  102 +++++++++++++++++++++++++------------------------------
 ip/iptuntap.c   |   59 ++++++++++++++------------------
 lib/utils.c     |   51 ++++++++++++++++++++++++++++
 5 files changed, 170 insertions(+), 146 deletions(-)

Comments

Stephen Hemminger Jan. 31, 2018, 11:04 p.m. UTC | #1
On Wed, 31 Jan 2018 21:49:45 +0200
Serhey Popovych <serhe.popovych@gmail.com> wrote:

> Currently there is two places in ip(8) where /proc/net/dev is read line
> by line with nearly identical steps: iptunnel.c and ip6tunnel.c
> 
> On the other hand we have iptuntap.c that uses /sys/class/net that could
> be problematic in case of unshare(1)d network namespace without sysfs
> being mounted.
> 
> Introduce and use do_each_proc_net_dev() helper to read data from
> /proc/net/dev line by line and pass this information to implementation
> specific callback function.
> 
> See individual patch description message for more details.
> 
> Series is open for reviews and comments.
> 
> Tested only by compiling and executing ip [-46] [-s] [-d] tunnel in
> various combinations: no problem so far. More can be done by request.
> 
> Thanks,
> Serhii
> 
> Serhey Popovych (4):
>   utils: Introduce do_each_proc_net_dev() helper
>   iptunnel: Use do_each_proc_net_dev()
>   ip6tunnel: Use do_each_proc_net_dev()
>   tuntap: Use do_each_proc_net_dev()
> 
>  include/utils.h |   10 ++++++
>  ip/ip6tunnel.c  |   94 ++++++++++++++++++++------------------------------
>  ip/iptunnel.c   |  102 +++++++++++++++++++++++++------------------------------
>  ip/iptuntap.c   |   59 ++++++++++++++------------------
>  lib/utils.c     |   51 ++++++++++++++++++++++++++++
>  5 files changed, 170 insertions(+), 146 deletions(-)
> 

/proc/net/dev is legacy and unextensible.

I would rather see netlink used everywhere and not /proc/net/dev or sysfs!
David Ahern Feb. 1, 2018, 3:17 a.m. UTC | #2
On 1/31/18 4:04 PM, Stephen Hemminger wrote:
> 
> /proc/net/dev is legacy and unextensible.
> 
> I would rather see netlink used everywhere and not /proc/net/dev or sysfs!
> 

agreed. ll_init_map is already called in some places so a device cache
already exists.
Serhey Popovych Feb. 1, 2018, 7:49 p.m. UTC | #3
Stephen Hemminger wrote:
> On Wed, 31 Jan 2018 21:49:45 +0200
> Serhey Popovych <serhe.popovych@gmail.com> wrote:
> 
>> Currently there is two places in ip(8) where /proc/net/dev is read line
>> by line with nearly identical steps: iptunnel.c and ip6tunnel.c
>>
>> On the other hand we have iptuntap.c that uses /sys/class/net that could
>> be problematic in case of unshare(1)d network namespace without sysfs
>> being mounted.
>>
>> Introduce and use do_each_proc_net_dev() helper to read data from
>> /proc/net/dev line by line and pass this information to implementation
>> specific callback function.
>>
>> See individual patch description message for more details.
>>
>> Series is open for reviews and comments.
>>
>> Tested only by compiling and executing ip [-46] [-s] [-d] tunnel in
>> various combinations: no problem so far. More can be done by request.
>>
>> Thanks,
>> Serhii
>>
>> Serhey Popovych (4):
>>   utils: Introduce do_each_proc_net_dev() helper
>>   iptunnel: Use do_each_proc_net_dev()
>>   ip6tunnel: Use do_each_proc_net_dev()
>>   tuntap: Use do_each_proc_net_dev()
>>
>>  include/utils.h |   10 ++++++
>>  ip/ip6tunnel.c  |   94 ++++++++++++++++++++------------------------------
>>  ip/iptunnel.c   |  102 +++++++++++++++++++++++++------------------------------
>>  ip/iptuntap.c   |   59 ++++++++++++++------------------
>>  lib/utils.c     |   51 ++++++++++++++++++++++++++++
>>  5 files changed, 170 insertions(+), 146 deletions(-)
>>
> 
> /proc/net/dev is legacy and unextensible.
> 
> I would rather see netlink used everywhere and not /proc/net/dev or sysfs!
> 

Look at my RFC series against iproute2-next with cover letter subject:
"ip: Use netlink to walk through network device list".

Thanks,
Serhii