Subject: Re: How to add if-IOCTL?
To: Heiko W.Rupp <>
From: Bill Studenmund <>
List: tech-net
Date: 08/06/1998 10:48:06
> I am not sure, if I am right on tech-net ...
> suppose, I want to add an IOCTL to e.g. enable debuggin of interface
> lo0. (e.g.   ioctl(s,DEBUGLO0,(struct ifreq *)), where the struct
> ifreq * contians as name field "lo0".

I think what you need to do is bind a socket to that interface (I'm not
exactly sure how to do this) and then do the ioctl.

You realize that the argument passed to the ioctl, the ifreq structure
in your example above, is an argument for the ioctl routine? I.E. your
code in the lo0 source will receive it. As this source is in if_loop.c,
I don't see why you need to pass it the name of its interface.

> What is there needed at what part of the kernel(-source) to add this new
> DEBUGLO0 ioctl to allow if_loop.c in its loioctl() routine to use
> this new one?

I think the only file which will need changing is net/if_loop.c, in its
ioctl processing routine.

> And no, I don't want to install some /dev/<if> devices and use these
> for communication if not absolutely necessary (which shold not be in
> my understanding).

Right. Network interfaces don't have /def/ files, which is really only
a problem if you want to do something to the interface and not the
communications flowing through it.

> Why are some of the get-ioctls in sys/sockio.h modelled as _IOR()
> and others as _IOWR() (SIOCGETVIFCNT vs SIOCGPGRP)?

_IOR ioctls only pass in arguments, _IOW ones pass out arguments, and
_IOWR ones pass both in and out arguments.

Take care,