Virtual device driver programming

2006-06-23 Thread Johnny Choque
Hi all,

I'm interested in programming a virtual network device driver -Linux
concept- on a FreeBSD box. The idea behind of this sort of interface is the
following:

From the kernel's point of view, a network interface is a software object
that can process outgoing packets, and the actual transmission mechanism
remains hidden inside the interface driver. Even though most interfaces are
associated to physical devices (or, for the loopback interface, to a
software-only data loop), it is possible to design network interface drivers
that rely on other interfaces to perform actual packet transmission. The
idea of a ``virtual'' interface can be useful to implement special-purpose
processing on data packets while avoiding to hack with the network subsystem
of the kernel.

I know that is not too complicated to program this sort of functionality in
linux but I would like to do it over freebsd, has anybody some idea on how
could I start doing it? I've been searching in the freebsd handbook but I
haven't found anything really relevant.

Regards,

Johnny

PS: You can find more information about virtual network device driver in the
following link:
http://www.linux.it/~rubini/docs/vinter/vinter.html


___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: Virtual device driver programming

2006-06-23 Thread Dmitry Pryanishnikov


Hello!

On Fri, 23 Jun 2006, Johnny Choque wrote:

I'm interested in programming a virtual network device driver -Linux
concept- on a FreeBSD box. The idea behind of this sort of interface is the
following:

From the kernel's point of view, a network interface is a software object
that can process outgoing packets, and the actual transmission mechanism
remains hidden inside the interface driver. Even though most interfaces are
associated to physical devices (or, for the loopback interface, to a
software-only data loop), it is possible to design network interface drivers
that rely on other interfaces to perform actual packet transmission. The
idea of a ``virtual'' interface can be useful to implement special-purpose
processing on data packets while avoiding to hack with the network subsystem
of the kernel.


 Isn't this exactly the same thing that FreeBSD's Netgraph subsystem does?

man 4 netgraph


Sincerely, Dmitry
--
Atlantis ISP, System Administrator
e-mail:  [EMAIL PROTECTED]
nic-hdl: LYNX-RIPE
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: Virtual device driver programming

2006-06-23 Thread Robert Watson


On Fri, 23 Jun 2006, Johnny Choque wrote:

I'm interested in programming a virtual network device driver -Linux 
concept- on a FreeBSD box. The idea behind of this sort of interface is the 
following:


From the kernel's point of view, a network interface is a software object 
that can process outgoing packets, and the actual transmission mechanism 
remains hidden inside the interface driver. Even though most interfaces are 
associated to physical devices (or, for the loopback interface, to a 
software-only data loop), it is possible to design network interface drivers 
that rely on other interfaces to perform actual packet transmission. The 
idea of a ``virtual'' interface can be useful to implement special-purpose 
processing on data packets while avoiding to hack with the network subsystem 
of the kernel.


I know that is not too complicated to program this sort of functionality in 
linux but I would like to do it over freebsd, has anybody some idea on how 
could I start doing it? I've been searching in the freebsd handbook but I 
haven't found anything really relevant.


tap(4) and tun(4) describe pseudo-devices you can use to instantiate ethernet 
and tunnel interfaces from user space.  Programs attach to pseudo-devices, and 
using read/write operations on the pseudo-device, can receive and generate 
packets on the network interface.  In kernel, the ifnet(9) API is used to 
implement network interfaces -- nothing in the API requires that the 
under-side of a network interface be hardware.  In fact, a great many network 
types without underlying hardware have been implemented, including the 
loopback interface, encapsulation interfaces, and the tap/tun interface 
drivers.


Robert N M Watson
Computer Laboratory
University of Cambridge
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to [EMAIL PROTECTED]


Simple question about mmap() system call

2006-06-23 Thread Dmitry Pryanishnikov


Hello!

 I'm writing an utility that should examine some bytes of a large file
and modify them - that't all. I've decided to mmap() the file:

void *diskp;

