system-dummy.c 7.2 KB

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