2
0

system-dummy.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  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. #include <sys/time.h>
  15. #include <stdio.h>
  16. #include <string.h>
  17. #include <arpa/inet.h>
  18. #ifndef DEBUG
  19. #define DEBUG
  20. #endif
  21. #include "netifd.h"
  22. #include "device.h"
  23. #include "system.h"
  24. int system_init(void)
  25. {
  26. return 0;
  27. }
  28. int system_bridge_addbr(struct device *bridge, struct bridge_config *cfg)
  29. {
  30. D(SYSTEM, "brctl addbr %s\n", bridge->ifname);
  31. return 0;
  32. }
  33. int system_bridge_delbr(struct device *bridge)
  34. {
  35. D(SYSTEM, "brctl delbr %s\n", bridge->ifname);
  36. return 0;
  37. }
  38. int system_bridge_addif(struct device *bridge, struct device *dev)
  39. {
  40. D(SYSTEM, "brctl addif %s %s\n", bridge->ifname, dev->ifname);
  41. return 0;
  42. }
  43. int system_bridge_delif(struct device *bridge, struct device *dev)
  44. {
  45. D(SYSTEM, "brctl delif %s %s\n", bridge->ifname, dev->ifname);
  46. return 0;
  47. }
  48. int system_vlan_add(struct device *dev, int id)
  49. {
  50. D(SYSTEM, "vconfig add %s %d\n", dev->ifname, id);
  51. return 0;
  52. }
  53. int system_vlan_del(struct device *dev)
  54. {
  55. D(SYSTEM, "vconfig rem %s\n", dev->ifname);
  56. return 0;
  57. }
  58. bool system_if_force_external(const char *ifname)
  59. {
  60. return false;
  61. }
  62. int system_if_up(struct device *dev)
  63. {
  64. D(SYSTEM, "ifconfig %s up\n", dev->ifname);
  65. return 0;
  66. }
  67. int system_if_down(struct device *dev)
  68. {
  69. D(SYSTEM, "ifconfig %s down\n", dev->ifname);
  70. return 0;
  71. }
  72. void system_if_clear_state(struct device *dev)
  73. {
  74. }
  75. int system_if_check(struct device *dev)
  76. {
  77. dev->ifindex = 0;
  78. if (!strcmp(dev->ifname, "eth0"))
  79. device_set_present(dev, true);
  80. return 0;
  81. }
  82. struct device *
  83. system_if_get_parent(struct device *dev)
  84. {
  85. if (!strcmp(dev->ifname, "eth0"))
  86. return device_get("eth1", true);
  87. return NULL;
  88. }
  89. int
  90. system_if_dump_info(struct device *dev, struct blob_buf *b)
  91. {
  92. blobmsg_add_u8(b, "link", dev->present);
  93. return 0;
  94. }
  95. int
  96. system_if_dump_stats(struct device *dev, struct blob_buf *b)
  97. {
  98. return 0;
  99. }
  100. void
  101. system_if_apply_settings(struct device *dev, struct device_settings *s)
  102. {
  103. }
  104. static int system_address_msg(struct device *dev, struct device_addr *addr, const char *type)
  105. {
  106. char ipaddr[64];
  107. int af = system_get_addr_family(addr->flags);
  108. D(SYSTEM, "ifconfig %s %s %s/%d\n",
  109. dev->ifname, type, inet_ntop(af, &addr->addr.in, ipaddr, sizeof(ipaddr)),
  110. addr->mask);
  111. return 0;
  112. }
  113. int system_add_address(struct device *dev, struct device_addr *addr)
  114. {
  115. return system_address_msg(dev, addr, "add");
  116. }
  117. int system_del_address(struct device *dev, struct device_addr *addr)
  118. {
  119. return system_address_msg(dev, addr, "del");
  120. }
  121. static int system_route_msg(struct device *dev, struct device_route *route, const char *type)
  122. {
  123. char addr[64], gw[64] = " gw ", devstr[64] = "";
  124. int af = system_get_addr_family(route->flags);
  125. int alen = system_get_addr_len(route->flags);
  126. static uint32_t zero_addr[4];
  127. if ((route->flags & DEVADDR_FAMILY) != DEVADDR_INET4)
  128. return -1;
  129. if (!route->mask)
  130. sprintf(addr, "default");
  131. else
  132. inet_ntop(af, &route->addr.in, addr, sizeof(addr));
  133. if (memcmp(&route->nexthop.in, (void *) zero_addr, alen) != 0)
  134. inet_ntop(af, &route->nexthop.in, gw + 4, sizeof(gw) - 4);
  135. else
  136. gw[0] = 0;
  137. if (dev)
  138. sprintf(devstr, " dev %s", dev->ifname);
  139. if (route->metric > 0)
  140. sprintf(devstr, " metric %d", route->metric);
  141. D(SYSTEM, "route %s %s%s%s\n", type, addr, gw, devstr);
  142. return 0;
  143. }
  144. int system_add_route(struct device *dev, struct device_route *route)
  145. {
  146. return system_route_msg(dev, route, "add");
  147. }
  148. int system_del_route(struct device *dev, struct device_route *route)
  149. {
  150. return system_route_msg(dev, route, "del");
  151. }
  152. int system_flush_routes(void)
  153. {
  154. return 0;
  155. }
  156. bool system_resolve_rt_table(const char *name, unsigned int *id)
  157. {
  158. *id = 0;
  159. return true;
  160. }
  161. int system_add_iprule(struct iprule *rule)
  162. {
  163. return 0;
  164. }
  165. int system_del_iprule(struct iprule *rule)
  166. {
  167. return 0;
  168. }
  169. int system_flush_iprules(void)
  170. {
  171. return 0;
  172. }
  173. bool system_resolve_iprule_action(const char *action, unsigned int *id)
  174. {
  175. *id = 0;
  176. return true;
  177. }
  178. time_t system_get_rtime(void)
  179. {
  180. struct timeval tv;
  181. if (gettimeofday(&tv, NULL) == 0)
  182. return tv.tv_sec;
  183. return 0;
  184. }
  185. int system_del_ip_tunnel(const char *name)
  186. {
  187. return 0;
  188. }
  189. int system_add_ip_tunnel(const char *name, struct blob_attr *attr)
  190. {
  191. return 0;
  192. }
  193. int system_update_ipv6_mtu(struct device *dev, int mtu)
  194. {
  195. return 0;
  196. }