system-dummy.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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. int system_add_address(struct device *dev, struct device_addr *addr)
  66. {
  67. uint8_t *a = (uint8_t *) &addr->addr.in;
  68. char ipaddr[64];
  69. if ((addr->flags & DEVADDR_FAMILY) == DEVADDR_INET4) {
  70. D(SYSTEM, "ifconfig %s add %d.%d.%d.%d/%d\n",
  71. dev->ifname, a[0], a[1], a[2], a[3], addr->mask);
  72. } else {
  73. inet_ntop(AF_INET6, &addr->addr.in6, ipaddr, sizeof(struct in6_addr));
  74. D(SYSTEM, "ifconfig %s add %s/%d\n",
  75. dev->ifname, ipaddr, addr->mask);
  76. return -1;
  77. }
  78. return 0;
  79. }
  80. int system_del_address(struct device *dev, struct device_addr *addr)
  81. {
  82. uint8_t *a = (uint8_t *) &addr->addr.in;
  83. char ipaddr[64];
  84. if ((addr->flags & DEVADDR_FAMILY) == DEVADDR_INET4) {
  85. D(SYSTEM, "ifconfig %s del %d.%d.%d.%d\n",
  86. dev->ifname, a[0], a[1], a[2], a[3]);
  87. } else {
  88. inet_ntop(AF_INET6, &addr->addr.in6, ipaddr, sizeof(struct in6_addr));
  89. D(SYSTEM, "ifconfig %s del %s/%d\n",
  90. dev->ifname, ipaddr, addr->mask);
  91. return -1;
  92. }
  93. return 0;
  94. }
  95. int system_add_route(struct device *dev, struct device_route *route)
  96. {
  97. uint8_t *a1 = (uint8_t *) &route->addr.in;
  98. uint8_t *a2 = (uint8_t *) &route->nexthop.in;
  99. char addr[40], gw[40] = "", devstr[64] = "";
  100. if ((route->flags & DEVADDR_FAMILY) != DEVADDR_INET4)
  101. return -1;
  102. if (!route->mask)
  103. sprintf(addr, "default");
  104. else
  105. sprintf(addr, "%d.%d.%d.%d/%d",
  106. a1[0], a1[1], a1[2], a1[3], route->mask);
  107. if (memcmp(a2, "\x00\x00\x00\x00", 4) != 0)
  108. sprintf(gw, " gw %d.%d.%d.%d",
  109. a2[0], a2[1], a2[2], a2[3]);
  110. if (route->flags & DEVADDR_DEVICE)
  111. sprintf(devstr, " dev %s", dev->ifname);
  112. D(SYSTEM, "route add %s%s%s\n", addr, gw, devstr);
  113. return 0;
  114. }
  115. int system_del_route(struct device *dev, struct device_route *route)
  116. {
  117. uint8_t *a1 = (uint8_t *) &route->addr.in;
  118. uint8_t *a2 = (uint8_t *) &route->nexthop.in;
  119. char addr[40], gw[40] = "", devstr[64] = "";
  120. if ((route->flags & DEVADDR_FAMILY) != DEVADDR_INET4)
  121. return -1;
  122. if (!route->mask)
  123. sprintf(addr, "default");
  124. else
  125. sprintf(addr, "%d.%d.%d.%d/%d",
  126. a1[0], a1[1], a1[2], a1[3], route->mask);
  127. if (memcmp(a2, "\x00\x00\x00\x00", 4) != 0)
  128. sprintf(gw, " gw %d.%d.%d.%d",
  129. a2[0], a2[1], a2[2], a2[3]);
  130. if (route->flags & DEVADDR_DEVICE)
  131. sprintf(devstr, " dev %s", dev->ifname);
  132. D(SYSTEM, "route del %s%s%s\n", addr, gw, devstr);
  133. return 0;
  134. }
  135. time_t system_get_rtime(void)
  136. {
  137. struct timeval tv;
  138. if (gettimeofday(&tv, NULL) == 0)
  139. return tv.tv_sec;
  140. return 0;
  141. }