Monday, March 26, 2012

Thugs at New Zealand skateparks

This is totally off-topic, but I saw this and it made me really angry. I used to love skateboarding when I was a kid, and the thought of grown adults shoulder-charging young kids off skateboards is just disgusting.

 
Today At Vic Park from NZskate.com on Vimeo.

In other news, I've been playing with the source code to BIRD to see if I can put in some hooks to make it work with NOX. It has a set of OS-specific "kernel" modules which install routes into the OS routing tables, so it shouldn't be hard to make a NOX version of this.

Another option would be to monitor the MRT dump file, or point it at a named pipe - then get NOX to use that to pick up updates.

One thing that Nick Buraglio pointed out was that BIRD is in need of an IS-IS implementation. IPv6 has been a good excuse to move from OSPF to IS-IS because it all runs in one instance - not requiring OSPFv2 and v3 instances for IPv4 and IPv6. Time will tell if there's still a place for decentralised IGP's in an OpenFlow world, but if we're going to see an influx of software routers, then IS-IS will definitely be added in the next year or two. (edit - somebody's beaten me to add this to quagga http://code.google.com/p/google-quagga/)

More details once I get BIRD talking to NOX though!

Saturday, March 17, 2012

Multicasts and Broadcasts and Flows, oh my!

Background
If you've set up pyswitch and NOX with Open vSwitch then you'll notice that any packets that don't match a flow get sent to the Openflow controller. If you set no flows, the controller receives every packet, until either you or the controller adds flows. Pyswitch will set flows for unicast traffic, but what happens when you start getting a substantial amount of background multicast/broadcast traffic?

A standard NOX setup can handle 10 flows per second. This means it can set up flows to handle 10 new hosts, or 10 different protocols, or it can simply return 10 packets to the switch and tell it to flood them.

Can you see the potential problem here? Any medium-to -large sized network will have all sorts of background multicast/unicast traffic, here are some of the things that will generate broadcast/multicast traffic on your network:

  • ARP requests
  • DHCP requests
  • SSDP messages (from any UPnP-enabled device)
  • SMB/NetBIOS (windows machines)
  • Bonjour/mDNS (Apple / anything with iTunes)
  • IGP routing protocols
  • Spanning tree
  • IPv6 router-advertisement messages
Taking a closer look
If you fire up wireshark you can filter on these messages

Just right-click on the IG bit, then go Apply as Filter -> Selected, and from now on, you'll only see multicast/broadcast packets. Here are some examples of what you might see on your network



What's worse is that if you sit and watch, you'll see groups of packets show up in large groups at a time - SSDP, mDNS and NBNS all send 5-10 packets at a time, and with a standard Openflow controller-switch setup, these 10 packets will pause your network for a whole second.

The solution
With Open vSwitch, you have a few options - you could add all your flows manually, or you can delegate that to an Openflow controller. For something like this however, you can add a flow that makes your switch automatically flood any multicast/broadcast traffic, leaving your Openflow controller to focus on unicast traffic.

The ovs-ofctl documentation gives us an easy answer - set a flow that masks the group address bit as follows:

ovs-ofctl add-flow br0 priority=65500,dl_dst=01:00:00:00:00:00/01:00:00:00:00:00,actions=flood

That was easy! If you want to do IGMP or MLD snooping, you can add flows with higher priorities - but first have a look at how much IP multicast traffic is on your network already - remember, 10 flows per second is probably your limit.

ovs-ofctl add-flow br0 priority=65500,dl_dst=01:00:5e:00:00:16,actions=controller
ovs-ofctl add-flow br0 priority=65500,dl_dst=33:33:00:00:00:16,actions=controller

The first flow will match IGMP traffic, and the second will match MLDv2 (IPv6 version of IGMPv3) traffic, but both versions of MLD unfortunately need more complicated flows, MLDv1 uses the all-local-nodes address, and even though MLDv2 has its own address, the MAC address 33:33:00:00:00:16 is valid for any IPv6 multicast address that ends in :0:16.

Has anyone done IGMP/MLD snooping on an Openflow controller yet? It's probably outside the scope of my current project, but it should be easy enough to build into Pyswitch if someone had the time. Let me know if you've done this, my twitter is @samrussellnz

