Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 1 Oct 2001 13:30:19 -0500
From:      Jonathan Lemon <jlemon@flugsvamp.com>
To:        Guido van Rooij <guido@gvr.org>
Cc:        Jonathan Lemon <jlemon@flugsvamp.com>, hackers@freebsd.org
Subject:   Re: cvs commit: src/sys/conf majors src/sys/net if.c
Message-ID:  <20011001133019.A12292@prism.flugsvamp.com>
In-Reply-To: <20011001202223.A57173@gvr.gvr.org>
References:  <local.mail.freebsd-committers/200109290555.f8T5t4t68441@freefall.freebsd.org> <200109290555.f8T5tCu17458@prism.flugsvamp.com> <20011001202223.A57173@gvr.gvr.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On Mon, Oct 01, 2001 at 08:22:23PM +0200, Guido van Rooij wrote:
> On Sat, Sep 29, 2001 at 12:55:12AM -0500, Jonathan Lemon wrote:
> > In article <local.mail.freebsd-committers/200109290555.f8T5t4t68441@freefall.freebsd.org> you write:
> > >jlemon      2001/09/28 22:55:04 PDT
> > >
> > >  Modified files:
> > >    sys/conf             majors 
> > >    sys/net              if.c 
> > >  Log:
> > >  Introduce network device nodes.  Network devices will now automatically
> > >  appear in /dev.  Interface hardware ioctls (not protocol or routing) can
> > >  be performed on the descriptor.  The SIOCGIFCONF ioctl may be performed
> > >  on the special /dev/network node.
> > 
> > The semantics of read/write on the node are currently undefined,
> > discussion on their appropriate behavior (if any) is invited.
> > This commit is the precursor for some additional features which
> > require a dev_t/filehandle for their operation (e.g.: kqueue support).
> 
> Cool. I did a presentation abt kqueue and added a slide with just something
> like this.
> 
> What I would, among other be interested in was media changes and errors.
> I alos here people talk about BPF stuff.
> Perhaps there should be a node and a control node...

Right now, there is /dev/network, which is intended as a control node.
One possibility would be to use this to provde a central place to do 
general operations like device cloning.  Another possibility would have
have network node changes (addition, removal) reported here, although
this probably wants some sort of central devd mechanism, rather than
restricting it to network devices only.   

As for link up/down events, try the small sample program attached.
I'm not quite satisfied with the behavior yet; there should be a way
to get the inital status of the link as well as link changes, but it 
is a start.
-- 
Jonathan

#include <stdio.h>
#include <fcntl.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/signal.h>
#include <sys/time.h>
#include <sys/errno.h>
#include <sys/types.h>
#include <sys/event.h>

int
main(int argc, char **argv)
{
	int fd, kq, n;
	struct kevent event[2];
	char buffer[128];
	struct timespec nullts = { 0, 0 };
	int fdout = 1;

	if (argc != 2)
		errx(1, "Usage: %s net_device\n", argv[0]);

	fd = open(argv[1], O_RDWR);
	if (fd == -1)
		err(1, "open(%s)", argv[1]);
	
        kq = kqueue();
        if (kq < 0)
                err(1, "kqueue");

	EV_SET(&event[0], fd, EVFILT_NETDEV, EV_ADD | EV_CLEAR,
	    NOTE_LINKUP | NOTE_LINKDOWN | NOTE_LINKINV, 0, 0);
	n = kevent(kq, event, 1, NULL, 0, &nullts);
	if (n == -1)
		err(1, "kevent");
	
	for (;;) {
		n = kevent(kq, NULL, 0, event, 1, NULL);
		if (n < 0)
			err(1, "kevent");
		printf("fflags: 0x%x\n", event[0].fflags);
		printf("Link");
		if (event[0].fflags & NOTE_LINKUP)
			printf(" up");
		if (event[0].fflags & NOTE_LINKDOWN)
			printf(" down");
		if (event[0].fflags & NOTE_LINKINV)
			printf(" indeterminate");
		printf("\n");
	}

	return (0);
}

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20011001133019.A12292>