BadVPN – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 # An example NCD script for network configuration.
2 #
3 # The first three processes demonstrate different kinds of interfaces
4 # and configurations. They are all disabled by default.
5 #
6 # The last process waits for one of the interfaces to come up
7 # and sets up routes and DNS entries to use that interface for
8 # Internet access.
9 #
10 # Be sure to change the dependency list in the last process to name
11 # the interfaces you use.
12  
13 # Example wired interface with static configuration.
14 process wired_example_static {
15 if("false"); # remove/comment to enable
16  
17 # Set device.
18 var("eth0") dev;
19  
20 # Wait for device.
21 net.backend.waitdevice(dev);
22 net.up(dev);
23 net.backend.waitlink(dev);
24  
25 # Static configuration.
26 var("192.168.111.116") addr;
27 var("24") addr_prefix;
28 var("192.168.111.1") gateway;
29 var({"192.168.111.14", "193.2.1.66"}) dns_servers;
30  
31 # Assign IP address.
32 net.ipv4.addr(dev, addr, addr_prefix);
33  
34 # Go on configuring the network.
35 concat("NET-", dev) provide_name;
36 multiprovide(provide_name);
37 }
38  
39 # Example wired interface with DHCP configuration.
40 process wired_example_dhcp {
41 if("false"); # remove/comment to enable
42  
43 # Set device.
44 var("eth1") dev;
45  
46 # Wait for device.
47 net.backend.waitdevice(dev);
48 net.up(dev);
49 net.backend.waitlink(dev);
50  
51 # DHCP configuration.
52 net.ipv4.dhcp(dev) dhcp;
53 ip_in_network(dhcp.addr, "127.0.0.0", "8") test_local;
54 ifnot(test_local);
55 var(dhcp.addr) addr;
56 var(dhcp.prefix) addr_prefix;
57 var(dhcp.gateway) gateway;
58 var(dhcp.dns_servers) dns_servers;
59  
60 # Assign IP address.
61 net.ipv4.addr(dev, addr, addr_prefix);
62  
63 # Go on configuring the network.
64 concat("NET-", dev) provide_name;
65 multiprovide(provide_name);
66 }
67  
68 # Example wireless interface with DHCP configuration.
69 # This will use the wpa_supplicant configuration file /etc/wpa_supplicant/all.conf
70 # which should specify the wireless networks and other options.
71 process wireless_example_dhcp {
72 if("false"); # remove/comment to enable
73  
74 # Set device.
75 var("wlan0") dev;
76  
77 # Wait for device and rfkill.
78 net.backend.waitdevice(dev);
79 net.backend.rfkill("wlan", dev);
80  
81 # Connect to wireless network.
82 net.backend.wpa_supplicant(dev, "/etc/wpa_supplicant/all.conf", "/usr/sbin/wpa_supplicant", {});
83  
84 # DHCP configuration.
85 net.ipv4.dhcp(dev) dhcp;
86 ip_in_network(dhcp.addr, "127.0.0.0", "8") test_local;
87 ifnot(test_local);
88 var(dhcp.addr) addr;
89 var(dhcp.prefix) addr_prefix;
90 var(dhcp.gateway) gateway;
91 var(dhcp.dns_servers) dns_servers;
92  
93 # Assign IP address.
94 net.ipv4.addr(dev, addr, addr_prefix);
95  
96 # Go on configuring the network.
97 concat("NET-", dev) provide_name;
98 multiprovide(provide_name);
99 }
100  
101 # This process sets up routes and DNS servers for at most one of
102 # the working interfaces. It will change the configuration if a
103 # more important interface comes up while one is already up.
104 process NETCONF {
105 # Choose devices and priorities; put preferred devices to the front.
106 var({"NET-eth0", "NET-eth1", "NET-wlan0"}) provide_names;
107  
108 # Wait for one of the interfaces (and deinit/switch appropriately).
109 multidepend(provide_names) ifdep;
110  
111 # Alias device values.
112 var(ifdep.dev) dev;
113 var(ifdep.addr) addr;
114 var(ifdep.addr_prefix) addr_prefix;
115 var(ifdep.gateway) gateway;
116 var(ifdep.dns_servers) dns_servers;
117  
118 # Add default route.
119 net.ipv4.route("0.0.0.0", "0", gateway, "20", dev);
120  
121 # Configure DNS servers.
122 net.dns(dns_servers, "20");
123 }