interfaces.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. // interfaces.h :
  2. //
  3. /////////////////////////////////////////////////////////////////////////////
  4. //
  5. // https://manpages.debian.org/stretch/ifupdown/interfaces.5.en.html
  6. // https://wiki.debian.org/NetworkConfiguration
  7. // https://wiki.ubuntuusers.de/interfaces/
  8. //
  9. /////////////////////////////////////////////////////////////////////////////
  10. #if !defined(AGD_INTERFACES_H__0F16A7C6_9054_4BBB_8A10_EAE00ED4EE9C__INCLUDED_)
  11. #define AGD_INTERFACES_H__0F16A7C6_9054_4BBB_8A10_EAE00ED4EE9C__INCLUDED_
  12. #include <string.h>
  13. #include <sys/types.h>
  14. #include <sys/socket.h>
  15. #include <netinet/in.h>
  16. #include <arpa/inet.h>
  17. #include <linux/if_packet.h>
  18. #include <linux/if_arp.h>
  19. #include <vector>
  20. #include <list>
  21. #include <string>
  22. #include "inet4s.h"
  23. #include "inet4d.h"
  24. #include "inet4m.h"
  25. /////////////////////////////////////////////////////////////////////////////
  26. // interfaces.h - Declarations:
  27. typedef struct _ITF_CONFIG_GROUP
  28. {
  29. _ITF_CONFIG_GROUP(){_reset();}
  30. void _reset(void)
  31. {
  32. cfgName.clear();
  33. members.clear();
  34. }
  35. std::string cfgName;
  36. std::vector<std::string> members;
  37. }ITF_CONFIG_GROUP, *LPITF_CONFIG_GROUP;
  38. typedef const ITF_CONFIG_GROUP *LPCITF_CONFIG_GROUP;
  39. typedef std::list<ITF_CONFIG_GROUP> ITF_CONFIG_GROUP_LIST;
  40. typedef enum CfgGroup
  41. {
  42. CG_Unknown = -1,
  43. CG_Auto,
  44. CG_AllowAuto,
  45. CG_AllowHotplug,
  46. CG_NoAutoDown,
  47. DG_NoScripts,
  48. CG_User
  49. }CfgGroup;
  50. CfgGroup ParseCfgGroup(const std::vector<std::string> &v, ITF_CONFIG_GROUP &icg);
  51. /////////////////////////////////////////////////////////////////////////////
  52. typedef enum IfaceProtos
  53. {
  54. IFP_Unknown = -1,
  55. IFP_Inet,
  56. IFP_Inet6,
  57. IFP_Ipx,
  58. IFP_Can
  59. }IfaceProtos;
  60. IfaceProtos GetIfaceProto(const std::string &s);
  61. const char *GetIfaceProtoStr(IfaceProtos ip);
  62. /////////////////////////////////////////////////////////////////////////////
  63. typedef enum IfaceMethods
  64. {
  65. IFM_Unknown = -1,
  66. IFM_Static,
  67. IFM_Dhcp,
  68. IFM_Manual,
  69. IFM_BootP,
  70. IFM_Tunnel,
  71. IFM_Ppp,
  72. IFM_WvDial,
  73. IFM_IpV4ll,
  74. IFM_Loopback,
  75. IFM_Auto
  76. }IfaceMethods;
  77. IfaceMethods GetIfaceMethod(const std::string &s);
  78. const char *GetIfaceMethodStr(IfaceMethods im);
  79. /////////////////////////////////////////////////////////////////////////////
  80. typedef enum IfaceCommands
  81. {
  82. IFC_Unknown = -1,
  83. IFC_PreUp,
  84. IFC_Up,
  85. IFC_PostUp,
  86. IFC_Down,
  87. IFC_PreDown,
  88. IFC_PostDown
  89. }IfaceCommands;
  90. typedef struct _IFACE_COMMAND
  91. {
  92. IfaceCommands cmd;
  93. std::string args;
  94. }IFACE_COMMAND, *LPIFACE_COMMAND;
  95. typedef const IFACE_COMMAND *LPCIFACE_COMMAND;
  96. IfaceCommands GetIfaceCommand(const std::string &s);
  97. const char *GetIfaceCommandsStr(IfaceCommands ic);
  98. bool ParseIfaceCmd(const std::vector<std::string> &v, std::vector<IFACE_COMMAND> &c);
  99. /////////////////////////////////////////////////////////////////////////////
  100. typedef enum ItfInclude
  101. {
  102. II_None = -1,
  103. II_File,
  104. II_Directory
  105. }ItfInclude;
  106. typedef struct _ITF_INCLUDE
  107. {
  108. ItfInclude inc;
  109. std::string path;
  110. }ITF_INCLUDE, *LPITF_INCLUDE;
  111. typedef const ITF_INCLUDE *LPCITF_INCLUDE;
  112. typedef std::list<ITF_INCLUDE> ITF_INCLUDE_LIST;
  113. bool ParseIncludes(const std::vector<std::string> &v, ITF_INCLUDE_LIST &inc);
  114. const char *GetIncTypeStr(ItfInclude inc);
  115. /////////////////////////////////////////////////////////////////////////////
  116. typedef struct _ITF_IFACE_BLOCK
  117. {
  118. _ITF_IFACE_BLOCK(){_reset();}
  119. void _reset(void)
  120. {
  121. cfgName.clear();
  122. proto = IFP_Unknown;
  123. method = IFM_Unknown;
  124. inheritedFrom.clear();
  125. desc.clear();
  126. cmds.clear();
  127. memberOf.clear();
  128. unparsed.clear();
  129. inet4s._reset();
  130. inet4d._reset();
  131. inet4m._reset();
  132. }
  133. std::string cfgName;
  134. IfaceProtos proto;
  135. IfaceMethods method;
  136. std::string inheritedFrom;
  137. std::string desc;
  138. std::vector<IFACE_COMMAND> cmds;
  139. std::vector<LPITF_CONFIG_GROUP> memberOf;
  140. std::vector<std::string> unparsed;
  141. IFACE_INET_STATIC inet4s;
  142. IFACE_INET_DHCP inet4d;
  143. IFACE_INET_MANUAL inet4m;
  144. }ITF_IFACE_BLOCK, *LPITF_IFACE_BLOCK;
  145. typedef const ITF_IFACE_BLOCK *LPCITF_IFACE_BLOCK;
  146. //typedef std::vector<ITF_IFACE_BLOCK> ITF_IFACE_BLOCK_LIST;
  147. typedef std::list<ITF_IFACE_BLOCK> ITF_IFACE_BLOCK_LIST;
  148. typedef enum IfaceHdrType
  149. {
  150. IHR_NoHdr,
  151. IHR_Invalid,
  152. IHR_Unknown,
  153. IHR_OK
  154. }IfaceHdrType;
  155. IfaceHdrType ParseIfaceHeader(const std::vector<std::string> &v, ITF_IFACE_BLOCK &ib);
  156. bool ParseIfaceParam(const std::vector<std::string> &v, ITF_IFACE_BLOCK &ib);
  157. bool ParseIfaceDesc(const std::vector<std::string> &v, ITF_IFACE_BLOCK &ib);
  158. /////////////////////////////////////////////////////////////////////////////
  159. typedef struct _ITF_MAPPING_BLOCK
  160. {
  161. _ITF_MAPPING_BLOCK(){_reset();}
  162. void _reset(void)
  163. {
  164. unparsed.clear();
  165. }
  166. std::vector<std::string> unparsed;
  167. }ITF_MAPPING_BLOCK, *LPITF_MAPPING_BLOCK;
  168. typedef const ITF_MAPPING_BLOCK *LPCITF_MAPPING_BLOCK;
  169. typedef std::list<ITF_MAPPING_BLOCK> ITF_MAPPING_BLOCK_LIST;
  170. bool ParseMapping(const std::vector<std::string> &v, ITF_MAPPING_BLOCK &mab);
  171. /////////////////////////////////////////////////////////////////////////////
  172. typedef struct _ETC_NETWORK_INTERFACES
  173. {
  174. _ETC_NETWORK_INTERFACES(void){_reset();}
  175. void _reset(void)
  176. {
  177. mbl.clear();
  178. cgl.clear();
  179. ibl.clear();
  180. inc.clear();
  181. unparsed.clear();
  182. }
  183. ITF_MAPPING_BLOCK_LIST mbl;
  184. ITF_CONFIG_GROUP_LIST cgl;
  185. ITF_IFACE_BLOCK_LIST ibl;
  186. ITF_INCLUDE_LIST inc;
  187. std::vector<std::string> unparsed;
  188. }ETC_NETWORK_INTERFACES, *LPETC_NETWORK_INTERFACES;
  189. typedef const ETC_NETWORK_INTERFACES *LPCETC_NETWORK_INTERFACES;
  190. void ProcessIface(ETC_NETWORK_INTERFACES &eni);
  191. void ProcessGroupMembers(ETC_NETWORK_INTERFACES &eni);
  192. bool ParseEtcNetworkInterfaces(ETC_NETWORK_INTERFACES &eni, const char *pszPath = NULL);
  193. bool WriteEtcNetworkInterfaces(const ETC_NETWORK_INTERFACES &eni, const char *pszPath = NULL);
  194. /////////////////////////////////////////////////////////////////////////////
  195. #endif // !defined(AGD_INTERFACES_H__0F16A7C6_9054_4BBB_8A10_EAE00ED4EE9C__INCLUDED_)