fix clearing device state, trigger it on device_init()
[project/netifd.git] / system-dummy.c
1 #include <stdio.h>
2 #include <string.h>
3
4 #include <arpa/inet.h>
5
6 #ifndef DEBUG
7 #define DEBUG
8 #endif
9
10 #include "netifd.h"
11 #include "device.h"
12 #include "system.h"
13
14 int system_init(void)
15 {
16         return 0;
17 }
18
19 int system_bridge_addbr(struct device *bridge, struct bridge_config *cfg)
20 {
21         D(SYSTEM, "brctl addbr %s\n", bridge->ifname);
22         return 0;
23 }
24
25 int system_bridge_delbr(struct device *bridge)
26 {
27         D(SYSTEM, "brctl delbr %s\n", bridge->ifname);
28         return 0;
29 }
30
31 int system_bridge_addif(struct device *bridge, struct device *dev)
32 {
33         D(SYSTEM, "brctl addif %s %s\n", bridge->ifname, dev->ifname);
34         return 0;
35 }
36
37 int system_bridge_delif(struct device *bridge, struct device *dev)
38 {
39         D(SYSTEM, "brctl delif %s %s\n", bridge->ifname, dev->ifname);
40         return 0;
41 }
42
43 int system_vlan_add(struct device *dev, int id)
44 {
45         D(SYSTEM, "vconfig add %s %d\n", dev->ifname, id);
46         return 0;
47 }
48
49 int system_vlan_del(struct device *dev)
50 {
51         D(SYSTEM, "vconfig rem %s\n", dev->ifname);
52         return 0;
53 }
54
55 int system_if_up(struct device *dev)
56 {
57         D(SYSTEM, "ifconfig %s up\n", dev->ifname);
58         return 0;
59 }
60
61 int system_if_down(struct device *dev)
62 {
63         D(SYSTEM, "ifconfig %s down\n", dev->ifname);
64         return 0;
65 }
66
67 void system_if_clear_state(struct device *dev)
68 {
69         return 0;
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 int system_add_address(struct device *dev, struct device_addr *addr)
83 {
84         uint8_t *a = (uint8_t *) &addr->addr.in;
85         char ipaddr[64];
86
87         if ((addr->flags & DEVADDR_FAMILY) == DEVADDR_INET4) {
88                 D(SYSTEM, "ifconfig %s add %d.%d.%d.%d/%d\n",
89                         dev->ifname, a[0], a[1], a[2], a[3], addr->mask);
90         } else {
91                 inet_ntop(AF_INET6, &addr->addr.in6, ipaddr, sizeof(struct in6_addr));
92                 D(SYSTEM, "ifconfig %s add %s/%d\n",
93                         dev->ifname, ipaddr, addr->mask);
94                 return -1;
95         }
96
97         return 0;
98 }
99
100 int system_del_address(struct device *dev, struct device_addr *addr)
101 {
102         uint8_t *a = (uint8_t *) &addr->addr.in;
103         char ipaddr[64];
104
105         if ((addr->flags & DEVADDR_FAMILY) == DEVADDR_INET4) {
106                 D(SYSTEM, "ifconfig %s del %d.%d.%d.%d\n",
107                         dev->ifname, a[0], a[1], a[2], a[3]);
108         } else {
109                 inet_ntop(AF_INET6, &addr->addr.in6, ipaddr, sizeof(struct in6_addr));
110                 D(SYSTEM, "ifconfig %s del %s/%d\n",
111                         dev->ifname, ipaddr, addr->mask);
112                 return -1;
113         }
114
115         return 0;
116 }
117
118 int system_add_route(struct device *dev, struct device_route *route)
119 {
120         uint8_t *a1 = (uint8_t *) &route->addr.in;
121         uint8_t *a2 = (uint8_t *) &route->nexthop.in;
122         char addr[40], gw[40] = "", devstr[64] = "";
123
124         if ((route->flags & DEVADDR_FAMILY) != DEVADDR_INET4)
125                 return -1;
126
127         if (!route->mask)
128                 sprintf(addr, "default");
129         else
130                 sprintf(addr, "%d.%d.%d.%d/%d",
131                         a1[0], a1[1], a1[2], a1[3], route->mask);
132
133         if (memcmp(a2, "\x00\x00\x00\x00", 4) != 0)
134                 sprintf(gw, " gw %d.%d.%d.%d",
135                         a2[0], a2[1], a2[2], a2[3]);
136
137         if (route->flags & DEVADDR_DEVICE)
138                 sprintf(devstr, " dev %s", dev->ifname);
139
140         D(SYSTEM, "route add %s%s%s\n", addr, gw, devstr);
141         return 0;
142 }
143
144 int system_del_route(struct device *dev, struct device_route *route)
145 {
146         uint8_t *a1 = (uint8_t *) &route->addr.in;
147         uint8_t *a2 = (uint8_t *) &route->nexthop.in;
148         char addr[40], gw[40] = "", devstr[64] = "";
149
150         if ((route->flags & DEVADDR_FAMILY) != DEVADDR_INET4)
151                 return -1;
152
153         if (!route->mask)
154                 sprintf(addr, "default");
155         else
156                 sprintf(addr, "%d.%d.%d.%d/%d",
157                         a1[0], a1[1], a1[2], a1[3], route->mask);
158
159         if (memcmp(a2, "\x00\x00\x00\x00", 4) != 0)
160                 sprintf(gw, " gw %d.%d.%d.%d",
161                         a2[0], a2[1], a2[2], a2[3]);
162
163         if (route->flags & DEVADDR_DEVICE)
164                 sprintf(devstr, " dev %s", dev->ifname);
165
166         D(SYSTEM, "route del %s%s%s\n", addr, gw, devstr);
167         return 0;
168 }