[Xorp-users] Question on supporting multiple routing tables [PATCH]

Ben Greear greearb at candelatech.com
Tue Sep 4 15:55:09 PDT 2007


I attempted to change my patch per your (off-list) comments,
basically to only bind when non-multicast and then immediately
un-bind.  Unfortunately, it appears that the Linux kernel logic
to un-bind does not work.  I sent a mail to the kernel mailing
list, so hopefully it can be fixed sometime soon (or I can be
properly beat around the head if it's my mistake.)

In the meantime, I think we will need to stick with something
similar to my previous patch that always binds, even when
sending multicast pkts.

For posterity's sake, here is my patch with the attempted un-binding
logic.  Please note that the un-binding logic is NOT following what the 'man 7 socket'
indicates is the proper method (zero-length optlen), but zero-length optlen
is not supported in Linux in 2.6.22 at least.
Do NOT apply this, as it doesn't work.

I will follow up in a new email with a working patch based on the previous
patch but w/out the commented out debugging code.

[greearb at file-server io]$ cvs diff
cvs diff: Diffing .
Index: io_ip_socket.cc
===================================================================
RCS file: /cvs/xorp/fea/data_plane/io/io_ip_socket.cc,v
retrieving revision 1.11
diff -r1.11 io_ip_socket.cc
2349a2350,2355
 > #ifdef SO_BINDTODEVICE
 >     // NOTE:  DO NOT RETURN from this method until the very end.  Set return
 >     // value properly and 'goto out' instead.  This way we are certain to unbind
 >     // the interface as needed.
 >     bool unbind = false;
 > #endif
2369,2371c2375,2377
<       if (set_default_multicast_interface(ifp->ifname(),
<                                           vifp->vifname(),
<                                           error_msg)
---
 >       if ((ret_value = set_default_multicast_interface(ifp->ifname(),
 >                                                        vifp->vifname(),
 >                                                        error_msg))
2373c2379
<           return (XORP_ERROR);
---
 >           goto out;
2379,2380c2385,2386
<       if (enable_multicast_loopback(true, error_msg) != XORP_OK) {
<           return (XORP_ERROR);
---
 >       if ((ret_value = enable_multicast_loopback(true, error_msg)) != XORP_OK) {
 >           goto out;
2383a2390,2407
 > #ifdef SO_BINDTODEVICE
 >     else {
 >       if (!vifp->ifname().empty()) {
 >           unbind = true;
 >           if (setsockopt(_proto_socket_out, SOL_SOCKET, SO_BINDTODEVICE,
 >                          vifp->ifname().c_str(), IFNAMSIZ)) {
 >               error_msg += c_format("setsockopt(SO_BINDTODEVICE, %s) failed: %s",
 >                                     vifp->ifname().c_str(), strerror(errno));
 >           }
 >           else {
 >               XLOG_ERROR("BINDTODEVICE, dev: %s, this: %p src-addr: %s",
 >                          vifp->ifname().c_str(), this, cstring(src_address));
 >           }
 >       }
 >     }
 > #endif
 >
 >
2409c2433,2434
<       return (XORP_ERROR);
---
 >       ret_value = XORP_ERROR;
 >       goto out;
2456c2481,2482
<       return (XORP_ERROR);
---
 >       ret_value = XORP_ERROR;
 >       goto out;
2478a2505,2526
 >   out:
 > #ifdef SO_BINDTODEVICE
 >     XLOG_ERROR("out, unbind: %i vifp: %s  mcast: %i",
 >              (int)(unbind), vifp->ifname().c_str(), (int)(dst_address.is_multicast()));
 >     if (unbind) {
 >       // Un-bind the interface
 >       int z = 0;
 >       if (setsockopt(_proto_socket_out, SOL_SOCKET, SO_BINDTODEVICE,
 >                      &z, sizeof(z))) {
 >           error_msg += c_format("setsockopt(SO_BINDTODEVICE, NULL) failed: %s",
 >                                 strerror(errno));
 >           XLOG_ERROR("un-BINDTODEVICE, dev: %s, this: %p src-addr: %s failed: %s",
 >                      vifp->ifname().c_str(), this, cstring(src_address),
 >                      strerror(errno));
 >       }
 >       else {
 >           XLOG_ERROR("un-BINDTODEVICE, dev: %s, this: %p src-addr: %s",
 >                      vifp->ifname().c_str(), this, cstring(src_address));
 >       }
 >     }
 > #endif
 >



-- 
Ben Greear <greearb at candelatech.com>
Candela Technologies Inc  http://www.candelatech.com



More information about the Xorp-users mailing list