procfs.h 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. /****************************************************************************
  2. * net/procfs/procfs.h
  3. *
  4. * Copyright (C) 2015 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. #ifndef __NET_PROCFS_PROCFS_H
  36. #define __NET_PROCFS_PROCFS_H
  37. /****************************************************************************
  38. * Included Files
  39. ****************************************************************************/
  40. #include <nuttx/config.h>
  41. #include <sys/types.h>
  42. #include <nuttx/fs/procfs.h>
  43. #if defined(CONFIG_FS_PROCFS) && !defined(CONFIG_FS_PROCFS_EXCLUDE_NET)
  44. /****************************************************************************
  45. * Pre-processor Definitions
  46. ****************************************************************************/
  47. #ifdef CONFIG_FS_PROCFS_EXCLUDE_ROUTE
  48. # undef CONFIG_NET_ROUTE
  49. #endif
  50. /* Determines the size of an intermediate buffer that must be large enough
  51. * to handle the longest line generated by this logic.
  52. */
  53. #define NET_LINELEN 80
  54. /****************************************************************************
  55. * Public Type Definitions
  56. ****************************************************************************/
  57. /* Describes the /net directory entries */
  58. enum netprocfs_entry_e
  59. {
  60. NETPROCFS_SUBDIR_DEV = 0 /* Multiple instances, e.g. /proc/net/eth0 */
  61. #ifdef CONFIG_NET_STATISTICS
  62. , NETPROCFS_SUBDIR_STAT /* /proc/net/stat */
  63. #ifdef CONFIG_NET_MLD
  64. , NETPROCFS_SUBDIR_MLD /* /proc/net/mld */
  65. #endif
  66. #endif
  67. #ifdef CONFIG_NET_ROUTE
  68. , NETPROCFS_SUBDIR_ROUTE /* /proc/net/route */
  69. #endif
  70. };
  71. /* This structure describes one open "file" */
  72. struct net_driver_s; /* Forward reference */
  73. struct netprocfs_file_s
  74. {
  75. struct procfs_file_s base; /* Base open file structure */
  76. FAR struct net_driver_s *dev; /* Current network device */
  77. uint8_t lineno; /* Line number */
  78. uint8_t linesize; /* Number of valid characters in line[] */
  79. uint8_t offset; /* Offset to first valid character in line[] */
  80. uint8_t entry; /* See enum netprocfs_entry_e */
  81. char line[NET_LINELEN]; /* Pre-allocated buffer for formatted lines */
  82. };
  83. /* Level 1 is the directory of attributes */
  84. struct netprocfs_level1_s
  85. {
  86. struct procfs_dir_priv_s base; /* Base directory private data */
  87. char name[NAME_MAX + 1]; /* Name of last node visited */
  88. #ifdef CONFIG_NETDEV_IFINDEX
  89. uint8_t ifindex; /* Next ifindex to visit */
  90. #endif
  91. };
  92. /* Line generating function type */
  93. typedef int (*linegen_t)(FAR struct netprocfs_file_s *netfile);
  94. /****************************************************************************
  95. * Public Data
  96. ****************************************************************************/
  97. #ifdef __cplusplus
  98. # define EXTERN extern "C"
  99. extern "C"
  100. {
  101. #else
  102. # define EXTERN extern
  103. #endif
  104. /****************************************************************************
  105. * Public Function Prototypes
  106. ****************************************************************************/
  107. /****************************************************************************
  108. * Name: netprocfs_read_linegen
  109. *
  110. * Description:
  111. * Read and format procfs data using a line generation table.
  112. *
  113. * Input Parameters:
  114. * priv - A reference to the network procfs file structure
  115. * buffer - The user-provided buffer into which device status will be
  116. * returned.
  117. * buflen - The size in bytes of the user provided buffer.
  118. * gentab - Table of line generation functions
  119. * nelems - The number of elements in the table
  120. *
  121. * Returned Value:
  122. * Zero (OK) is returned on success; a negated errno value is returned
  123. * on failure.
  124. *
  125. ****************************************************************************/
  126. ssize_t netprocfs_read_linegen(FAR struct netprocfs_file_s *priv,
  127. FAR char *buffer, size_t buflen,
  128. FAR const linegen_t *gentab, int nelems);
  129. /****************************************************************************
  130. * Name: netprocfs_read_netstats
  131. *
  132. * Description:
  133. * Read and format network layer statistics.
  134. *
  135. * Input Parameters:
  136. * priv - A reference to the network procfs file structure
  137. * buffer - The user-provided buffer into which network status will be
  138. * returned.
  139. * bulen - The size in bytes of the user provided buffer.
  140. *
  141. * Returned Value:
  142. * Zero (OK) is returned on success; a negated errno value is returned
  143. * on failure.
  144. *
  145. ****************************************************************************/
  146. #ifdef CONFIG_NET_STATISTICS
  147. ssize_t netprocfs_read_netstats(FAR struct netprocfs_file_s *priv,
  148. FAR char *buffer, size_t buflen);
  149. #endif
  150. /****************************************************************************
  151. * Name: netprocfs_read_mldstats
  152. *
  153. * Description:
  154. * Read and format MLD statistics.
  155. *
  156. * Input Parameters:
  157. * priv - A reference to the network procfs file structure
  158. * buffer - The user-provided buffer into which network status will be
  159. * returned.
  160. * bulen - The size in bytes of the user provided buffer.
  161. *
  162. * Returned Value:
  163. * Zero (OK) is returned on success; a negated errno value is returned
  164. * on failure.
  165. *
  166. ****************************************************************************/
  167. #if defined(CONFIG_NET_STATISTICS) && defined(CONFIG_NET_MLD)
  168. ssize_t netprocfs_read_mldstats(FAR struct netprocfs_file_s *priv,
  169. FAR char *buffer, size_t buflen);
  170. #endif
  171. /****************************************************************************
  172. * Name: netprocfs_read_routes
  173. *
  174. * Description:
  175. * Read and format routing table entries.
  176. *
  177. * Input Parameters:
  178. * priv - A reference to the network procfs file structure
  179. * buffer - The user-provided buffer into which network status will be
  180. * returned.
  181. * bulen - The size in bytes of the user provided buffer.
  182. *
  183. * Returned Value:
  184. * Zero (OK) is returned on success; a negated errno value is returned
  185. * on failure.
  186. *
  187. ****************************************************************************/
  188. #ifdef CONFIG_NET_ROUTE
  189. ssize_t netprocfs_read_routes(FAR struct netprocfs_file_s *priv,
  190. FAR char *buffer, size_t buflen);
  191. #endif
  192. /****************************************************************************
  193. * Name: netprocfs_read_devstats
  194. *
  195. * Description:
  196. * Read and format network device statistics.
  197. *
  198. * Input Parameters:
  199. * priv - A reference to the network procfs file structure
  200. * buffer - The user-provided buffer into which device status will be
  201. * returned.
  202. * bulen - The size in bytes of the user provided buffer.
  203. *
  204. * Returned Value:
  205. * Zero (OK) is returned on success; a negated errno value is returned
  206. * on failure.
  207. *
  208. ****************************************************************************/
  209. ssize_t netprocfs_read_devstats(FAR struct netprocfs_file_s *priv,
  210. FAR char *buffer, size_t buflen);
  211. #undef EXTERN
  212. #ifdef __cplusplus
  213. }
  214. #endif
  215. #endif /* CONFIG_FS_PROCFS && !CONFIG_FS_PROCFS_EXCLUDE_NET */
  216. #endif /* __NET_PROCFS_PROCFS_H */