add forced shell proto setup kill (timeout: 1 second)
[project/netifd.git] / system-dummy.c
1 #include <stdio.h>
2 #include <string.h>
3
4 #ifndef DEBUG
5 #define DEBUG
6 #endif
7
8 #include "netifd.h"
9 #include "device.h"
10 #include "system.h"
11
12 int system_bridge_addbr(struct device *bridge)
13 {
14 DPRINTF("brctl addbr %s\n", bridge->ifname);
15 return 0;
16 }
17
18 int system_bridge_delbr(struct device *bridge)
19 {
20 DPRINTF("brctl delbr %s\n", bridge->ifname);
21 return 0;
22 }
23
24 int system_bridge_addif(struct device *bridge, struct device *dev)
25 {
26 DPRINTF("brctl addif %s %s\n", bridge->ifname, dev->ifname);
27 return 0;
28 }
29
30 int system_bridge_delif(struct device *bridge, struct device *dev)
31 {
32 DPRINTF("brctl delif %s %s\n", bridge->ifname, dev->ifname);
33 return 0;
34 }
35
36 int system_vlan_add(struct device *dev, int id)
37 {
38 DPRINTF("vconfig add %s %d\n", dev->ifname, id);
39 return 0;
40 }
41
42 int system_vlan_del(struct device *dev)
43 {
44 DPRINTF("vconfig rem %s\n", dev->ifname);
45 return 0;
46 }
47
48 int system_if_up(struct device *dev)
49 {
50 DPRINTF("ifconfig %s up\n", dev->ifname);
51 return 0;
52 }
53
54 int system_if_down(struct device *dev)
55 {
56 DPRINTF("ifconfig %s down\n", dev->ifname);
57 return 0;
58 }
59
60 int system_if_check(struct device *dev)
61 {
62 dev->ifindex = 0;
63
64 if (!strcmp(dev->ifname, "eth0"))
65 device_set_present(dev, true);
66
67 return 0;
68 }
69
70 int system_add_address(struct device *dev, struct device_addr *addr)
71 {
72 uint8_t *a = (uint8_t *) &addr->addr.in;
73
74 if ((addr->flags & DEVADDR_FAMILY) == DEVADDR_INET4) {
75 DPRINTF("ifconfig %s add %d.%d.%d.%d/%d\n",
76 dev->ifname, a[0], a[1], a[2], a[3], addr->mask);
77 } else {
78 return -1;
79 }
80
81 return 0;
82 }
83
84 int system_del_address(struct device *dev, struct device_addr *addr)
85 {
86 uint8_t *a = (uint8_t *) &addr->addr.in;
87
88 if ((addr->flags & DEVADDR_FAMILY) == DEVADDR_INET4) {
89 DPRINTF("ifconfig %s del %d.%d.%d.%d\n",
90 dev->ifname, a[0], a[1], a[2], a[3]);
91 } else {
92 return -1;
93 }
94
95 return 0;
96 }
97
98 int system_add_route(struct device *dev, struct device_route *route)
99 {
100 uint8_t *a1 = (uint8_t *) &route->addr.in;
101 uint8_t *a2 = (uint8_t *) &route->nexthop.in;
102 char addr[40], gw[40] = "", devstr[64] = "";
103
104 if ((route->flags & DEVADDR_FAMILY) != DEVADDR_INET4)
105 return -1;
106
107 if (!route->mask)
108 sprintf(addr, "default");
109 else
110 sprintf(addr, "%d.%d.%d.%d/%d",
111 a1[0], a1[1], a1[2], a1[3], route->mask);
112
113 if (memcmp(a2, "\x00\x00\x00\x00", 4) != 0)
114 sprintf(gw, " gw %d.%d.%d.%d",
115 a2[0], a2[1], a2[2], a2[3]);
116
117 if (route->flags & DEVADDR_DEVICE)
118 sprintf(devstr, " dev %s", dev->ifname);
119
120 DPRINTF("route add %s%s%s\n", addr, gw, devstr);
121 return 0;
122 }
123
124 int system_del_route(struct device *dev, struct device_route *route)
125 {
126 uint8_t *a1 = (uint8_t *) &route->addr.in;
127 uint8_t *a2 = (uint8_t *) &route->nexthop.in;
128 char addr[40], gw[40] = "", devstr[64] = "";
129
130 if ((route->flags & DEVADDR_FAMILY) != DEVADDR_INET4)
131 return -1;
132
133 if (!route->mask)
134 sprintf(addr, "default");
135 else
136 sprintf(addr, "%d.%d.%d.%d/%d",
137 a1[0], a1[1], a1[2], a1[3], route->mask);
138
139 if (memcmp(a2, "\x00\x00\x00\x00", 4) != 0)
140 sprintf(gw, " gw %d.%d.%d.%d",
141 a2[0], a2[1], a2[2], a2[3]);
142
143 if (route->flags & DEVADDR_DEVICE)
144 sprintf(devstr, " dev %s", dev->ifname);
145
146 DPRINTF("route del %s%s%s\n", addr, gw, devstr);
147 return 0;
148 }