system-dummy.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. #include <sys/time.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <arpa/inet.h>
  5. #ifndef DEBUG
  6. #define DEBUG
  7. #endif
  8. #include "netifd.h"
  9. #include "device.h"
  10. #include "system.h"
  11. int system_init(void)
  12. {
  13. return 0;
  14. }
  15. int system_bridge_addbr(struct device *bridge, struct bridge_config *cfg)
  16. {
  17. D(SYSTEM, "brctl addbr %s\n", bridge->ifname);
  18. return 0;
  19. }
  20. int system_bridge_delbr(struct device *bridge)
  21. {
  22. D(SYSTEM, "brctl delbr %s\n", bridge->ifname);
  23. return 0;
  24. }
  25. int system_bridge_addif(struct device *bridge, struct device *dev)
  26. {
  27. D(SYSTEM, "brctl addif %s %s\n", bridge->ifname, dev->ifname);
  28. return 0;
  29. }
  30. int system_bridge_delif(struct device *bridge, struct device *dev)
  31. {
  32. D(SYSTEM, "brctl delif %s %s\n", bridge->ifname, dev->ifname);
  33. return 0;
  34. }
  35. int system_vlan_add(struct device *dev, int id)
  36. {
  37. D(SYSTEM, "vconfig add %s %d\n", dev->ifname, id);
  38. return 0;
  39. }
  40. int system_vlan_del(struct device *dev)
  41. {
  42. D(SYSTEM, "vconfig rem %s\n", dev->ifname);
  43. return 0;
  44. }
  45. int system_if_up(struct device *dev)
  46. {
  47. D(SYSTEM, "ifconfig %s up\n", dev->ifname);
  48. return 0;
  49. }
  50. int system_if_down(struct device *dev)
  51. {
  52. D(SYSTEM, "ifconfig %s down\n", dev->ifname);
  53. return 0;
  54. }
  55. void system_if_clear_state(struct device *dev)
  56. {
  57. }
  58. int system_if_check(struct device *dev)
  59. {
  60. dev->ifindex = 0;
  61. if (!strcmp(dev->ifname, "eth0"))
  62. device_set_present(dev, true);
  63. return 0;
  64. }
  65. struct device *
  66. system_if_get_parent(struct device *dev)
  67. {
  68. if (!strcmp(dev->ifname, "eth0"))
  69. return device_get("eth1", true);
  70. return NULL;
  71. }
  72. int
  73. system_if_dump_info(struct device *dev, struct blob_buf *b)
  74. {
  75. blobmsg_add_u8(b, "link", dev->present);
  76. return 0;
  77. }
  78. int
  79. system_if_dump_stats(struct device *dev, struct blob_buf *b)
  80. {
  81. return 0;
  82. }
  83. int system_add_address(struct device *dev, struct device_addr *addr)
  84. {
  85. uint8_t *a = (uint8_t *) &addr->addr.in;
  86. char ipaddr[64];
  87. if ((addr->flags & DEVADDR_FAMILY) == DEVADDR_INET4) {
  88. D(SYSTEM, "ifconfig %s add %d.%d.%d.%d/%d\n",
  89. dev->ifname, a[0], a[1], a[2], a[3], addr->mask);
  90. } else {
  91. inet_ntop(AF_INET6, &addr->addr.in6, ipaddr, sizeof(struct in6_addr));
  92. D(SYSTEM, "ifconfig %s add %s/%d\n",
  93. dev->ifname, ipaddr, addr->mask);
  94. return -1;
  95. }
  96. return 0;
  97. }
  98. int system_del_address(struct device *dev, struct device_addr *addr)
  99. {
  100. uint8_t *a = (uint8_t *) &addr->addr.in;
  101. char ipaddr[64];
  102. if ((addr->flags & DEVADDR_FAMILY) == DEVADDR_INET4) {
  103. D(SYSTEM, "ifconfig %s del %d.%d.%d.%d\n",
  104. dev->ifname, a[0], a[1], a[2], a[3]);
  105. } else {
  106. inet_ntop(AF_INET6, &addr->addr.in6, ipaddr, sizeof(struct in6_addr));
  107. D(SYSTEM, "ifconfig %s del %s/%d\n",
  108. dev->ifname, ipaddr, addr->mask);
  109. return -1;
  110. }
  111. return 0;
  112. }
  113. int system_add_route(struct device *dev, struct device_route *route)
  114. {
  115. uint8_t *a1 = (uint8_t *) &route->addr.in;
  116. uint8_t *a2 = (uint8_t *) &route->nexthop.in;
  117. char addr[40], gw[40] = "", devstr[64] = "";
  118. if ((route->flags & DEVADDR_FAMILY) != DEVADDR_INET4)
  119. return -1;
  120. if (!route->mask)
  121. sprintf(addr, "default");
  122. else
  123. sprintf(addr, "%d.%d.%d.%d/%d",
  124. a1[0], a1[1], a1[2], a1[3], route->mask);
  125. if (memcmp(a2, "\x00\x00\x00\x00", 4) != 0)
  126. sprintf(gw, " gw %d.%d.%d.%d",
  127. a2[0], a2[1], a2[2], a2[3]);
  128. sprintf(devstr, " dev %s", dev->ifname);
  129. if (route->metric > 0)
  130. sprintf(devstr, " metric %d", route->metric);
  131. D(SYSTEM, "route add %s%s%s\n", addr, gw, devstr);
  132. return 0;
  133. }
  134. int system_del_route(struct device *dev, struct device_route *route)
  135. {
  136. uint8_t *a1 = (uint8_t *) &route->addr.in;
  137. uint8_t *a2 = (uint8_t *) &route->nexthop.in;
  138. char addr[40], gw[40] = "", devstr[64] = "";
  139. if ((route->flags & DEVADDR_FAMILY) != DEVADDR_INET4)
  140. return -1;
  141. if (!route->mask)
  142. sprintf(addr, "default");
  143. else
  144. sprintf(addr, "%d.%d.%d.%d/%d",
  145. a1[0], a1[1], a1[2], a1[3], route->mask);
  146. if (memcmp(a2, "\x00\x00\x00\x00", 4) != 0)
  147. sprintf(gw, " gw %d.%d.%d.%d",
  148. a2[0], a2[1], a2[2], a2[3]);
  149. sprintf(devstr, " dev %s", dev->ifname);
  150. D(SYSTEM, "route del %s%s%s\n", addr, gw, devstr);
  151. return 0;
  152. }
  153. int system_flush_routes(void)
  154. {
  155. return 0;
  156. }
  157. time_t system_get_rtime(void)
  158. {
  159. struct timeval tv;
  160. if (gettimeofday(&tv, NULL) == 0)
  161. return tv.tv_sec;
  162. return 0;
  163. }
  164. int system_del_ip_tunnel(const char *name)
  165. {
  166. return 0;
  167. }
  168. int system_add_ip_tunnel(const char *name, struct blob_attr *attr)
  169. {
  170. return 0;
  171. }