discuss-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Discuss-gnuradio] TunTap device problem in GRC


From: Josh Blum
Subject: Re: [Discuss-gnuradio] TunTap device problem in GRC
Date: Fri, 17 Oct 2008 17:23:23 -0400
User-agent: Thunderbird 2.0.0.0 (X11/20070326)

I pasted the relevant code below so we can reference its mystery hex number.

The tun tap block in grc takes code from the tun tap example to open a tun tap file descriptor. The file descriptor is fed into a file descriptor source and sink. From the outside of the tun tap block, we see the input to the file descriptor sink and the output of the file descriptor source.

GRC will try to exec ifconfig on the tun tap device name, if an ip address is specified. You can manually run ifconfig as well. I dont think this is the problem.

Should this work in linux? Maybe.

Should this work in mac os? Possibilities are even worse: those hard coded hex values, they probably have header file constants that change numeric value from linux to freebsd.

This could be helpful:
http://alex.king.net.nz/tuntap.html

Relevant Code from 0.70:

#######################################################################################
##      TUN/TAP
#######################################################################################

IFF_TUN         = 0x0001   # tunnel IP packets
IFF_TAP         = 0x0002   # tunnel ethernet frames
IFF_NO_PI       = 0x1000   # don't pass extra packet info
IFF_ONE_QUEUE   = 0x2000   # beats me ;)
DEFAULT_TUN_DEVICE = '/dev/net/tun'
DEFAULT_VIRTUAL_DEVICE = 'tun%d'
DEFAULT_IP_ADDR = '10.0.0.1'

def open_tun_interface(tun_device_filename=DEFAULT_TUN_DEVICE, virtual_device_filename=DEFAULT_VIRTUAL_DEVICE):
        """!
        Open a virtual ethernet interface via the Tun/Tap framework.
An alternative function can be found: "from eunuchs.tuntap import opentuntap"
        @param tun_device_filename the path to the tun device
@param virtual_device_filename the name of the virtual device (to be created) @return a file descriptor to rw the device, name of the virtual device (created)
        """
        from fcntl import ioctl
        mode = IFF_TAP | IFF_NO_PI
        TUNSETIFF = 0x400454ca
        tun_fd = os.open(tun_device_filename, os.O_RDWR)
ifs = ioctl(tun_fd, TUNSETIFF, struct.pack("16sH", virtual_device_filename, mode))
        ifname = ifs[:16].strip("\x00")
        return tun_fd, ifname

class TunTapHelper(gr.hier_block2):
        """Make the tun tap hier2 block."""
        def __init__(self, item_size, tun_fd):
                """!
                TunTapHelper constructor.
                @param item_size the size in bytes of the IO data stream
                @param tun_fd the file descriptor for the virtual device
                """
                #create hier block
                gr.hier_block2.__init__(
                        self, 'tun_tap',
                        gr.io_signature(1, 1, item_size),
                        gr.io_signature(1, 1, item_size)
                )
                #I/O blocks
                sink = gr.file_descriptor_sink(item_size, tun_fd)
                source = gr.file_descriptor_source(item_size, tun_fd)
                #connect
                self.connect(self, sink)
                self.connect(source, self)              

def TunTap(sb):
        gr.file_descriptor_sink, gr.file_descriptor_source      #uses
        type = Enum(all_choices, 1)
        sb.add_input_socket('in', Variable(type))
        sb.add_output_socket('out', Variable(type))             
        sb.add_param('Type', type, False, type=True)
        sb.add_param('Tun Device', String(DEFAULT_TUN_DEVICE))
        sb.add_param('Virtual Device', String(DEFAULT_VIRTUAL_DEVICE))
        sb.add_param('IP Address', String(DEFAULT_IP_ADDR))
        sb.set_docs('''\
Foward data between gnuradio and a virtual ethernet interface.
---
Tun Device: File path to the tun device.

Virtual Device: Desired name for the virtual ethernet device. \
"%d" will give the device a number starting at zero.

IP Address: IP address for the virtual device, leave blank and device will not be configured.
''')
        def make(fg, type, tun, virt, ip_addr):
                item_size = type.parse().get_num_bytes()
                tun_fd, ifname = open_tun_interface(tun.parse(), virt.parse())
                #try to set the ip address
                ip_addr = ip_addr.parse()
                if ip_addr: os.system('ifconfig %s %s'%(ifname, ip_addr))
                return TunTapHelper(item_size, tun_fd)
        return sb, make


Ed Criscuolo wrote:
Has anybody had any luck using the Tun/Tap device in GRC?

I've tried it with GRC 0.70 and 0.69 under Fedora 8, and
GRC 0.69 under Mac OSX and had no luck, even when running
everything as root.

Under OSX 10.4, I installed Mattias Nissler's tun/tap driver
( http://tuntaposx.sourceforge.net/ ) dated 2008-Aug-4. It
creates all the /dev/tun<x> and /dev/tap<x> devices
right away, and doesn't seem to have the /dev/net/tun
master device. (Michael Dickens, have you had any experience
with the tun/tap driver on OSX?) Trying to use the
/dev/tun0 in place of /dev/net/tun predictably failed,
producing

ifs = ioctl(tun_fd, TUNSETIFF, struct.pack("16sH", virtual_device_filename, mode))
IOError: [Errno 25] Inappropriate ioctl for device

----

Under Fedora 8, with either GRC 0.69 or 0.70, things
went a little better, but not much.  With the following
flow graph


----------      ----------------------    -----------
|        |      |   Tun/Tap          |    |         |
| Vector |----->| Dev = /dev/net/tun |--->|  File   |
| Source |      | Virt Dev = tun%d   |    |  Sink   |
|        |      | IP addr = 10.0.0.1 |    |         |
----------      ----------------------    -----------

things ran without error and the net pseudo-device "tun0"
was created, but an ifconfig showed that no IP address
was assigned to it. I successfully used ifconfig to
assign address 10.0.0.1 to it, and sent packets to
that address, but nothing was captured in the file.
And another 'ifconfig tun0' showed that no new TX bytes
had been sent out the interface.

Is there an error in GRC that results in the IP address
not being assigned?  And why didn't my packets get there
when there WAS an address assigned?

@(^.^)@  Ed


_______________________________________________
Discuss-gnuradio mailing list
address@hidden
http://lists.gnu.org/mailman/listinfo/discuss-gnuradio





reply via email to

[Prev in Thread] Current Thread [Next in Thread]