blob: f419c4ecb29bcc4bc16cf25ba9a4edbe19dee445 [file] [log] [blame]
John DeNisco06dcd452018-07-26 12:45:10 -04001.. _homegateway:
2
3.. toctree::
4
5Using VPP as a Home Gateway
6===========================
7
8Vpp running on a small system (with appropriate NICs) makes a fine
9home gateway. The resulting system performs far in excess of
Dave Barachd455e5a2019-07-22 10:55:05 -040010requirements: a TAG=vpp_debug image runs at a vector size of ~1.2
11terminating a 150-mbit down / 10-mbit up cable modem connection.
John DeNisco06dcd452018-07-26 12:45:10 -040012
13At a minimum, install sshd and the isc-dhcp-server. If you prefer, you
14can use dnsmasq.
15
16Configuration files
17-------------------
18
19/etc/vpp/startup.conf::
20
21 unix {
22 nodaemon
23 log /var/log/vpp/vpp.log
24 full-coredump
25 cli-listen /run/vpp/cli.sock
26 startup-config /setup.gate
Dave Barachd455e5a2019-07-22 10:55:05 -040027 poll-sleep-usec 100
John DeNisco06dcd452018-07-26 12:45:10 -040028 gid vpp
29 }
30 api-segment {
31 gid vpp
32 }
33 dpdk {
34 dev 0000:03:00.0
35 dev 0000:14:00.0
36 etc.
Dave Barachd455e5a2019-07-22 10:55:05 -040037 }
John DeNisco06dcd452018-07-26 12:45:10 -040038
Dave Barachd455e5a2019-07-22 10:55:05 -040039 plugins {
40 ## Disable all plugins, selectively enable specific plugins
41 ## YMMV, you may wish to enable other plugins (acl, etc.)
42 plugin default { disable }
43 plugin dpdk_plugin.so { enable }
44 plugin nat_plugin.so { enable }
45 ## if you plan to use the time-based MAC filter
46 plugin mactime_plugin.so { enable }
47 }
48
49/etc/dhcp/dhcpd.conf::
John DeNisco06dcd452018-07-26 12:45:10 -040050
51 subnet 192.168.1.0 netmask 255.255.255.0 {
52 range 192.168.1.10 192.168.1.99;
53 option routers 192.168.1.1;
54 option domain-name-servers 8.8.8.8;
55 }
56
57If you decide to enable the vpp dns name resolver, substitute
58192.168.1.2 for 8.8.8.8 in the dhcp server configuration.
59
Dave Barachd455e5a2019-07-22 10:55:05 -040060/etc/default/isc-dhcp-server::
61
62 # On which interfaces should the DHCP server (dhcpd) serve DHCP requests?
63 # Separate multiple interfaces with spaces, e.g. "eth0 eth1".
64 INTERFACESv4="lstack"
65 INTERFACESv6=""
66
John DeNisco06dcd452018-07-26 12:45:10 -040067/etc/ssh/sshd_config::
68
69 # What ports, IPs and protocols we listen for
70 Port <REDACTED-high-number-port>
71 # Change to no to disable tunnelled clear text passwords
72 PasswordAuthentication no
73
74For your own comfort and safety, do NOT allow password authentication
75and do not answer ssh requests on port 22. Experience shows several
76hack attempts per hour on port 22, but none (ever) on random
77high-number ports.
78
Dave Barachd455e5a2019-07-22 10:55:05 -040079vpp configuration (/setup.gate)::
John DeNisco06dcd452018-07-26 12:45:10 -040080
81 comment { This is the WAN interface }
82 set int state GigabitEthernet3/0/0 up
83 comment { set int mac address GigabitEthernet3/0/0 mac-to-clone-if-needed }
84 set dhcp client intfc GigabitEthernet3/0/0 hostname vppgate
85
86 comment { Create a BVI loopback interface}
87 loop create
88 set int l2 bridge loop0 1 bvi
89 set int ip address loop0 192.168.1.1/24
90 set int state loop0 up
91
92 comment { Add more inside interfaces as needed ... }
93 set int l2 bridge GigabitEthernet0/14/0 1
Dave Barachd455e5a2019-07-22 10:55:05 -040094 set int state GigabitEthernet0/14/0 up
John DeNisco06dcd452018-07-26 12:45:10 -040095
96 comment { dhcp server and host-stack access }
Dave Barachd455e5a2019-07-22 10:55:05 -040097 create tap host-if-name lstack host-ip4-addr 192.168.1.2/24 host-ip4-gw 192.168.1.1
Dave Barach5e36c3c2018-10-30 10:24:17 -040098 set int l2 bridge tap0 1
99 set int state tap0 up
John DeNisco06dcd452018-07-26 12:45:10 -0400100
101 comment { Configure NAT}
102 nat44 add interface address GigabitEthernet3/0/0
103 set interface nat44 in loop0 out GigabitEthernet3/0/0
104
Dave Barachd455e5a2019-07-22 10:55:05 -0400105 comment { allow inbound ssh to the <REDACTED-high-number-port> }
106 nat44 add static mapping local 192.168.1.2 <REDACTED> external GigabitEthernet3/0/0 <REDACTED> tcp
John DeNisco06dcd452018-07-26 12:45:10 -0400107
108 comment { if you want to use the vpp DNS server, add the following }
109 comment { Remember to adjust the isc-dhcp-server configuration appropriately }
110 comment { nat44 add identity mapping external GigabitEthernet3/0/0 udp 53053 }
111 comment { bin dns_name_server_add_del 8.8.8.8 }
112 comment { bin dns_name_server_add_del 68.87.74.166 }
113 comment { bin dns_enable_disable }
114 comment { see patch below, which adds these commands }
115 service restart isc-dhcp-server
Dave Barachd455e5a2019-07-22 10:55:05 -0400116
117Systemd configuration
118---------------------
119
120In a typical home-gateway use-case, vpp owns the one-and-only WAN link
121with a prayer of reaching the public internet. Simple things like
122updating distro software requires use of the "lstack" interface
123created above, and configuring a plausible upstream DNS name resolver.
124
125Configure /etc/systemd/resolved.conf as follows.
126
127/etc/systemd/resolved.conf::
128
129 [Resolve]
130 DNS=8.8.8.8
131 #FallbackDNS=
132 #Domains=
133 #LLMNR=no
134 #MulticastDNS=no
135 #DNSSEC=no
136 #Cache=yes
137 #DNSStubListener=yes
138
139Netplan configuration
140---------------------
141
142If you want to configure a static IP address on one of your
143home-gateway Ethernet ports on Ubuntu 18.04, you'll need to configure
144netplan. Netplan is relatively new. It and the network manager GUI and
145can be cranky. In the configuration shown below,
146s/enp4s0/<your-interface>/...
147
148/etc/netplan-01-netcfg.yaml::
149
150 # This file describes the network interfaces available on your system
151 # For more information, see netplan(5).
152 network:
153 version: 2
154 renderer: networkd
155 ethernets:
156 enp4s0:
157 dhcp4: no
158 addresses: [192.168.2.254/24]
159 gateway4: 192.168.2.100
160 nameservers:
161 search: [my.local]
162 addresses: [8.8.8.8]
163
164/etc/systemd/network-10.enp4s0.network::
165
166 [Match]
167 Name=enp4s0
168
169 [Link]
170 RequiredForOnline=no
171
172 [Network]
173 ConfigureWithoutCarrier=true
174 Address=192.168.2.254/24
175
176Note that we've picked an IP address for the home gateway which is on
177an independent unrouteable subnet. This is handy for installing (and
178possibly reverting) new vpp software.
179
180Installing new vpp software
181---------------------------
182
183If you're **sure** that a given set of vpp Debian packages will
184install and work properly, you can install them while logged into the
185gateway via the lstack / nat path. This procedure is a bit like
186standing on a rug and yanking it. If all goes well, a perfect
187back-flip occurs. If not, you may wish that you'd configured a static
188IP address on a reserved Ethernet interface as described above.
189
190Installing a new vpp image via ssh to 192.168.1.2::
191
192 # nohup dpkg -i *.deb >/dev/null 2>&1 &
193
194Within a few seconds, the inbound ssh connection SHOULD begin to respond
195again. If it does not, you'll have to debug the issue(s).
196
197Testing new software
198--------------------
199
200If you frequently test new home gateway software, it may be handy to
201set up a test gateway behind your production gateway. This testing
202methodology reduces complaints from family members, to name one benefit.
203
204Change the inside network (dhcp) subnet from 192.168.1.0/24 to
205192.168.3.0/24, change the (dhcp) advertised router to 192.168.3.1,
206reconfigure the vpp tap interface addresses onto the 192.168.3.0/24
207subnet, and you should be all set.
208
209This scenario nats traffic twice: first, from the 192.168.3.0/24
210network onto the 192.168.1.0/24 network. Next, from the 192.168.1.0/24
211network onto the public internet.
212
John DeNisco06dcd452018-07-26 12:45:10 -0400213Patches
214-------
215
Dave Barach5e36c3c2018-10-30 10:24:17 -0400216You'll need this patch to add the "service restart" command::
John DeNisco06dcd452018-07-26 12:45:10 -0400217
218 diff --git a/src/vpp/vnet/main.c b/src/vpp/vnet/main.c
219 index 6e136e19..69189c93 100644
220 --- a/src/vpp/vnet/main.c
221 +++ b/src/vpp/vnet/main.c
222 @@ -18,6 +18,8 @@
223 #include <vlib/unix/unix.h>
224 #include <vnet/plugin/plugin.h>
225 #include <vnet/ethernet/ethernet.h>
226 +#include <vnet/ip/ip4_packet.h>
227 +#include <vnet/ip/format.h>
228 #include <vpp/app/version.h>
229 #include <vpp/api/vpe_msg_enum.h>
230 #include <limits.h>
231 @@ -400,6 +402,63 @@ VLIB_CLI_COMMAND (test_crash_command, static) = {
232
233 #endif
234
235 +static clib_error_t *
236 +restart_isc_dhcp_server_command_fn (vlib_main_t * vm,
Dave Barachd455e5a2019-07-22 10:55:05 -0400237 + unformat_input_t * input,
John DeNisco06dcd452018-07-26 12:45:10 -0400238 + vlib_cli_command_t * cmd)
239 +{
240 + int rv __attribute__((unused));
241 + /* Wait three seconds... */
242 + vlib_process_suspend (vm, 3.0);
Dave Barachd455e5a2019-07-22 10:55:05 -0400243 +
John DeNisco06dcd452018-07-26 12:45:10 -0400244 + rv = system ("/usr/sbin/service isc-dhcp-server restart");
Dave Barachd455e5a2019-07-22 10:55:05 -0400245 +
John DeNisco06dcd452018-07-26 12:45:10 -0400246 + vlib_cli_output (vm, "Restarted the isc-dhcp-server...");
247 + return 0;
248 +}
249 +
250 +/* *INDENT-OFF* */
251 +VLIB_CLI_COMMAND (restart_isc_dhcp_server_command, static) = {
252 + .path = "service restart isc-dhcp-server",
253 + .short_help = "restarts the isc-dhcp-server",
254 + .function = restart_isc_dhcp_server_command_fn,
255 +};
256 +/* *INDENT-ON* */
257 +
Dave Barach5e36c3c2018-10-30 10:24:17 -0400258
John DeNisco06dcd452018-07-26 12:45:10 -0400259
Dave Barachd455e5a2019-07-22 10:55:05 -0400260Using the time-based mac filter plugin
261--------------------------------------
John DeNisco06dcd452018-07-26 12:45:10 -0400262
263If you need to restrict network access for certain devices to specific
Dave Barachd455e5a2019-07-22 10:55:05 -0400264daily time ranges, configure the "mactime" plugin. Add it to the list
265of enabled plugins in /etc/vpp/startup.conf, then enable the feature
John DeNisco06dcd452018-07-26 12:45:10 -0400266on the NAT "inside" interfaces::
267
268 bin mactime_enable_disable GigabitEthernet0/14/0
269 bin mactime_enable_disable GigabitEthernet0/14/1
270 ...
271
272Create the required src-mac-address rule database. There are 4 rule
273entry types:
274
275* allow-static - pass traffic from this mac address
276* drop-static - drop traffic from this mac address
277* allow-range - pass traffic from this mac address at specific times
278* drop-range - drop traffic from this mac address at specific times
279
280Here are some examples::
281
282 bin mactime_add_del_range name alarm-system mac 00:de:ad:be:ef:00 allow-static
283 bin mactime_add_del_range name unwelcome mac 00:de:ad:be:ef:01 drop-static
284 bin mactime_add_del_range name not-during-business-hours mac <mac> drop-range Mon - Fri 7:59 - 18:01
285 bin mactime_add_del_range name monday-busines-hours mac <mac> allow-range Mon 7:59 - 18:01