add interface uptime to the status info
[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 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 }
169
170 time_t system_get_rtime(void)
171 {
172         struct timeval tv;
173
174         if (gettimeofday(&tv, NULL) == 0)
175                 return tv.tv_sec;
176
177         return 0;
178 }