Hello,

Can you please try attached patch to see if it works for you?
You have to revert patch 07/12 if you applied already to apply attached patch.

p.s I couldn't find a nice way to set ip address from kernel module
without patching kernel therefore you have to set ip address of your
device after configuring FromHost. (You won't be able to set it by
FromHost argument)
Setting ethernet address by FromHost argument should be still working.

Joonwoo.

On Tue, Nov 9, 2010 at 9:25 PM, Joonwoo Park <[email protected]> wrote:
> Hi,
>
> Thanks for call trace and simplified config.
> I should have allocated netdev_ops and assign it to dev->netdev_ops.
> It seem to me dev->netdev_ops is NULL.
> My bad.  I'll fix and submit new patch as soon as I have chance.
>
> Joonwoo
>
> On Tue, Nov 9, 2010 at 3:30 PM, Sascha Alexander Jopen
> <[email protected]> wrote:
>> Hi,
>>
>> i finally removed the mentioned 'false' requirement and the element was
>> compiled and integrated into the kernel module. When installing the
>> module with a click script using click-install, the module crashes with
>> a null pointer dereference, however. I didn't have the time to do
>> further tests with simpler click scripts. I will check this within the
>> next days.
>> Attached you will find the kernel call trace for this null pointer
>> dereference. The corresponding click part:
>>
>> AddressInfo(localDevice DEVNAME:ip/24 DEVNAME:eth);
>> FromHost(fake0, localDevice:ipnet, ETHER localDevice:eth, TYPE IP) -> ...
>>
>> DEVNAME will be replaced by an existing network device.
>> Maybe this is sufficient for someone to detect the problem.
>>
>> Sascha
>>
>> Am 09.11.2010 22:27, schrieb Sascha Alexander Jopen:
>>> Hello,
>>>
>>> the FromHost element simply does not exist after compiling. ToHost,
>>> ToHostSniffers and ToDevice, as well as FromDevice, are compiled,
>>> FromHost not.
>>> When feeding a click script to click-install the following error is emitted:
>>> <stdin>:144: unknown element class 'FromHost'
>>>
>>> fromhost.cc contains
>>> ELEMENT_REQUIRES(AnyDevice linuxmodule false)
>>> The 'false' requirement, may be this prevents compiling this element?
>>>
>>> Sascha
>>>
>>>
>>>
>>> Am 09.11.2010 22:06, schrieb Joonwoo Park:
>>>> Hi Sascha,
>>>>
>>>> I guess I'm not quite following FromHost issue here.
>>>>
>>>> Are you having build failure or any other problem?
>>>> When I submitted patchless patches, I also built and fixes FromHost
>>>> element and confirmed it's building.  I haven't tested element though.
>>>> Did you apply '07/12 FromHost: netdev_ops for linux 2.6.33+'?
>>>> http://www.mail-archive.com/[email protected]/msg04242.html
>>>>
>>>> Thanks,
>>>> Joonwoo
>>>>
>>>> On Tue, Nov 9, 2010 at 11:42 AM, Sascha Alexander Jopen
>>>> <[email protected]> wrote:
>>>>> Hey,
>>>>>
>>>>> i compiled for a recent kernel from ubuntu, namely 2.6.35-22-generic. I
>>>>> didn't apply your NETREG_REGISTERED patch, but it seems, everything
>>>>> compiled fine.
>>>>> I think this patch part is included in Joonwoos "[PATCH 04/12]
>>>>> Configury: prepend net_device namespace for NETREG_REGISTERED"
>>>>> As the enum in question is part of the net_device struct, everything
>>>>> should work as expected. Applying your patch leads to compiler errors on
>>>>> my system.
>>>>>
>>>>> So basically i am right, that FromHost is completely missing, currently?
>>>>> It would be nice, if someone could point me to the right direction. What
>>>>> is the problematic part in implementing this element?
>>>>>
>>>>> Regards,
>>>>> Sascha
>>>>>
>>>>> Am 09.11.2010 19:35, schrieb Roman Chertov:
>>>>>> Sascha,
>>>>>>
>>>>>> What kernel version did you use?  It appears that for 2.6.35 and above 
>>>>>> the
>>>>>> NETREG_REGISTERED fix is required as well.  If you start on updating 
>>>>>> FromHost, I
>>>>>> will be glad to give you a hand.
>>>>>>
>>>>>> Roman
>>>>>>
>>>>>>
>>>>>> On Fri, 05 Nov 2010 20:02:38 +0100 Sascha Alexander Jopen
>>>>>> <[email protected]> wrote
>>>>>>
>>>>>>> Hello,
>>>>>>>
>>>>>>> i tried click patchless today. I used those patches from Joonwoo, which
>>>>>>> didn't make it into the repository till now. Especially the patches to
>>>>>>> fixincludes and the configure scripts were necessary.
>>>>>>>
>>>>>>> It seems the FromHost element is not included during build. I know this
>>>>>>> was the last element which had to be done, but is it really still not
>>>>>>> finished? What are the missing parts for this element to work?
>>>>>>>
>>>>>>> We are using click userlevel and kernel level isn't really necessary but
>>>>>>> still nice to have. So maybe i could use some spare time to finish the
>>>>>>> FromHost element, if there isn't that much missing.
>>>>>>>
>>>>>>> Regards,
>>>>>>> Sascha Jopen
>>>>>>>
>>>>>>> On 11/03/10 17:42, Roman Chertov wrote:
>>>>>>>> This will also require Joonwoo's PATCH1/12.  It removes #include
>>>>>>>> <linux/autoconf.h>  from configure.in
>>>>>>>>
>>>>>>>> On Tue, 02 Nov 2010 18:44:32 -0700 "Roman 
>>>>>>>> Chertov"<[email protected]>
>>>>>>>> wrote
>>>>>>>>
>>>>>>>>> Hello,
>>>>>>>>>
>>>>>>>>> This works on Fedora 13 running 2.6.35.8 SMP kernel.  The second 
>>>>>>>>> patch is
>>>>>>>>> based
>>>>>>>>> on patches 2/12 and 3/12 that Joonwoo released.  I had to add the
>>>>>>>>> NETREG_REGISTERED patch due to scoping issues when an enum declared in
>>>>>>>>> net_device is used.  Otherwise, the code is same as in github master
>>>>>>>>> branch.
>>>>>>>>> I
>>>>>>>>> am not sure if there is a more elegant way to solve that issue.
>>>>>>>>>
>>>>>>>>> Roman
>>>>>>>>
>>>>>>>>
>>>>>>>> _______________________________________________
>>>>>>>> click mailing list
>>>>>>>> [email protected]
>>>>>>>> https://amsterdam.lcs.mit.edu/mailman/listinfo/click
>>>>>>>
>>>>>>> _______________________________________________
>>>>>>> click mailing list
>>>>>>> [email protected]
>>>>>>> https://amsterdam.lcs.mit.edu/mailman/listinfo/click
>>>>>>
>>>>>>
>>>>>
>>>>> _______________________________________________
>>>>> click mailing list
>>>>> [email protected]
>>>>> https://amsterdam.lcs.mit.edu/mailman/listinfo/click
>>>>>
>>>
>>> _______________________________________________
>>> click mailing list
>>> [email protected]
>>> https://amsterdam.lcs.mit.edu/mailman/listinfo/click
>>
>>
>> _______________________________________________
>> click mailing list
>> [email protected]
>> https://amsterdam.lcs.mit.edu/mailman/listinfo/click
>>
>>
>
From 7844c92ecf500a69641d8e80849b08579a853c2a Mon Sep 17 00:00:00 2001
From: Joonwoo Park <[email protected]>
Date: Sat, 13 Nov 2010 22:25:46 -0800
Subject: [PATCH] FromHost for pathchless linux.

