system-dummy.c 7.7 KB

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