if ((fd=open(argv[1], O_RDWR)) == -1)
err(EX_NOINPUT, Can't open %s for readind and writing, argv[1]);

if ((diskp=mmap(NULL, 512,
PROT_READ | PROT_WRITE, 0, fd, 0)) == MAP_FAILED)
err(EX_IOERR, Can't mmap() file);

printf(%c\n,* (char *)diskp);
* (char *)diskp = '!';

if (msync(diskp, 0, MS_SYNC) || close(fd))
err(EX_IOERR, Error closing file);

All proceeds w/o errors with the sample (2 bytes long) file, printf()
shows actual first byte of my file. But modification doesn't get written back 
to the disk, file contents are unchanged after execution of my code. I'm sure 
I'm overlooking something very basic and stupid, but can't find what exactly.


Sincerely, Dmitry
--
Atlantis ISP, System Administrator
e-mail:  [EMAIL PROTECTED]
nic-hdl: LYNX-RIPE
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: Simple question about mmap() system call

2006-06-23 Thread Stanislav Sedov
On Fri, 23 Jun 2006 17:47:57 +0300 (EEST)
Dmitry Pryanishnikov [EMAIL PROTECTED] wrote:

 Hello!
 
   I'm writing an utility that should examine some bytes of a large file
 and modify them - that't all. I've decided to mmap() the file:
 
  void *diskp;
 
  if ((fd=open(argv[1], O_RDWR)) == -1)
  err(EX_NOINPUT, Can't open %s for readind and writing, argv[1]);
 
  if ((diskp=mmap(NULL, 512,
  PROT_READ | PROT_WRITE, 0, fd, 0)) == MAP_FAILED)
  err(EX_IOERR, Can't mmap() file);
 
  printf(%c\n,* (char *)diskp);
  * (char *)diskp = '!';
 
  if (msync(diskp, 0, MS_SYNC) || close(fd))
  err(EX_IOERR, Error closing file);
 
 All proceeds w/o errors with the sample (2 bytes long) file, printf()
 shows actual first byte of my file. But modification doesn't get written back 
 to the disk, file contents are unchanged after execution of my code. I'm sure 
 I'm overlooking something very basic and stupid, but can't find what exactly.
 

munmap(2)?

-- 
Stanislav Sedov MBSD labs, Inc. [EMAIL PROTECTED]
Россия, Москва  http://mbsd.msk.ru


If the facts don't fit the theory, change the facts.  -- A. Einstein

PGP fingerprint:  F21E D6CC 5626 9609 6CE2  A385 2BF5 5993 EB26 9581


pgp0H2fDxyodw.pgp
Description: PGP signature


Buses, devices and modules

2006-06-23 Thread Artem Ignatiev

Hi all, I have a question regarding probe and attach routines.

I've got 2 modules: for bus (mybus.ko) and for device (mydev.ko) on  
that bus.


mydev.ko has
MODULE_DEPEND(mydev, mybus, 1, 1, 1);

When kldloading mydev.ko, mybus.ko is loading automatically, then it  
founds its device, attaches properly, and mydev.ko after that founds  
its own device, and attaches to the bus, and all works fine.


When I do 'echo mydev_load=YES /boot/loader.conf', loader loads  
both mydev.ko and mybus.ko, and mybus.ko attaches properly, but  
mydev.ko don't attach to anything.


I suppose this happens because mydev happens to probe for devices  
before mybus creates them, and fails to find anything to attach to.


I'm looking for way to trigger the mydev driver to re-probe after the  
mybus driver actually creates the devices, or may be I'm missing  
something simple (like priority of module probing)?

___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: Simple question about mmap() system call

2006-06-23 Thread Dan Nelson
In the last episode (Jun 23), Dmitry Pryanishnikov said:
  I'm writing an utility that should examine some bytes of a large
 file and modify them - that't all. I've decided to mmap() the file:
 
 void *diskp;
 
 if ((fd=open(argv[1], O_RDWR)) == -1)
 err(EX_NOINPUT, Can't open %s for readind and writing, argv[1]);
 
 if ((diskp=mmap(NULL, 512,
 PROT_READ | PROT_WRITE, 0, fd, 0)) == MAP_FAILED)
 err(EX_IOERR, Can't mmap() file);

Try adding MAP_SHARED.  mmap defaults to private mappings, which means
you changes don't get synched back to disk.

I wonder how many programs would break if the mmap syscall returned an
error if neither MAP_PRIVATE or MAP_SHARED were set...

-- 
Dan Nelson
[EMAIL PROTECTED]
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: Simple question about mmap() system call

2006-06-23 Thread Dmitry Pryanishnikov


Hello!

On Fri, 23 Jun 2006, Konstantin Belousov wrote:

if ((diskp=mmap(NULL, 512,
PROT_READ | PROT_WRITE, 0, fd, 0)) == MAP_FAILED)
err(EX_IOERR, Can't mmap() file);

shows actual first byte of my file. But modification doesn't get written
back to the disk, file contents are unchanged after execution of my code.
I'm sure I'm overlooking something very basic and stupid, but can't find
what exactly.

You forgot MAP_SHARED.


 Thank you! Yes, that's it. I would say that it's description

 MAP_SHAREDModifications are shared.

is rather terse and doesn't explicitly says that w/o it data will not be
stored back to the mmapped object. One can only deduce this behaviour,
and deduction sometimes fails at the end of working day ;)


Sincerely, Dmitry
--
Atlantis ISP, System Administrator
e-mail:  [EMAIL PROTECTED]
nic-hdl: LYNX-RIPE
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: Virtual device driver programming

2006-06-23 Thread Julian Elischer

Robert Watson wrote:



On Fri, 23 Jun 2006, Johnny Choque wrote:

I'm interested in programming a virtual network device driver -Linux 
concept- on a FreeBSD box. The idea behind of this sort of interface 
is the following:


From the kernel's point of view, a network interface is a software 
object that can process outgoing packets, and the actual transmission 
mechanism remains hidden inside the interface driver. Even though 
most interfaces are associated to physical devices (or, for the 
loopback interface, to a software-only data loop), it is possible to 
design network interface drivers that rely on other interfaces to 
perform actual packet transmission. The idea of a ``virtual'' 
interface can be useful to implement special-purpose processing on 
data packets while avoiding to hack with the network subsystem of the 
kernel.


I know that is not too complicated to program this sort of 
functionality in linux but I would like to do it over freebsd, has 
anybody some idea on how could I start doing it? I've been searching 
in the freebsd handbook but I haven't found anything really relevant.



tap(4) and tun(4) describe pseudo-devices you can use to instantiate 
ethernet and tunnel interfaces from user space.  Programs attach to 
pseudo-devices, and using read/write operations on the pseudo-device, 
can receive and generate packets on the network interface.  In kernel, 
the ifnet(9) API is used to implement network interfaces -- nothing in 
the API requires that the under-side of a network interface be 
hardware.  In fact, a great many network types without underlying 
hardware have been implemented, including the loopback interface, 
encapsulation interfaces, and the tap/tun interface



drivers.


there is also gif(4) as well

and if that is not enough the netgraph system gives you a toolkit to 
make your own kernel based

virtual network interfaces.
(ng_iface, ng_ether, ng_eiface (and others))


Robert N M Watson
Computer Laboratory
University of Cambridge
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to 
[EMAIL PROTECTED]


___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to [EMAIL PROTECTED]


mmap() vs. character special file

2006-06-23 Thread Dmitry Pryanishnikov


Hello!

 mmap(2) manpage has the following title:

NAME
 mmap -- allocate memory, or map files or devices into memory

I'm curious about mmap()ing devices (particularly, HDD slices). The manpage
mentions character special files only once:

 [EINVAL]   MAP_ANON has not been specified and fd did not refer-
ence a regular or character special file.

So it looks like one should be able to mmap() a character special file (w/o 
MAP_ANON, of course). However, if I try to issue:


if ((fd=open(argv[1], O_RDWR)) == -1)
err(EX_NOINPUT, Can't open %s for readind and writing, argv[1]);

if ((diskp=mmap(NULL, label_offset + sizeof (struct disklabel),
PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0)) == MAP_FAILED)
err(EX_IOERR, Can't mmap() file);

against /dev/adXsY (adXsY and adXsYZ are _not_ mounted), I'm getting EINVAL
from mmap(). Is mmap()ping a disk slice/partition impossible by design, or it
just isn't implemented yet? IMHO manpage doesn't reply to this question.

Sincerely, Dmitry
--
Atlantis ISP, System Administrator
e-mail:  [EMAIL PROTECTED]
nic-hdl: LYNX-RIPE
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: mmap() vs. character special file

2006-06-23 Thread Stanislav Sedov
On Sat, 24 Jun 2006 01:27:05 +0300 (EEST)
Dmitry Pryanishnikov [EMAIL PROTECTED] wrote:

 Hello!
 
   mmap(2) manpage has the following title:
 
 NAME
   mmap -- allocate memory, or map files or devices into memory
 
 I'm curious about mmap()ing devices (particularly, HDD slices). The manpage
 mentions character special files only once:
 
   [EINVAL]   MAP_ANON has not been specified and fd did not refer-
  ence a regular or character special file.
 
 So it looks like one should be able to mmap() a character special file (w/o 
 MAP_ANON, of course). However, if I try to issue:
 
  if ((fd=open(argv[1], O_RDWR)) == -1)
  err(EX_NOINPUT, Can't open %s for readind and writing, argv[1]);
 
  if ((diskp=mmap(NULL, label_offset + sizeof (struct disklabel),
  PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0)) == MAP_FAILED)
  err(EX_IOERR, Can't mmap() file);
 
 against /dev/adXsY (adXsY and adXsYZ are _not_ mounted), I'm getting EINVAL
 from mmap(). Is mmap()ping a disk slice/partition impossible by design, or it
 just isn't implemented yet? IMHO manpage doesn't reply to this question.
 

You cannot mmap ata devices (as well as scsi ones), since mmap functions
was not implemented. Actually, only few devices have such support
(e.g. drm, bktr).

mmap requires device to return pointer to contigues memory range - 
drm, for example, returns pointer to physical memory of the graphical
adapter.

Implementing mmap for disk devices involves complicated VM intercations,
since you cannot simply return pointer to physical memory. Actually,
implementing mmap, IMHO, doesn't worth efforts to do this.

-- 
Stanislav Sedov MBSD labs, Inc. [EMAIL PROTECTED]
Россия, Москва  http://mbsd.msk.ru


If the facts don't fit the theory, change the facts.  -- A. Einstein

PGP fingerprint:  F21E D6CC 5626 9609 6CE2  A385 2BF5 5993 EB26 9581


pgppOzxyCuGx9.pgp
Description: PGP signature