Thursday, March 15, 2012

Dead drops: breaking open USB flash drives

I love it when people come up with interesting ways of using technology, and when I came across dead drops, I was immediately hooked. The idea is to concrete USB flash drives into walls in public places, and then see what people use them for. Unlike conventional networks, such as the internet, it's not immediately obvious what dead drops would be useful for, but given the last few years of restrictive new laws, teenagers and fat Germans being extradited for running websites, and now NTIA playing silly buggers about who gets to run DNS, dead drops are a green-field opportunity that hasn't yet been tainted by money and lawyers.

Here's how it works. You buy a USB key (this one was $20NZD and is 8GB), and admire it in its shiny new packaging
Once you're satisfied with how awesome your purchase was, you use scissors or a screwdriver to pry off the cover.

 For protection, we'll tape around the circuit board

And finally, we test that it still works (it does). Your dead drop is ready to be installed somewhere - just make sure you get permission first! Given it will cost your local council nothing, and is a novel new type of street art, it's quite possible the answer will be yes, as long as you ask first.


Wednesday, March 14, 2012

Pyswitch bugfix, and DoS vulnerability in open vSwitch

Pyswitch
I had a bit of time to work on Pyswitch today, and I've cut it back so that it only sets the destination MAC and out port, and that was enough for it to start setting flows properly. You can look at the source if you like, or just focus on the part I've changed:

The function I've modified is forward_l2_packet - as the name suggests, it either floods all ports with the packet it has received, or sends the packet out the correct port and installs a flow in the switch. Here is the function:


def forward_l2_packet(dpid, inport, packet, buf, bufid):    
    dstaddr = packet.dst.tostring()
    if not ord(dstaddr[0]) & 1 and inst.st[dpid].has_key(dstaddr):
        prt = inst.st[dpid][dstaddr]
        if  prt[0] == inport:
            log.err('**warning** learned port = inport', system="pyswitch")
            inst.send_openflow(dpid, bufid, buf, openflow.OFPP_FLOOD, inport)
        else:
            # We know the outport, set up a flow
            log.msg('installing flow for ' + str(packet), system="pyswitch")
            flow = extract_flow(packet)
            flow[core.IN_PORT] = inport
            actions = [[openflow.OFPAT_OUTPUT, [0, prt[0]]]]
            inst.install_datapath_flow(dpid, flow, CACHE_TIMEOUT, 
                                       openflow.OFP_FLOW_PERMANENT, actions,
                                       bufid, openflow.OFP_DEFAULT_PRIORITY,
                                       inport, buf)
    else:    
        # haven't learned destination MAC. Flood 
        inst.send_openflow(dpid, bufid, buf, openflow.OFPP_FLOOD, inport)

The key to creating t flow is the extract_flow function from util.py


def extract_flow(ethernet):
    """
    Extracts and returns flow attributes from the given 'ethernet' packet.
    The caller is responsible for setting IN_PORT itself.
    """
    attrs = {}
    attrs[core.DL_SRC] = ethernet.src
    attrs[core.DL_DST] = ethernet.dst
    attrs[core.DL_TYPE] = ethernet.type
    p = ethernet.next


    if isinstance(p, vlan):
        attrs[core.DL_VLAN] = p.id
        attrs[core.DL_VLAN_PCP] = p.pcp
        p = p.next
    else:
        attrs[core.DL_VLAN] = 0xffff # XXX should be written OFP_VLAN_NONE
        attrs[core.DL_VLAN_PCP] = 0


    if isinstance(p, ipv4):
        attrs[core.NW_SRC] = p.srcip
        attrs[core.NW_DST] = p.dstip
        attrs[core.NW_PROTO] = p.protocol
        p = p.next


        if isinstance(p, udp) or isinstance(p, tcp):
            attrs[core.TP_SRC] = p.srcport
            attrs[core.TP_DST] = p.dstport
        else:
            if isinstance(p, icmp):
                attrs[core.TP_SRC] = p.type
                attrs[core.TP_DST] = p.code
            else:
                attrs[core.TP_SRC] = 0
                attrs[core.TP_DST] = 0
    else:
        attrs[core.NW_SRC] = 0
        attrs[core.NW_DST] = 0
        attrs[core.NW_PROTO] = 0
        attrs[core.TP_SRC] = 0
        attrs[core.TP_DST] = 0
    return attrs