---
 elements/linuxmodule/fromhost.cc |   99 ++++++++++++++++++++++++++++---------
 1 files changed, 75 insertions(+), 24 deletions(-)

diff --git a/elements/linuxmodule/fromhost.cc b/elements/linuxmodule/fromhost.cc
index 841c4d1..8b76672 100644
--- a/elements/linuxmodule/fromhost.cc
+++ b/elements/linuxmodule/fromhost.cc
@@ -35,6 +35,7 @@ CLICK_CXX_PROTECT
 #include <linux/ip.h>
 #include <linux/inetdevice.h>
 #include <linux/if_arp.h>
+#include <linux/etherdevice.h>
 #include <net/route.h>
 #include <net/dst.h>
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24)
@@ -72,6 +73,10 @@ static void fl_wakeup(Timer *, void *);
 
 static AnyDeviceMap fromlinux_map;
 
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 32)
+static struct net_device_ops fromhost_netdev_ops;
+#endif
+
 void
 FromHost::static_initialize()
 {
@@ -131,6 +136,7 @@ FromHost::new_device(const char *name)
     if (!dev)
 	return 0;
 
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 32)
 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0)
     setup(dev);
 #endif
@@ -138,8 +144,17 @@ FromHost::new_device(const char *name)
     dev->stop = fl_close;
     dev->hard_start_xmit = fl_tx;
     dev->get_stats = fl_stats;
