1 /* 2 * netifd - network interface daemon 3 * Copyright (C) 2012 Felix Fietkau <nbd@openwrt.org> 4 * 5 * This program is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License version 2 7 * as published by the Free Software Foundation 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 */ 14 #define SYSTEM_IMPL 15 #include <sys/time.h> 16 #include <stdio.h> 17 #include <string.h> 18 19 #include <arpa/inet.h> 20 21 #ifndef DEBUG 22 #define DEBUG 23 #endif 24 25 #include "netifd.h" 26 #include "device.h" 27 #include "system.h" 28 29 int system_init(void) 30 { 31 return 0; 32 } 33 34 int system_bridge_addbr(struct device *bridge, struct bridge_config *cfg) 35 { 36 return 0; 37 } 38 39 int system_bridge_delbr(struct device *bridge) 40 { 41 return 0; 42 } 43 44 int system_bridge_addif(struct device *bridge, struct device *dev) 45 { 46 return 0; 47 } 48 49 int system_bridge_delif(struct device *bridge, struct device *dev) 50 { 51 return 0; 52 } 53 54 int system_bridge_vlan(const char *iface, uint16_t vid, int16_t vid_end, bool add, unsigned int vflags) 55 { 56 return 0; 57 } 58 59 void system_bridge_set_stp_state(struct device *dev, bool val) 60 { 61 } 62 63 int system_bridge_vlan_check(struct device *dev, char *ifname) 64 { 65 return 0; 66 } 67 68 int system_bonding_set_device(struct device *dev, struct bonding_config *cfg) 69 { 70 return 0; 71 } 72 73 int system_bonding_set_port(struct device *dev, struct device *port, bool add, bool primary) 74 { 75 return 0; 76 } 77 78 int system_link_netns_move(struct device *dev, int netns_fd, const char *target_ifname) 79 { 80 D(SYSTEM, "ip link set %s name %s netns %d", dev->ifname, target_ifname, netns_fd); 81 return 0; 82 } 83 84 int system_netns_open(const pid_t target_ns) 85 { 86 D(SYSTEM, "open netns of pid %d", target_ns); 87 return 1; 88 } 89 90 int system_netns_set(int netns_fd) 91 { 92 D(SYSTEM, "set netns %d", netns_fd); 93 return 0; 94 } 95 96 int system_vlan_add(struct device *dev, int id) 97 { 98 D(SYSTEM, "vconfig add %s %d", dev->ifname, id); 99 return 0; 100 } 101 102 int system_vlan_del(struct device *dev) 103 { 104 D(SYSTEM, "vconfig rem %s", dev->ifname); 105 return 0; 106 } 107 108 bool system_if_force_external(const char *ifname) 109 { 110 return false; 111 } 112 113 int system_if_up(struct device *dev) 114 { 115 D(SYSTEM, "ifconfig %s up", dev->ifname); 116 return 0; 117 } 118 119 int system_if_down(struct device *dev) 120 { 121 D(SYSTEM, "ifconfig %s down", dev->ifname); 122 return 0; 123 } 124 125 void system_if_get_settings(struct device *dev, struct device_settings *s) 126 { 127 } 128 129 void system_if_clear_state(struct device *dev) 130 { 131 device_set_ifindex(dev, system_if_resolve(dev)); 132 } 133 134 int system_if_check(struct device *dev) 135 { 136 if (dev->type == &simple_device_type) 137 device_set_present(dev, true); 138 139 device_set_link(dev, true); 140 141 return 0; 142 } 143 144 int system_if_resolve(struct device *dev) 145 { 146 return 1; 147 } 148 149 struct device * 150 system_if_get_parent(struct device *dev) 151 { 152 return NULL; 153 } 154 155 int 156 system_if_dump_info(struct device *dev, struct blob_buf *b) 157 { 158 blobmsg_add_u8(b, "link", dev->present); 159 return 0; 160 } 161 162 int 163 system_if_dump_stats(struct device *dev, struct blob_buf *b) 164 { 165 return 0; 166 } 167 168 void 169 system_if_apply_settings(struct device *dev, struct device_settings *s, uint64_t apply_mask) 170 { 171 apply_mask &= s->flags; 172 173 if ((apply_mask & (DEV_OPT_MACADDR | DEV_OPT_DEFAULT_MACADDR)) && !dev->external) { 174 D(SYSTEM, "ifconfig %s hw ether %s", 175 dev->ifname, format_macaddr(s->macaddr)); 176 } 177 } 178 179 void system_if_apply_settings_after_up(struct device *dev, struct device_settings *s) 180 { 181 } 182 183 static int system_address_msg(struct device *dev, struct device_addr *addr, const char *type) 184 { 185 char ipaddr[64]; 186 int af = system_get_addr_family(addr->flags); 187 188 D(SYSTEM, "ifconfig %s %s %s/%u", 189 dev->ifname, type, inet_ntop(af, &addr->addr.in, ipaddr, sizeof(ipaddr)), 190 addr->mask); 191 192 return 0; 193 } 194 195 int system_add_address(struct device *dev, struct device_addr *addr) 196 { 197 return system_address_msg(dev, addr, "add"); 198 } 199 200 int system_del_address(struct device *dev, struct device_addr *addr) 201 { 202 return system_address_msg(dev, addr, "del"); 203 } 204 205 static int system_route_msg(struct device *dev, struct device_route *route, const char *type) 206 { 207 char addr[64], gw[64] = " gw ", devstr[64] = ""; 208 int af = system_get_addr_family(route->flags); 209 int alen = system_get_addr_len(route->flags); 210 static uint32_t zero_addr[4]; 211 212 if ((route->flags & DEVADDR_FAMILY) != DEVADDR_INET4) 213 return -1; 214 215 if (!route->mask) 216 sprintf(addr, "default"); 217 else 218 inet_ntop(af, &route->addr.in, addr, sizeof(addr)); 219 220 if (memcmp(&route->nexthop.in, (void *) zero_addr, alen) != 0) 221 inet_ntop(af, &route->nexthop.in, gw + 4, sizeof(gw) - 4); 222 else 223 gw[0] = 0; 224 225 if (dev) 226 sprintf(devstr, " dev %s", dev->ifname); 227 228 if (route->metric > 0) 229 sprintf(devstr, " metric %d", route->metric); 230 231 D(SYSTEM, "route %s %s%s%s", type, addr, gw, devstr); 232 return 0; 233 } 234 235 static int system_neighbor_msg(struct device *dev, struct device_neighbor *neighbor, const char *type) 236 { 237 char addr[64]; 238 int af = system_get_addr_family(neighbor->flags); 239 inet_ntop(af, &neighbor->addr.in , addr, sizeof(addr)); 240 241 D(SYSTEM, "neigh %s %s%s%s %s", type, addr, neighbor->proxy ? "proxy " : "", 242 (neighbor->flags & DEVNEIGH_MAC) ? format_macaddr(neighbor->macaddr) : "", 243 neighbor->router ? "router": ""); 244 return 0; 245 } 246 247 int system_add_neighbor(struct device *dev, struct device_neighbor *neighbor) 248 { 249 return system_neighbor_msg(dev, neighbor, "add"); 250 } 251 252 int system_del_neighbor(struct device *dev, struct device_neighbor *neighbor) 253 { 254 return system_neighbor_msg(dev, neighbor, "del"); 255 } 256 257 int system_add_route(struct device *dev, struct device_route *route) 258 { 259 return system_route_msg(dev, route, "add"); 260 } 261 262 int system_del_route(struct device *dev, struct device_route *route) 263 { 264 return system_route_msg(dev, route, "del"); 265 } 266 267 int system_flush_routes(void) 268 { 269 return 0; 270 } 271 272 bool system_resolve_rt_type(const char *type, unsigned int *id) 273 { 274 *id = 0; 275 return true; 276 } 277 278 bool system_resolve_rt_proto(const char *type, unsigned int *id) 279 { 280 *id = 0; 281 return true; 282 } 283 284 bool system_resolve_rt_table(const char *name, unsigned int *id) 285 { 286 *id = 0; 287 return true; 288 } 289 290 bool system_is_default_rt_table(unsigned int id) 291 { 292 return true; 293 } 294 295 bool system_resolve_rpfilter(const char *filter, unsigned int *id) 296 { 297 *id = 0; 298 return true; 299 } 300 301 int system_add_iprule(struct iprule *rule) 302 { 303 return 0; 304 } 305 306 int system_del_iprule(struct iprule *rule) 307 { 308 return 0; 309 } 310 311 int system_flush_iprules(void) 312 { 313 return 0; 314 } 315 316 bool system_resolve_iprule_ipproto(const char *name, unsigned int *id) 317 { 318 *id = 0; 319 return true; 320 } 321 322 bool system_resolve_iprule_action(const char *action, unsigned int *id) 323 { 324 *id = 0; 325 return true; 326 } 327 328 time_t system_get_rtime(void) 329 { 330 struct timeval tv; 331 332 if (gettimeofday(&tv, NULL) == 0) 333 return tv.tv_sec; 334 335 return 0; 336 } 337 338 int system_del_ip_tunnel(const struct device *dev) 339 { 340 return 0; 341 } 342 343 int system_add_ip_tunnel(const struct device *dev, struct blob_attr *attr) 344 { 345 return 0; 346 } 347 348 int system_update_ipv6_mtu(struct device *dev, int mtu) 349 { 350 return 0; 351 } 352 353 int system_macvlan_add(struct device *macvlan, struct device *dev, struct macvlan_config *cfg) 354 { 355 return 0; 356 } 357 358 int system_macvlan_del(struct device *macvlan) 359 { 360 return 0; 361 } 362 363 int system_veth_add(struct device *veth, struct veth_config *cfg) 364 { 365 return 0; 366 } 367 368 int system_veth_del(struct device *veth) 369 { 370 return 0; 371 } 372 373 int system_vlandev_add(struct device *vlandev, struct device *dev, struct vlandev_config *cfg) 374 { 375 return 0; 376 } 377 378 int system_vlandev_del(struct device *vlandev) 379 { 380 return 0; 381 } 382 383 int system_vrf_addvrf(struct device *vrf, unsigned int table) 384 { 385 return 0; 386 } 387 388 int system_vrf_delvrf(struct device *vrf) 389 { 390 return 0; 391 } 392 393 int system_vrf_addif(struct device *vrf, struct device *dev) 394 { 395 return 0; 396 } 397 398 int system_vrf_delif(struct device *vrf, struct device *dev) 399 { 400 return 0; 401 } 402 403 void system_tcp_l3mdev(bool enable) 404 { 405 } 406 407 void system_udp_l3mdev(bool enable) 408 { 409 } 410
This page was automatically generated by LXR 0.3.1. • OpenWrt