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 bool system_if_is_point_to_point(struct device *dev) 145 { 146 return false; 147 } 148 149 int system_if_resolve(struct device *dev) 150 { 151 return 1; 152 } 153 154 struct device * 155 system_if_get_parent(struct device *dev) 156 { 157 return NULL; 158 } 159 160 int 161 system_if_dump_info(struct device *dev, struct blob_buf *b) 162 { 163 blobmsg_add_u8(b, "link", dev->present); 164 return 0; 165 } 166 167 int 168 system_if_dump_stats(struct device *dev, struct blob_buf *b) 169 { 170 return 0; 171 } 172 173 void 174 system_if_apply_settings(struct device *dev, struct device_settings *s, uint64_t apply_mask) 175 { 176 apply_mask &= s->flags; 177 178 if ((apply_mask & (DEV_OPT_MACADDR | DEV_OPT_DEFAULT_MACADDR)) && !dev->external) { 179 D(SYSTEM, "ifconfig %s hw ether %s", 180 dev->ifname, format_macaddr(s->macaddr)); 181 } 182 } 183 184 void system_if_apply_settings_after_up(struct device *dev, struct device_settings *s) 185 { 186 } 187 188 static int system_address_msg(struct device *dev, struct device_addr *addr, const char *type) 189 { 190 char ipaddr[64]; 191 int af = system_get_addr_family(addr->flags); 192 193 D(SYSTEM, "ifconfig %s %s %s/%u", 194 dev->ifname, type, inet_ntop(af, &addr->addr.in, ipaddr, sizeof(ipaddr)), 195 addr->mask); 196 197 return 0; 198 } 199 200 int system_add_address(struct device *dev, struct device_addr *addr) 201 { 202 return system_address_msg(dev, addr, "add"); 203 } 204 205 int system_del_address(struct device *dev, struct device_addr *addr) 206 { 207 return system_address_msg(dev, addr, "del"); 208 } 209 210 static int system_route_msg(struct device *dev, struct device_route *route, const char *type) 211 { 212 char addr[64], gw[64] = " gw ", devstr[64] = ""; 213 int af = system_get_addr_family(route->flags); 214 int alen = system_get_addr_len(route->flags); 215 static uint32_t zero_addr[4]; 216 217 if ((route->flags & DEVADDR_FAMILY) != DEVADDR_INET4) 218 return -1; 219 220 if (!route->mask) 221 sprintf(addr, "default"); 222 else 223 inet_ntop(af, &route->addr.in, addr, sizeof(addr)); 224 225 if (memcmp(&route->nexthop.in, (void *) zero_addr, alen) != 0) 226 inet_ntop(af, &route->nexthop.in, gw + 4, sizeof(gw) - 4); 227 else 228 gw[0] = 0; 229 230 if (dev) 231 sprintf(devstr, " dev %s", dev->ifname); 232 233 if (route->metric > 0) 234 sprintf(devstr + strlen(devstr), " metric %d", route->metric); 235 236 D(SYSTEM, "route %s %s%s%s", type, addr, gw, devstr); 237 return 0; 238 } 239 240 static int system_neighbor_msg(struct device *dev, struct device_neighbor *neighbor, const char *type) 241 { 242 char addr[64]; 243 int af = system_get_addr_family(neighbor->flags); 244 inet_ntop(af, &neighbor->addr.in , addr, sizeof(addr)); 245 246 D(SYSTEM, "neigh %s %s%s%s %s", type, addr, neighbor->proxy ? "proxy " : "", 247 (neighbor->flags & DEVNEIGH_MAC) ? format_macaddr(neighbor->macaddr) : "", 248 neighbor->router ? "router": ""); 249 return 0; 250 } 251 252 int system_add_neighbor(struct device *dev, struct device_neighbor *neighbor) 253 { 254 return system_neighbor_msg(dev, neighbor, "add"); 255 } 256 257 int system_del_neighbor(struct device *dev, struct device_neighbor *neighbor) 258 { 259 return system_neighbor_msg(dev, neighbor, "del"); 260 } 261 262 int system_add_route(struct device *dev, struct device_route *route) 263 { 264 return system_route_msg(dev, route, "add"); 265 } 266 267 int system_del_route(struct device *dev, struct device_route *route) 268 { 269 return system_route_msg(dev, route, "del"); 270 } 271 272 int system_flush_routes(void) 273 { 274 return 0; 275 } 276 277 bool system_resolve_rt_type(const char *type, unsigned int *id) 278 { 279 *id = 0; 280 return true; 281 } 282 283 bool system_resolve_rt_proto(const char *type, unsigned int *id) 284 { 285 *id = 0; 286 return true; 287 } 288 289 bool system_resolve_rt_table(const char *name, unsigned int *id) 290 { 291 *id = 0; 292 return true; 293 } 294 295 bool system_is_default_rt_table(unsigned int id) 296 { 297 return true; 298 } 299 300 bool system_resolve_rpfilter(const char *filter, unsigned int *id) 301 { 302 *id = 0; 303 return true; 304 } 305 306 int system_add_iprule(struct iprule *rule) 307 { 308 return 0; 309 } 310 311 int system_del_iprule(struct iprule *rule) 312 { 313 return 0; 314 } 315 316 int system_flush_iprules(void) 317 { 318 return 0; 319 } 320 321 bool system_resolve_iprule_ipproto(const char *name, unsigned int *id) 322 { 323 *id = 0; 324 return true; 325 } 326 327 bool system_resolve_iprule_action(const char *action, unsigned int *id) 328 { 329 *id = 0; 330 return true; 331 } 332 333 time_t system_get_rtime(void) 334 { 335 struct timeval tv; 336 337 if (gettimeofday(&tv, NULL) == 0) 338 return tv.tv_sec; 339 340 return 0; 341 } 342 343 int system_del_ip_tunnel(const struct device *dev) 344 { 345 return 0; 346 } 347 348 int system_add_ip_tunnel(const struct device *dev, struct blob_attr *attr) 349 { 350 return 0; 351 } 352 353 int system_update_ipv6_mtu(struct device *dev, int mtu) 354 { 355 return 0; 356 } 357 358 int system_macvlan_add(struct device *macvlan, struct device *dev, struct macvlan_config *cfg) 359 { 360 return 0; 361 } 362 363 int system_macvlan_del(struct device *macvlan) 364 { 365 return 0; 366 } 367 368 int system_veth_add(struct device *veth, struct veth_config *cfg) 369 { 370 return 0; 371 } 372 373 int system_veth_del(struct device *veth) 374 { 375 return 0; 376 } 377 378 int system_vlandev_add(struct device *vlandev, struct device *dev, struct vlandev_config *cfg) 379 { 380 return 0; 381 } 382 383 int system_vlandev_del(struct device *vlandev) 384 { 385 return 0; 386 } 387 388 int system_vrf_addvrf(struct device *vrf, unsigned int table) 389 { 390 return 0; 391 } 392 393 int system_vrf_delvrf(struct device *vrf) 394 { 395 return 0; 396 } 397 398 int system_vrf_addif(struct device *vrf, struct device *dev) 399 { 400 return 0; 401 } 402 403 int system_vrf_delif(struct device *vrf, struct device *dev) 404 { 405 return 0; 406 } 407 408 void system_tcp_l3mdev(bool enable) 409 { 410 } 411 412 void system_udp_l3mdev(bool enable) 413 { 414 } 415
This page was automatically generated by LXR 0.3.1. • OpenWrt