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