system-linux: add functions for adding/removing ip tunnels (currently only sit supported)
[project/netifd.git] / system-dummy.c
1 #include <sys/time.h>
2 #include <stdio.h>
3 #include <string.h>
4
5 #include <arpa/inet.h>
6
7 #ifndef DEBUG
8 #define DEBUG
9 #endif
10
11 #include "netifd.h"
12 #include "device.h"
13 #include "system.h"
14
15 int system_init(void)
16 {
17 return 0;
18 }
19
20 int system_bridge_addbr(struct device *bridge, struct bridge_config *cfg)
21 {
22 D(SYSTEM, "brctl addbr %s\n", bridge->ifname);
23 return 0;
24 }
25
26 int system_bridge_delbr(struct device *bridge)
27 {
28 D(SYSTEM, "brctl delbr %s\n", bridge->ifname);
29 return 0;
30 }
31
32 int system_bridge_addif(struct device *bridge, struct device *dev)
33 {
34 D(SYSTEM, "brctl addif %s %s\n", bridge->ifname, dev->ifname);
35 return 0;
36 }
37
38 int system_bridge_delif(struct device *bridge, struct device *dev)
39 {
40 D(SYSTEM, "brctl delif %s %s\n", bridge->ifname, dev->ifname);
41 return 0;
42 }
43
44 int system_vlan_add(struct device *dev, int id)
45 {
46 D(SYSTEM, "vconfig add %s %d\n", dev->ifname, id);
47 return 0;
48 }
49
50 int system_vlan_del(struct device *dev)
51 {
52 D(SYSTEM, "vconfig rem %s\n", dev->ifname);
53 return 0;
54 }
55
56 int system_if_up(struct device *dev)
57 {
58 D(SYSTEM, "ifconfig %s up\n", dev->ifname);
59 return 0;
60 }
61
62 int system_if_down(struct device *dev)
63 {
64 D(SYSTEM, "ifconfig %s down\n", dev->ifname);
65 return 0;
66 }
67
68 void system_if_clear_state(struct device *dev)
69 {
70 }
71
72 int system_if_check(struct device *dev)
73 {
74 dev->ifindex = 0;
75
76 if (!strcmp(dev->ifname, "eth0"))
77 device_set_present(dev, true);
78
79 return 0;
80 }
81
82 struct device *
83 system_if_get_parent(struct device *dev)
84 {
85 if (!strcmp(dev->ifname, "eth0"))
86 return device_get("eth1", true);
87
88 return NULL;
89 }
90
91 int
92 system_if_dump_info(struct device *dev, struct blob_buf *b)
93 {
94 blobmsg_add_u8(b, "link", dev->present);
95 return 0;
96 }
97
98 int
99 system_if_dump_stats(struct device *dev, struct blob_buf *b)
100 {
101 return 0;
102 }
103
104 int system_add_address(struct device *dev, struct device_addr *addr)
105 {
106 uint8_t *a = (uint8_t *) &addr->addr.in;
107 char ipaddr[64];
108
109 if ((addr->flags & DEVADDR_FAMILY) == DEVADDR_INET4) {
110 D(SYSTEM, "ifconfig %s add %d.%d.%d.%d/%d\n",
111 dev->ifname, a[0], a[1], a[2], a[3], addr->mask);
112 } else {
113 inet_ntop(AF_INET6, &addr->addr.in6, ipaddr, sizeof(struct in6_addr));
114 D(SYSTEM, "ifconfig %s add %s/%d\n",
115 dev->ifname, ipaddr, addr->mask);
116 return -1;
117 }
118
119 return 0;
120 }
121
122 int system_del_address(struct device *dev, struct device_addr *addr)
123 {
124 uint8_t *a = (uint8_t *) &addr->addr.in;
125 char ipaddr[64];
126
127 if ((addr->flags & DEVADDR_FAMILY) == DEVADDR_INET4) {
128 D(SYSTEM, "ifconfig %s del %d.%d.%d.%d\n",
129 dev->ifname, a[0], a[1], a[2], a[3]);
130 } else {
131 inet_ntop(AF_INET6, &addr->addr.in6, ipaddr, sizeof(struct in6_addr));
132 D(SYSTEM, "ifconfig %s del %s/%d\n",
133 dev->ifname, ipaddr, addr->mask);
134 return -1;
135 }
136
137 return 0;
138 }
139
140 int system_add_route(struct device *dev, struct device_route *route)
141 {
142 uint8_t *a1 = (uint8_t *) &route->addr.in;
143 uint8_t *a2 = (uint8_t *) &route->nexthop.in;
144 char addr[40], gw[40] = "", devstr[64] = "";
145
146 if ((route->flags & DEVADDR_FAMILY) != DEVADDR_INET4)
147 return -1;
148
149 if (!route->mask)
150 sprintf(addr, "default");
151 else
152 sprintf(addr, "%d.%d.%d.%d/%d",
153 a1[0], a1[1], a1[2], a1[3], route->mask);
154
155 if (memcmp(a2, "\x00\x00\x00\x00", 4) != 0)
156 sprintf(gw, " gw %d.%d.%d.%d",
157 a2[0], a2[1], a2[2], a2[3]);
158
159 if (route->flags & DEVADDR_DEVICE)
160 sprintf(devstr, " dev %s", dev->ifname);
161
162 if (route->metric > 0)
163 sprintf(devstr, " metric %d", route->metric);
164
165 D(SYSTEM, "route add %s%s%s\n", addr, gw, devstr);
166 return 0;
167 }
168
169 int system_del_route(struct device *dev, struct device_route *route)
170 {
171 uint8_t *a1 = (uint8_t *) &route->addr.in;
172 uint8_t *a2 = (uint8_t *) &route->nexthop.in;
173 char addr[40], gw[40] = "", devstr[64] = "";
174
175 if ((route->flags & DEVADDR_FAMILY) != DEVADDR_INET4)
176 return -1;
177
178 if (!route->mask)
179 sprintf(addr, "default");
180 else
181 sprintf(addr, "%d.%d.%d.%d/%d",
182 a1[0], a1[1], a1[2], a1[3], route->mask);
183
184 if (memcmp(a2, "\x00\x00\x00\x00", 4) != 0)
185 sprintf(gw, " gw %d.%d.%d.%d",
186 a2[0], a2[1], a2[2], a2[3]);
187
188 if (route->flags & DEVADDR_DEVICE)
189 sprintf(devstr, " dev %s", dev->ifname);
190
191 D(SYSTEM, "route del %s%s%s\n", addr, gw, devstr);
192 return 0;
193 }
194
195 int system_flush_routes(void)
196 {
197 return 0;
198 }
199
200 time_t system_get_rtime(void)
201 {
202 struct timeval tv;
203
204 if (gettimeofday(&tv, NULL) == 0)
205 return tv.tv_sec;
206
207 return 0;
208 }
209
210 int system_del_ip_tunnel(const char *name)
211 {
212 return 0;
213 }
214
215 int system_add_ip_tunnel(const char *name, struct blob_attr *attr)
216 {
217 return 0;
218 }