Now, if we're just making a basic switch, this does way more than we need - why would a switch care about layer 4 protocols? Fortunately, open vSwitch on the Pronto ignores most of it because it uses DL_TYPE=0x8100 (which means the packet is 802.1q VLAN tagged, and the actual ethertype is 4 bytes futher up), but having the wrong DL_TYPE is why nothing ends up matching the flow...

Util.py needs to be fixed to interpret VLANs properly, but in the meantime, pyswitch will work fine as a simple layer two switch if we use a cut-down version of the extract_flow function. And here it is:

def create_l2_out_flow(ethernet):
    attrs = {}
    attrs[core.DL_DST] = ethernet.dst
    return attrs

Simple, right? Now we use this instead of extract_flow, and then we can walk through what the function does in detail:

ddef forward_l2_packet(dpid, inport, packet, buf, bufid):    
    dstaddr = packet.dst.tostring()
    if not ord(dstaddr[0]) & 1 and inst.st[dpid].has_key(dstaddr):
[...]

    else:  
        # haven't learned destination MAC. Flood
        inst.send_openflow(dpid, bufid, buf, openflow.OFPP_FLOOD, inport)


This pulls the destination MAC address out of the packet, converts it to a string, and makes sure the first character is 0 = unicast. If this is the case, it checks to see if it's learnt it before, and if so, then we can proceed. Otherwise, it floods to all ports - correct for both broadcast/multicast and unknown MAC addresses.

        prt = inst.st[dpid][dstaddr]
        if  prt[0] == inport:
            log.err('**warning** learned port = inport', system="pyswitch")
            inst.send_openflow(dpid, bufid, buf, openflow.OFPP_FLOOD, inport)

If the destination MAC is assigned to the source port then something is weird (either a spoof or a loop in the network), so behave like a hub for this packet

        else:
            # We know the outport, set up a flow
            log.msg('installing flow for ' + str(packet), system="pyswitch")
            # sam edit - just load dest address, the rest doesn't matter
            flow = create_l2_out_flow(packet)
            actions = [[openflow.OFPAT_OUTPUT, [0, prt[0]]]]
            inst.install_datapath_flow(dpid, flow, CACHE_TIMEOUT,
                                       openflow.OFP_FLOW_PERMANENT, actions,
                                       bufid, openflow.OFP_DEFAULT_PRIORITY,
                                       inport, buf)

This is the switch part - we create our very specific flow with our new function (just destination MAC address - not all 10 or so parts to match on), set the action to output to the correct port, then call install_datapath_flow (part of nox::lib::core::Component), which sends back the new flow and instruction on where to send the packet. All done, and works well, except for one thing:

Open vSwitch DoS (probably one of many)
The problem with OpenFlow that everybody points out is that you can only really send 10 packets per second to your controller. You can try and optimise this if you want, but this switch-controller connection is where the battle will be fought to make OpenFlow perform better. I didn't think this would be a problem with the Pronto, because I assumed that open vSwitch would process packets somewhat like this:


  1. Find flow for packet - if found, follow the actions and go to next packet
  2. Send packet to controller
  3. Get packet and flow back from controller, follow instruction for this packet and install flow
  4. Go back to 1 for next packet.
Unfortunately, it appears that open vSwitch does things a little differently:

  1. Find flow for packet - if found, follow the actions and go to next packet
  2. Send packet to controller
  3. Get packet and flow back from controller, follow instruction for this packet and add flow to some queue somewhere
  4. Go back to 1 for next packet
  5. If no more packets waiting, look at the queue and install the flow
Surprisingly enough, this works fine for TCP - the 3-way handshake gives the switch enough downtime to install the flow, and get ready for the influx of data. However, if you surprise it with 500Mb/s of UDP iperf, you find the receiving server only getting ~150Kb/s, every single packet going to the controller, and no flow being installed!

