net_queue_ramroute.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. /****************************************************************************
  2. * net/route/net_queue_ramroute.c
  3. *
  4. * Copyright (C) 2017 Gregory Nutt. All rights reserved.
  5. * Author: Gregory Nutt <gnutt@nuttx.org>
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions
  9. * are met:
  10. *
  11. * 1. Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. * 2. Redistributions in binary form must reproduce the above copyright
  14. * notice, this list of conditions and the following disclaimer in
  15. * the documentation and/or other materials provided with the
  16. * distribution.
  17. * 3. Neither the name NuttX nor the names of its contributors may be
  18. * used to endorse or promote products derived from this software
  19. * without specific prior written permission.
  20. *
  21. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  24. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  25. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  26. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  27. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  28. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  29. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  30. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  31. * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  32. * POSSIBILITY OF SUCH DAMAGE.
  33. *
  34. ****************************************************************************/
  35. /****************************************************************************
  36. * Included Files
  37. ****************************************************************************/
  38. #include <nuttx/config.h>
  39. #include "route/ramroute.h"
  40. #include "route/route.h"
  41. #if defined(CONFIG_ROUTE_IPv4_RAMROUTE) || defined(CONFIG_ROUTE_IPv6_RAMROUTE)
  42. /****************************************************************************
  43. * Public Functions
  44. ****************************************************************************/
  45. /****************************************************************************
  46. * Name: ramroute_ipv4_addlast/ramroute_ipv6_addlast
  47. *
  48. * Description:
  49. * Remove the entry at the end of an IPv4/IPv6 routing table list
  50. *
  51. * Input Parameters:
  52. * entry - A pointer to the new entry to add to the list
  53. * list - The list to be used.
  54. *
  55. * Returned Value:
  56. * None
  57. *
  58. ****************************************************************************/
  59. #ifdef CONFIG_ROUTE_IPv4_RAMROUTE
  60. void ramroute_ipv4_addlast(FAR struct net_route_ipv4_entry_s *entry,
  61. FAR struct net_route_ipv4_queue_s *list)
  62. {
  63. entry->flink = NULL;
  64. if (!list->head)
  65. {
  66. list->head = entry;
  67. list->tail = entry;
  68. }
  69. else
  70. {
  71. list->tail->flink = entry;
  72. list->tail = entry;
  73. }
  74. }
  75. #endif
  76. #ifdef CONFIG_ROUTE_IPv6_RAMROUTE
  77. void ramroute_ipv6_addlast(FAR struct net_route_ipv6_entry_s *entry,
  78. FAR struct net_route_ipv6_queue_s *list)
  79. {
  80. entry->flink = NULL;
  81. if (!list->head)
  82. {
  83. list->head = entry;
  84. list->tail = entry;
  85. }
  86. else
  87. {
  88. list->tail->flink = entry;
  89. list->tail = entry;
  90. }
  91. }
  92. #endif
  93. /****************************************************************************
  94. * Name: ramroute_ipv4_remfirst/ramroute_ipv6_remfirst
  95. *
  96. * Description:
  97. * Add an entry to the end of an IPv4/IPv6 routing table list
  98. *
  99. * Input Parameters:
  100. * entry - A pointer to the new entry to add to the list
  101. * list - The list to be used.
  102. *
  103. * Returned Value:
  104. * A pointer to the entry removed from the head of the list or NULL if the
  105. * list was empty.
  106. *
  107. ****************************************************************************/
  108. #ifdef CONFIG_ROUTE_IPv4_RAMROUTE
  109. FAR struct net_route_ipv4_entry_s *
  110. ramroute_ipv4_remfirst(struct net_route_ipv4_queue_s *list)
  111. {
  112. FAR struct net_route_ipv4_entry_s *ret = list->head;
  113. if (ret)
  114. {
  115. list->head = ret->flink;
  116. if (!list->head)
  117. {
  118. list->tail = NULL;
  119. }
  120. ret->flink = NULL;
  121. }
  122. return ret;
  123. }
  124. #endif
  125. #ifdef CONFIG_ROUTE_IPv6_RAMROUTE
  126. FAR struct net_route_ipv6_entry_s *
  127. ramroute_ipv6_remfirst(struct net_route_ipv6_queue_s *list)
  128. {
  129. FAR struct net_route_ipv6_entry_s *ret = list->head;
  130. if (ret)
  131. {
  132. list->head = ret->flink;
  133. if (!list->head)
  134. {
  135. list->tail = NULL;
  136. }
  137. ret->flink = NULL;
  138. }
  139. return ret;
  140. }
  141. #endif
  142. /****************************************************************************
  143. * Name: ramroute_ipv4_remafter/ramroute_ipv6_remafter
  144. *
  145. * Description:
  146. * Remove the entry in the IPv4/IPv6 routing table list after the specified
  147. * entry.
  148. *
  149. * Input Parameters:
  150. * entry - A pointer to the new entry to add to the list
  151. * list - The list to be used.
  152. *
  153. * Returned Value:
  154. * A pointer to the entry removed from the head of the list or NULL if the
  155. * list was empty.
  156. *
  157. ****************************************************************************/
  158. #ifdef CONFIG_ROUTE_IPv4_RAMROUTE
  159. FAR struct net_route_ipv4_entry_s *
  160. ramroute_ipv4_remafter(FAR struct net_route_ipv4_entry_s *entry,
  161. FAR struct net_route_ipv4_queue_s *list)
  162. {
  163. FAR struct net_route_ipv4_entry_s *ret = entry->flink;
  164. if (list->head && ret)
  165. {
  166. if (list->tail == ret)
  167. {
  168. list->tail = entry;
  169. entry->flink = NULL;
  170. }
  171. else
  172. {
  173. entry->flink = ret->flink;
  174. }
  175. ret->flink = NULL;
  176. }
  177. return ret;
  178. }
  179. #endif
  180. #ifdef CONFIG_ROUTE_IPv6_RAMROUTE
  181. FAR struct net_route_ipv6_entry_s *
  182. ramroute_ipv6_remafter(FAR struct net_route_ipv6_entry_s *entry,
  183. struct net_route_ipv6_queue_s *list)
  184. {
  185. FAR struct net_route_ipv6_entry_s *ret = entry->flink;
  186. if (list->head && ret)
  187. {
  188. if (list->tail == ret)
  189. {
  190. list->tail = entry;
  191. entry->flink = NULL;
  192. }
  193. else
  194. {
  195. entry->flink = ret->flink;
  196. }
  197. ret->flink = NULL;
  198. }
  199. return ret;
  200. }
  201. #endif
  202. #endif /* CONFIG_ROUTE_IPv4_RAMROUTE || CONFIG_ROUTE_IPv4_RAMROUTE */