system-dummy.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  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_link_netns_move(const char *ifname, int netns_fd)
  49. {
  50. D(SYSTEM, "ip link %s netns %d\n", ifname, netns_fd);
  51. return 0;
  52. }
  53. int system_netns_open(const pid_t target_ns)
  54. {
  55. D(SYSTEM, "open netns of pid %d\n", target_ns);
  56. return 1;
  57. }
  58. int system_netns_set(int netns_fd)
  59. {
  60. D(SYSTEM, "set netns %d\n", netns_fd);
  61. return 0;
  62. }
  63. int system_vlan_add(struct device *dev, int id)
  64. {
  65. D(SYSTEM, "vconfig add %s %d\n", dev->ifname, id);
  66. return 0;
  67. }
  68. int system_vlan_del(struct device *dev)
  69. {
  70. D(SYSTEM, "vconfig rem %s\n", dev->ifname);
  71. return 0;
  72. }
  73. bool system_if_force_external(const char *ifname)
  74. {
  75. return false;
  76. }
  77. int system_if_up(struct device *dev)
  78. {
  79. D(SYSTEM, "ifconfig %s up\n", dev->ifname);
  80. return 0;
  81. }
  82. int system_if_down(struct device *dev)
  83. {
  84. D(SYSTEM, "ifconfig %s down\n", dev->ifname);
  85. return 0;
  86. }
  87. void system_if_get_settings(struct device *dev, struct device_settings *s)
  88. {
  89. }
  90. void system_if_clear_state(struct device *dev)
  91. {
  92. }
  93. int system_if_check(struct device *dev)
  94. {
  95. dev->ifindex = 0;
  96. device_set_present(dev, true);
  97. device_set_link(dev, true);
  98. return 0;
  99. }
  100. int system_if_resolve(struct device *dev)
  101. {
  102. return 0;
  103. }
  104. struct device *
  105. system_if_get_parent(struct device *dev)
  106. {
  107. return NULL;
  108. }
  109. int
  110. system_if_dump_info(struct device *dev, struct blob_buf *b)
  111. {
  112. blobmsg_add_u8(b, "link", dev->present);
  113. return 0;
  114. }
  115. int
  116. system_if_dump_stats(struct device *dev, struct blob_buf *b)
  117. {
  118. return 0;
  119. }
  120. void
  121. system_if_apply_settings(struct device *dev, struct device_settings *s, unsigned int apply_mask)
  122. {
  123. }
  124. static int system_address_msg(struct device *dev, struct device_addr *addr, const char *type)
  125. {
  126. char ipaddr[64];
  127. int af = system_get_addr_family(addr->flags);
  128. D(SYSTEM, "ifconfig %s %s %s/%u\n",
  129. dev->ifname, type, inet_ntop(af, &addr->addr.in, ipaddr, sizeof(ipaddr)),
  130. addr->mask);
  131. return 0;
  132. }
  133. int system_add_address(struct device *dev, struct device_addr *addr)
  134. {
  135. return system_address_msg(dev, addr, "add");
  136. }
  137. int system_del_address(struct device *dev, struct device_addr *addr)
  138. {
  139. return system_address_msg(dev, addr, "del");
  140. }
  141. static int system_route_msg(struct device *dev, struct device_route *route, const char *type)
  142. {
  143. char addr[64], gw[64] = " gw ", devstr[64] = "";
  144. int af = system_get_addr_family(route->flags);
  145. int alen = system_get_addr_len(route->flags);
  146. static uint32_t zero_addr[4];
  147. if ((route->flags & DEVADDR_FAMILY) != DEVADDR_INET4)
  148. return -1;
  149. if (!route->mask)
  150. sprintf(addr, "default");
  151. else
  152. inet_ntop(af, &route->addr.in, addr, sizeof(addr));
  153. if (memcmp(&route->nexthop.in, (void *) zero_addr, alen) != 0)
  154. inet_ntop(af, &route->nexthop.in, gw + 4, sizeof(gw) - 4);
  155. else
  156. gw[0] = 0;
  157. if (dev)
  158. sprintf(devstr, " dev %s", dev->ifname);
  159. if (route->metric > 0)
  160. sprintf(devstr, " metric %d", route->metric);
  161. D(SYSTEM, "route %s %s%s%s\n", type, addr, gw, devstr);
  162. return 0;
  163. }
  164. static int system_neighbor_msg(struct device *dev, struct device_neighbor *neighbor, const char *type)
  165. {
  166. char addr[64];
  167. int af = system_get_addr_family(neighbor->flags);
  168. inet_ntop(af, &neighbor->addr.in , addr, sizeof(addr));
  169. D(SYSTEM, "neigh %s %s%s%s %s\n", type, addr, neighbor->proxy ? "proxy " : "",
  170. (neighbor->flags & DEVNEIGH_MAC) ? format_macaddr(neighbor->macaddr) : "",
  171. neighbor->router ? "router": "");
  172. }
  173. int system_add_neighbor(struct device *dev, struct device_neighbor *neighbor)
  174. {
  175. return system_neighbor_msg(dev, neighbor, "add");
  176. }
  177. int system_del_neighbor(struct device *dev, struct device_neighbor *neighbor)
  178. {
  179. return system_neighbor_msg(dev, neighbor, "del");
  180. }
  181. int system_add_route(struct device *dev, struct device_route *route)
  182. {
  183. return system_route_msg(dev, route, "add");
  184. }
  185. int system_del_route(struct device *dev, struct device_route *route)
  186. {
  187. return system_route_msg(dev, route, "del");
  188. }
  189. int system_flush_routes(void)
  190. {
  191. return 0;
  192. }
  193. bool system_resolve_rt_type(const char *type, unsigned int *id)
  194. {
  195. *id = 0;
  196. return true;
  197. }
  198. bool system_resolve_rt_proto(const char *type, unsigned int *id)
  199. {
  200. *id = 0;
  201. return true;
  202. }
  203. bool system_resolve_rt_table(const char *name, unsigned int *id)
  204. {
  205. *id = 0;
  206. return true;
  207. }
  208. bool system_is_default_rt_table(unsigned int id)
  209. {
  210. return true;
  211. }
  212. bool system_resolve_rpfilter(const char *filter, unsigned int *id)
  213. {
  214. *id = 0;
  215. return true;
  216. }
  217. int system_add_iprule(struct iprule *rule)
  218. {
  219. return 0;
  220. }
  221. int system_del_iprule(struct iprule *rule)
  222. {
  223. return 0;
  224. }
  225. int system_flush_iprules(void)
  226. {
  227. return 0;
  228. }
  229. bool system_resolve_iprule_action(const char *action, unsigned int *id)
  230. {
  231. *id = 0;
  232. return true;
  233. }
  234. time_t system_get_rtime(void)
  235. {
  236. struct timeval tv;
  237. if (gettimeofday(&tv, NULL) == 0)
  238. return tv.tv_sec;
  239. return 0;
  240. }
  241. int system_del_ip_tunnel(const char *name, struct blob_attr *attr)
  242. {
  243. return 0;
  244. }
  245. int system_add_ip_tunnel(const char *name, struct blob_attr *attr)
  246. {
  247. return 0;
  248. }
  249. int system_update_ipv6_mtu(struct device *dev, int mtu)
  250. {
  251. return 0;
  252. }
  253. int system_macvlan_add(struct device *macvlan, struct device *dev, struct macvlan_config *cfg)
  254. {
  255. return 0;
  256. }
  257. int system_macvlan_del(struct device *macvlan)
  258. {
  259. return 0;
  260. }
  261. int system_veth_add(struct device *veth, struct veth_config *cfg)
  262. {
  263. return 0;
  264. }
  265. int system_veth_del(struct device *veth)
  266. {
  267. return 0;
  268. }
  269. int system_vlandev_add(struct device *vlandev, struct device *dev, struct vlandev_config *cfg)
  270. {
  271. return 0;
  272. }
  273. int system_vlandev_del(struct device *vlandev)
  274. {
  275. return 0;
  276. }