ipfwd_dropstats.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. /****************************************************************************
  2. * net/ipforward/ipfwd_dropstats.c
  3. *
  4. * Licensed to the Apache Software Foundation (ASF) under one or more
  5. * contributor license agreements. See the NOTICE file distributed with
  6. * this work for additional information regarding copyright ownership. The
  7. * ASF licenses this file to you under the Apache License, Version 2.0 (the
  8. * "License"); you may not use this file except in compliance with the
  9. * License. You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  15. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  16. * License for the specific language governing permissions and limitations
  17. * under the License.
  18. *
  19. ****************************************************************************/
  20. /****************************************************************************
  21. * Included Files
  22. ****************************************************************************/
  23. #include <nuttx/config.h>
  24. #include <errno.h>
  25. #include <nuttx/mm/iob.h>
  26. #include <nuttx/net/ip.h>
  27. #include <nuttx/net/netstats.h>
  28. #include "ipforward/ipforward.h"
  29. #if defined(CONFIG_NET_IPFORWARD) && defined(CONFIG_NET_STATISTICS)
  30. /****************************************************************************
  31. * Private Functions
  32. ****************************************************************************/
  33. /****************************************************************************
  34. * Name: proto_dropstats
  35. *
  36. * Description:
  37. * Update statistics for a dropped L2 protocol packet.
  38. *
  39. * Input Parameters:
  40. * proto - The protocol from the IPv4 or IPv6 header.
  41. *
  42. * Returned Value:
  43. * On success, zero (OK) is returned. Otherwise, a negated errno value
  44. * is returned. The only error is if the protocol is not recognized.
  45. *
  46. ****************************************************************************/
  47. static int proto_dropstats(int proto)
  48. {
  49. switch (proto)
  50. {
  51. #ifdef CONFIG_NET_TCP
  52. case IP_PROTO_TCP:
  53. g_netstats.tcp.drop++;
  54. break;
  55. #endif
  56. #ifdef CONFIG_NET_UDP
  57. case IP_PROTO_UDP:
  58. g_netstats.udp.drop++;
  59. break;
  60. #endif
  61. #ifdef CONFIG_NET_ICMPv6
  62. case IP_PROTO_ICMP6:
  63. g_netstats.icmpv6.drop++;
  64. break;
  65. #endif
  66. default:
  67. return -EPROTONOSUPPORT;
  68. }
  69. return OK;
  70. }
  71. /****************************************************************************
  72. * Public Functions
  73. ****************************************************************************/
  74. /****************************************************************************
  75. * Name: ipv6_dropstats
  76. *
  77. * Description:
  78. * Update statistics for a dropped Ipv6 packet.
  79. *
  80. * Input Parameters:
  81. * ipv6 - A pointer to the IPv6 header in within the IPv6 packet to be
  82. * dropped.
  83. *
  84. * Returned Value:
  85. * None
  86. *
  87. ****************************************************************************/
  88. #ifdef CONFIG_NET_IPv6
  89. void ipv6_dropstats(FAR struct ipv6_hdr_s *ipv6)
  90. {
  91. int ret;
  92. ret = proto_dropstats(ipv6->proto);
  93. if (ret < 0)
  94. {
  95. g_netstats.ipv6.protoerr++;
  96. }
  97. g_netstats.ipv6.drop++;
  98. }
  99. #endif
  100. /****************************************************************************
  101. * Name: ipv4_dropstats
  102. *
  103. * Description:
  104. * Update statistics for a dropped Ipv4 packet.
  105. *
  106. * Input Parameters:
  107. * ipv4 - A pointer to the IPv4 header in within the IPv4 packet to be
  108. * dropped.
  109. *
  110. * Returned Value:
  111. * None
  112. *
  113. ****************************************************************************/
  114. #ifdef CONFIG_NET_IPv4
  115. void ipv4_dropstats(FAR struct ipv4_hdr_s *ipv4)
  116. {
  117. int ret;
  118. ret = proto_dropstats(ipv4->proto);
  119. if (ret < 0)
  120. {
  121. g_netstats.ipv4.protoerr++;
  122. }
  123. g_netstats.ipv4.drop++;
  124. }
  125. #endif
  126. /****************************************************************************
  127. * Name: ipfwd_dropstats
  128. *
  129. * Description:
  130. * Update statistics for a dropped packet.
  131. *
  132. * Input Parameters:
  133. * fwd - The forwarding state structure
  134. *
  135. * Returned Value:
  136. * None
  137. *
  138. ****************************************************************************/
  139. void ipfwd_dropstats(FAR struct forward_s *fwd)
  140. {
  141. #ifdef CONFIG_NET_IPv4
  142. #ifdef CONFIG_NET_IPv6
  143. if (fwd->f_domain == PF_INET)
  144. #endif
  145. {
  146. ipv4_dropstats((FAR struct ipv4_hdr_s *)fwd->f_iob->io_data);
  147. }
  148. #endif
  149. #ifdef CONFIG_NET_IPv6
  150. #ifdef CONFIG_NET_IPv4
  151. else
  152. #endif
  153. {
  154. ipv6_dropstats((FAR struct ipv6_hdr_s *)fwd->f_iob->io_data);
  155. }
  156. #endif
  157. }
  158. #endif /* CONFIG_NET_IPFORWARD && CONFIG_NET_STATISTICS */