+#else
+    fromhost_netdev_ops.ndo_open = fl_open;
+    fromhost_netdev_ops.ndo_stop = fl_close;
+    fromhost_netdev_ops.ndo_start_xmit = fl_tx;
+    fromhost_netdev_ops.ndo_get_stats = fl_stats;
+    fromhost_netdev_ops.ndo_set_mac_address = eth_mac_addr;
+    dev->netdev_ops = &fromhost_netdev_ops;
+#endif
     dev->mtu = _mtu;
     dev->tx_queue_len = 0;
+    dev->ifindex = -1;
     return dev;
 }
 
@@ -175,7 +190,11 @@ FromHost::configure(Vector<String> &conf, ErrorHandler *errh)
     // check for existing device
     _dev = AnyDevice::get_by_name(_devname.c_str());
     if (_dev) {
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 32)
 	if (_dev->open != fl_open) {
+#else
+	if (_dev->netdev_ops->ndo_open != fl_open) {
+#endif
 	    dev_put(_dev);
 	    _dev = 0;
 	    return errh->error("device '%s' already exists", _devname.c_str());
@@ -203,18 +222,29 @@ FromHost::configure(Vector<String> &conf, ErrorHandler *errh)
     _dev = new_device(_devname.c_str());
     if (!_dev)
 	return errh->error("out of memory! registering device '%s'", _devname.c_str());
-    else if ((res = register_netdev(_dev)) < 0) {
+    else {
+	// register_netdev ends up to call copy_rtnl_link_stats which
+	// requires valid net_device_stats structure, therefore device has to
+	// mapped before calling register_netdev
+	dev_hold(_dev);
+	fromlinux_map.insert(this, false);
+	if ((res = register_netdev(_dev))) {
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0)
-	free_netdev(_dev);
+	    free_netdev(_dev);
 #else
-	kfree(_dev);
+	    kfree(_dev);
 #endif
-	_dev = 0;
-	return errh->error("error %d registering device '%s'", res, _devname.c_str());
+	    dev_put(_dev);
+            fromlinux_map.remove(this, false);
+	    _dev = 0;
+	    return errh->error("error %d registering device '%s'", res, _devname.c_str());
+	} else {
+	    // _dev is in unknown_map
+	    fromlinux_map.remove(this, false);
+	    fromlinux_map.insert(this, false);
+	}
     }
 
-    dev_hold(_dev);
-    fromlinux_map.insert(this, false);
     return 0;
 }
 
@@ -225,34 +255,43 @@ FromHost::set_device_addresses(ErrorHandler *errh)
     struct ifreq ifr;
     strncpy(ifr.ifr_name, _dev->name, IFNAMSIZ);
     struct sockaddr_in *sin = (struct sockaddr_in *)&ifr.ifr_addr;
-
-#if HAVE_LINUX_DEV_IOCTL && HAVE_LINUX_DEVINET_IOCTL
-    mm_segment_t oldfs = get_fs();
-    set_fs(get_ds());
+    mm_segment_t oldfs;
 
     if (_macaddr) {
 	ifr.ifr_hwaddr.sa_family = _dev->type;
 	memcpy(ifr.ifr_hwaddr.sa_data, _macaddr.data(), 6);
-	if ((res = netdev_ioctl(_dev, SIOCSIFHWADDR, &ifr)) < 0)
-	    errh->error("error %d setting hardware address for device '%s'", res, _devname.c_str());
+#if HAVE_LINUX_DEV_IOCTL
+	oldfs = get_fs();
+	set_fs(get_ds());
+	res = netdev_ioctl(_dev, SIOCSIFHWADDR, &ifr);
+	set_fs(oldfs);
+#else
+	rtnl_lock();
+	res = dev_set_mac_address(_dev, &ifr.ifr_hwaddr);
+	rtnl_unlock();
+#endif
+	if (res)
+	    errh->error("error %d setting hardware address for device '%s'",
+			res, _devname.c_str());
     }
 
     if (_destaddr) {
+#if HAVE_LINUX_DEVINET_IOCTL
         sin->sin_family = AF_INET;
         sin->sin_addr = _destaddr;
+	oldfs = get_fs();
+	set_fs(get_ds());
         if (res >= 0 && (res = inetdev_ioctl(_dev, SIOCSIFADDR, &ifr)) < 0)
             errh->error("error %d setting address for device '%s'", res, _devname.c_str());
 
         sin->sin_addr = _destmask;
         if (res >= 0 && (res = inetdev_ioctl(_dev, SIOCSIFNETMASK, &ifr)) < 0)
             errh->error("error %d setting netmask for device '%s'", res, _devname.c_str());
-    }
-
-    set_fs(oldfs);
+	set_fs(oldfs);
 #else
-    if (_macaddr || _destaddr)
-	res = errh->error("cannot set addresses for FromHost devices on this kernel");
+	res = errh->error("cannot set ip address for FromHost devices on this kernel");
 #endif
+    }
 
     return res;
 }
