{"id":35,"date":"2019-10-31T02:20:17","date_gmt":"2019-10-31T02:20:17","guid":{"rendered":"https:\/\/www.vandervecken.com\/faucet\/?p=35"},"modified":"2019-11-15T23:16:44","modified_gmt":"2019-11-15T23:16:44","slug":"injecting-services-into-the-dataplane-with-coprocessing","status":"publish","type":"post","link":"https:\/\/faucet.vandervecken.com\/index.php\/2019\/10\/31\/injecting-services-into-the-dataplane-with-coprocessing\/","title":{"rendered":"Injecting services into the dataplane with coprocessing"},"content":{"rendered":"\n<p>With the coprocessor feature, FAUCET allows an external NFV host to receive packets from the dataplane, inject arbitrary packets, or both. In particular, coprocessing allows you to inject services into the dataplane, or even override services on hosts already present.<\/p>\n\n\n\n<p>In this example, we have a real host 192.168.2.1 (a router) which has an ssh service. We have a host on the network, 192.168.2.5. 192.168.2.5 may do anything it likes, but if it should try to connect to ssh on 192.168.2.1, we want to redirect that connection to a fake service running on the coprocessor server.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"640\" height=\"595\" src=\"https:\/\/www.vandervecken.com\/faucet\/wp-content\/uploads\/2019\/10\/fake-1.jpg\" alt=\"\" class=\"wp-image-37\" srcset=\"https:\/\/faucet.vandervecken.com\/wp-content\/uploads\/2019\/10\/fake-1.jpg 640w, https:\/\/faucet.vandervecken.com\/wp-content\/uploads\/2019\/10\/fake-1-300x279.jpg 300w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/figure>\n\n\n\n<p>First we will need to tell FAUCET to intercept the service using an ACL, which will be applied to the test host&#8217;s port. Port 18 is the coprocessor port, and port 13 is the test host.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>acls:\n  coprocessssh:\n    - rule:\n        dl_type: 0x806\n        actions:\n          allow: 1\n          output:\n            ports: [18]\n    - rule:\n        dl_type: 0x800\n        ip_proto: 6\n        tcp_dst: 22\n        actions:\n          output:\n            ports: [18]\n    - rule:\n        actions:\n          allow: 1\nvlans:\n  trusted:\n    vid: 2\ndps:\n  dp:\n    interfaces:\n      13:\n        native_vlan: trusted\n        acls_in: [coprocessssh]\n      18:\n        coprocessor: {strategy: vlan_vid}<\/code><\/pre>\n\n\n\n<p>FAUCET will now redirect port 22 to the coprocessor port. We will now need to set up an OVS switch on the coprocessor so we can start fake services, and allow ARP to work in parallel with the real host. The fake host will need to use the same MAC address as the real one, which won&#8217;t cause a conflict because FAUCET is intercepting just the TCP service and FAUCET knows not to re-learn the real host on the coprocessor port.<\/p>\n\n\n\n<p>Note the OVS actions for setting VID to 4098 &#8211; that&#8217;s the VID for the <code>trusted<\/code> VLAN (2) or&#8217;d with the VID present bit (4096). That will cause packets from the coprocessor to have the right VID to be switched back into the <code>trusted<\/code> VLAN.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>root@coprocessor:\/home\/pi# cat setupcopro.sh \n#!\/bin\/sh\n\nNFVINT=enx0023565c8859\nFAKEHW=aa:56:63:87:9e:e9\nFAKEIP=192.168.2.1\/24\nNS=copro\n\nip netns add $NS\nifconfig $NFVINT up\nip link add dev fake0 type veth peer name fakeovs0\nifconfig fakeovs0 up\nip link set fake0 netns $NS\nip netns exec $NS ifconfig fake0 hw ether $FAKEHW $FAKEIP up\nfor i in $NFVINT fakeovs0 ovs-system ; do\n  echo 1 > \/proc\/sys\/net\/ipv6\/conf\/$i\/disable_ipv6\ndone\nifconfig ovs-system 0.0.0.0\n\novs-vsctl del-br br0\novs-vsctl add-br br0\novs-ofctl del-flows br0\n\nfor i in $NFVINT fakeovs0 ; do\n  ovs-vsctl add-port br0 $i\ndone\n\novs-ofctl add-flow -OOpenFlow13 br0 \"in_port=1,actions=output:2\"\novs-ofctl add-flow -OOpenFlow13 br0 \"in_port=2,vlan_tci=0x0000\/0x1fff,ip,tcp,actions=push_vlan:0x8100,set_field:4098->vlan_vid,output:1\"\novs-ofctl add-flow -OOpenFlow13 br0 \"in_port=2,vlan_tci=0x0000\/0x1fff,arp,actions=push_vlan:0x8100,set_field:4098->vlan_vid,output:1\"<\/code><\/pre>\n\n\n\n<p>Now we will start a fake service on the coprocessor and connect to it from the test host.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>root@coprocessor:\/home\/pi# cat fakessh.sh \n#!\/bin\/sh\n\nwhile \/bin\/true ; do echo completely awesome ssh service| ip netns exec copro nc -l 192.168.2.1 22 ; done\nroot@coprocessor:\/home\/pi# .\/fakessh.sh<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>pi@pi8021x:~ $ telnet 192.168.2.1 22\nTrying 192.168.2.1...\nConnected to 192.168.2.1.\nEscape character is '^]'.\ncompletely awesome ssh service\n^]\ntelnet> close\nConnection closed.\n<\/code><\/pre>\n\n\n\n<p>That&#8217;s it. We could run other services on the fake host &#8211; for example to broadcast CDP to impersonate a router, for example, or redirect other services.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>With the coprocessor feature, FAUCET allows an external NFV host to receive packets from the dataplane, inject arbitrary packets, or both. In particular, coprocessing allows you to inject services into the dataplane, or even override services on hosts already present. In this example, we have a real host 192.168.2.1 (a router) which has an ssh &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/faucet.vandervecken.com\/index.php\/2019\/10\/31\/injecting-services-into-the-dataplane-with-coprocessing\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Injecting services into the dataplane with coprocessing&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-35","post","type-post","status-publish","format-standard","hentry","category-uncategorised","entry"],"_links":{"self":[{"href":"https:\/\/faucet.vandervecken.com\/index.php\/wp-json\/wp\/v2\/posts\/35","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/faucet.vandervecken.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/faucet.vandervecken.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/faucet.vandervecken.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/faucet.vandervecken.com\/index.php\/wp-json\/wp\/v2\/comments?post=35"}],"version-history":[{"count":7,"href":"https:\/\/faucet.vandervecken.com\/index.php\/wp-json\/wp\/v2\/posts\/35\/revisions"}],"predecessor-version":[{"id":57,"href":"https:\/\/faucet.vandervecken.com\/index.php\/wp-json\/wp\/v2\/posts\/35\/revisions\/57"}],"wp:attachment":[{"href":"https:\/\/faucet.vandervecken.com\/index.php\/wp-json\/wp\/v2\/media?parent=35"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/faucet.vandervecken.com\/index.php\/wp-json\/wp\/v2\/categories?post=35"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/faucet.vandervecken.com\/index.php\/wp-json\/wp\/v2\/tags?post=35"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}