Fortunately, the staff at Pronto have been awesome to work with, so I'm hoping we'll get a solution soon, and in the meantime, I'll try to find a workaround myself. If you're testing and stuck in a similar situation, either start off with a little UDP test first, or even ping the other host before starting your iperf - this will set the flows, and then you can send as much data as you like!

Monday, March 12, 2012

Openflow with NOX & Pronto/Pica8

We've got a Pronto 3290 at work, and with Josh Bailey's help I've been getting it talking Openflow to a NOX controller running pyswitch.

I figure the more I write about it, the more sense it'll make, so here's a summary of how far I've come:


  • The pronto runs Open vSwitch, which lets you add your own flows manually - makes it easy to see what flows your controller has added too. They're supposedly going to add Openflow v1.2 support soon, which means IPv6!
  • NOX doesn't find the Python bindings for OpenSSL on Ubuntu 11.10 (oneiric) in its current branch, but the destiny branch does - a bit of Git skill will sort this out for you
  • Wireshark has an OpenFlow dissector which is part of the OpenFlow code, but it doesn't work with newer versions of Wireshark, you'll need this patch to make it build - confirmed working on Ubuntu 11.10
  • Pyswitch (included as part of NOX) doesn't send back the right flows to the pronto - it sets the ethertype as 0x8100, so the flows look like this: idle_timeout=5,priority=65535,in_port=8,dl_vlan=1,dl_vlan_pcp=0,dl_src=00:XX:XX:XX:XX:XX,dl_dst=00:YY:YY:YY:YY:YY,dl_type=0x8100 actions=output:3 - this is where I'm going to start modding pyswitch
And this is where I am now. The plan for the next few weeks (which will probably change) is going to be something like this:
  1. Make pyswitch send correct Openflow data
  2. Mod pyswitch (or a demo router app) to do some basic routing and ACL
  3. Hope that someone has written a BGP Openflow app so that I don't have to - otherwise, look at options for this
I'll be back with more details

Saturday, July 2, 2011

Woohoo, 3-way!

I added my third router and machine, but couldn't get multicast to go more than one hop... it turns out that when I tried to test msdp and pim without tunneling them, msdp worked, pim didn't, so only pim got changed back to the tunneled address. Changing msdp to the tunnelled address made it work almost immediately!

Config dump

interfaces {
    em0 {
        unit 0 {
            family inet {
                address 10.1.1.198/8;
            }
        }
    }
    em1 {
        unit 0 {
            family inet {
                address 192.168.11.1/24;
            }
        }
    }
    em2 {
        unit 0 {
            family inet {
                address 192.168.2.1/24;
            }
        }
    }
    em3 {
        unit 0;
    }
    gre {
        unit 0 {
            tunnel {
                source 192.168.11.1;
                destination 192.168.11.2;
            }
            family inet {
                address 192.168.101.1/30;
            }
            family inet6 {
                address 2001:4428:251:2::1:1/120;
            }
        }
    }
    ipip {
        unit 0 {
            tunnel {
                source 192.168.2.1;
                destination 192.168.2.2;
            }
            family inet {
                address 192.168.201.1/30;
            }
            family inet6 {
                address 2001:4428:251:2::1/120;
            }
        }
        unit 1 {
            tunnel {
                source 192.168.2.1;
                destination 192.168.2.3;
            }
            family inet {
                address 192.168.202.1/30;
            }
        }
    }
    lo0 {
        unit 0 {
            family inet {
                address 1.1.1.1/32;
            }
        }
    }
}
routing-options {
    interface-routes {
        rib-group inet if-rib;
    }
    rib-groups {
        multicast-rpf-rib {
            export-rib inet.2;
            import-rib inet.2;
        }
        if-rib {
            import-rib [ inet.2 inet.0 ];
        }
    }
    autonomous-system 65000;
}
protocols {
    igmp {
        interface all {
            version 3;
        }
    }
    bgp {
        local-as 65000;
        group branch1 {
            type external;
            export [ to-branch1 allow-all ];
            peer-as 65001;
            neighbor 192.168.201.2 {
                family inet {
                    any;
                }
            }
            neighbor 2001:4428:251:2::2 {
                family inet6 {
                    any;
                }
            }
        }
        group branch2 {
            type external;
            export [ to-branch1 allow-all ];
            peer-as 65002;
            neighbor 192.168.202.2 {
                family inet {
                    any;
                }
            }
        }
    }
    msdp {
        rib-group inet multicast-rpf-rib;
        export allow-all;
        import allow-all;
        group test {
            peer 192.168.202.2 {
                local-address 192.168.202.1;
            }
            peer 192.168.201.2 {
                local-address 192.168.201.1;
            }
        }
    }
    pim {
        rib-group inet multicast-rpf-rib;
        rp {
            local {
                address 192.168.101.1;
                group-ranges {
                    224.0.0.0/4;
                }
            }
        }
        interface all {
            mode sparse;
            version 2;
        }
        dr-election-on-p2p;
    }
    rip {
        group gateway {
            export gateway-rip;
            neighbor em0.0;
        }
    }
}
policy-options {
    policy-statement allow-all {
        then accept;
    }
    policy-statement gateway-rip {
        from protocol [ direct bgp ];
        then accept;
    }
    policy-statement reject-all {
        from protocol rip;
        then reject;
    }
    policy-statement to-branch {
        from protocol [ direct local ospf bgp static rip pim ];
        then accept;
    }
    policy-statement to-branch1 {
        from protocol [ direct local ospf bgp static rip pim ];
        then accept;
    }
}