@@ -263,7 +302,7 @@ dev_updown(net_device *dev, int up, ErrorHandler *errh)
     struct ifreq ifr;
     strncpy(ifr.ifr_name, dev->name, IFNAMSIZ);
     uint32_t flags = IFF_UP | IFF_RUNNING;
-    int res;
+    int res = -EINVAL;
 
 #if HAVE_LINUX_DEV_IOCTL
     mm_segment_t oldfs = get_fs();
@@ -276,11 +315,16 @@ dev_updown(net_device *dev, int up, ErrorHandler *errh)
 
     set_fs(oldfs);
 #else
-    if (errh)
-	errh->error("FromHost devices are not supported on this kernel");
-    res = -EINVAL;
+    rtnl_lock();
+    if ((res = dev_change_flags(dev, dev->flags | IFF_UP) < 0)) {
+	errh->error("error %d bringing %s device '%s'", res, (up > 0 ? "up" : "down"), dev->name);
+    }
+    rtnl_unlock();
 #endif
 
+    if (res)
+	errh->error("FromHost devices are not supported on this kernel");
+
     return res;
 }
 
@@ -376,8 +420,11 @@ fl_stats(net_device *dev)
 {
     net_device_stats *stats = 0;
     unsigned long lock_flags;
+    FromHost *fl;
     fromlinux_map.lock(false, lock_flags);
-    if (FromHost *fl = (FromHost *)fromlinux_map.lookup(dev, 0))
+    if (fl = (FromHost *)fromlinux_map.lookup(dev, 0))
+	stats = fl->stats();
+    else if (fl = (FromHost *)fromlinux_map.lookup_unknown(dev, 0))
 	stats = fl->stats();
     fromlinux_map.unlock(false, lock_flags);
     return stats;
@@ -410,10 +457,14 @@ FromHost::fl_tx(struct sk_buff *skb, net_device *dev)
 #if HAVE_SKB_DST_DROP
 	    skb_dst_drop(skb);
 #else
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 35)
 	    if (skb->dst) {
 		dst_release(skb->dst);
 		skb->dst = 0;
 	    }
+#else
+	    dst_release(skb_dst(skb));
+#endif
 #endif
 
 	    Packet *p = Packet::make(skb);
@@ -499,5 +550,5 @@ FromHost::add_handlers()
     add_data_handlers("drops", Handler::OP_READ, &_drops);
 }
 
-ELEMENT_REQUIRES(AnyDevice linuxmodule false)
+ELEMENT_REQUIRES(AnyDevice linuxmodule)
 EXPORT_ELEMENT(FromHost)
-- 
1.7.1

_______________________________________________
click mailing list
[email protected]
https://amsterdam.lcs.mit.edu/mailman/listinfo/click

Reply via email to