As you can see, I've started setting up IPv6 addresses on the routers. I've got RA and stateful DHCPv6 working on my real network, so there's no point muddying up the config here. By the way, it turns out you can have as many tunnels as you like - turns out stacking routed gre/ipip interfaces is totally okay. I hope to have some IPv6 multicast results this evening, so stay tuned

Clockwork Olive: multicast update

After much pissing around it turns out multicast does work, but emcast has been having problems. Dbeacon runs well in super verbose mode, emcast receives the info, but just doesn't seem to send very well - it could be that the olives are just being shit and dropping packets though.

Want to see the config?


interfaces {
    em0 {
        unit 0 {
            family inet {
                address 192.168.2.2/24;
            }
        }
    }
    em1 {
        unit 0 {
            family inet {
                address 192.168.12.1/24;
            }
        }
    }
    gre {
        unit 0 {
            tunnel {
                source 192.168.12.1;
                destination 192.168.12.2;
            }
            family inet {
                address 192.168.102.1/30;
            }
        }
    }
    ipip {
        unit 0 {
            tunnel {
                source 192.168.2.2;
                destination 192.168.2.1;
            }
            family inet {
                address 192.168.201.2/30;
            }
        }
    }
    lo0 {
        unit 0 {
            family inet {
                address 1.1.1.2/32;
            }
        }
    }
}
routing-options {
    interface-routes {
        rib-group inet if-rib;
    }
    rib-groups {
        multicast-rpf-rib {
            export-rib inet.2;
            import-rib inet.2;
        }
        if-rib {
            import-rib [ inet.2 inet.0 ];
        }
    }
    autonomous-system 65001;
}
protocols {
    igmp {
        interface all {
            version 3;
        }
    }
    bgp {
        local-as 65001;
        group olive {
            type external;
            family inet {
                any;
            }
            export to-branch1;
            peer-as 65000;
            neighbor 192.168.201.1;
        }
    }
    msdp {
        rib-group inet multicast-rpf-rib;
        group test {
            peer 192.168.201.1 {
                local-address 192.168.201.2;
            }
        }
    }
    pim {
        rib-group inet multicast-rpf-rib;
        rp {
            local {
                address 192.168.102.1;
                group-ranges {
                    224.0.0.0/4;
                }
            }
        }
        interface all {
            mode sparse;
            version 2;
        }
        dr-election-on-p2p;
    }
}
policy-options {
    policy-statement allow-all {
        then accept;
    }
    policy-statement to-branch1 {
        from protocol [ direct local ospf bgp pim ];
        then accept;
    }
}


I'm going to be a bastard any sources except this one. I'm tempted to chalk the emcast send failure down to packets simply being dropped, and maybe try a test VLC stream if I can be bothered with that, but this was only meant to be a means to an end - the next step is IPv6 multicast!