pibrump.c.html 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  1. <?xml version='1.0' encoding='iso-8859-1'?>
  2. <!doctype html public '-//W3C//DTD XHTML 1.0 Strict//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>
  3. <html xmlns='http://www.w3c.org/1999/xhtml' lang='en-us'>
  4. <head>
  5. <title>
  6. pibrump.c
  7. </title>
  8. <meta http-equiv='content-type' content='text/html;iso-8859-1'/>
  9. <meta name='generator' content='motley-tools 1.9.4 13:40:33 Feb 18 2015'/>
  10. <meta name='author' content='cmaier@cmassoc.net'/>
  11. <meta name='robots' content='noindex,nofollow'/>
  12. <link href='toolkit.css' rel='stylesheet' type='text/css'/>
  13. </head>
  14. <body>
  15. <div class='headerlink'>
  16. [<a href='pibruin.c.html' title=' pibruin.c '>PREV</a>]
  17. [<a href='toolkit.html' title=' Index '>HOME</a>]
  18. [<a href='pibscalers.c.html' title=' pibscalers.c '>NEXT</a>]
  19. </div>
  20. <pre>
  21. /*====================================================================*
  22. *
  23. * Copyright (c) 2013 Qualcomm Atheros, Inc.
  24. *
  25. * All rights reserved.
  26. *
  27. * Redistribution and use in source and binary forms, with or
  28. * without modification, are permitted (subject to the limitations
  29. * in the disclaimer below) provided that the following conditions
  30. * are met:
  31. *
  32. * * Redistributions of source code must retain the above copyright
  33. * notice, this list of conditions and the following disclaimer.
  34. *
  35. * * Redistributions in binary form must reproduce the above
  36. * copyright notice, this list of conditions and the following
  37. * disclaimer in the documentation and/or other materials
  38. * provided with the distribution.
  39. *
  40. * * Neither the name of Qualcomm Atheros nor the names of
  41. * its contributors may be used to endorse or promote products
  42. * derived from this software without specific prior written
  43. * permission.
  44. *
  45. * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
  46. * GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE
  47. * COPYRIGHT HOLDERS AND CONTRIBUTORS &quot;AS IS&quot; AND ANY EXPRESS OR
  48. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  49. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  50. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
  51. * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  52. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  53. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  54. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  55. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  56. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  57. * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  58. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  59. *
  60. *--------------------------------------------------------------------*/
  61. /*====================================================================*
  62. *
  63. * pibrump.c - Atheros Classification Rule Dump Utility;
  64. *
  65. * This program read classification rules stored in a PIB file and
  66. * prints them on stdout in a format similar to int6krule commands;
  67. *
  68. *
  69. * Contributor(s):
  70. * Nathaniel Houghton &lt;nhoughto@qca.qualcomm.com&gt;
  71. *
  72. *--------------------------------------------------------------------*/
  73. /*====================================================================*&quot;
  74. * system header files;
  75. *--------------------------------------------------------------------*/
  76. #include &lt;unistd.h&gt;
  77. #include &lt;stdlib.h&gt;
  78. #include &lt;stdint.h&gt;
  79. #include &lt;string.h&gt;
  80. #include &lt;netinet/in.h&gt;
  81. #include &lt;arpa/inet.h&gt;
  82. /*====================================================================*
  83. * custom header files;
  84. *--------------------------------------------------------------------*/
  85. #include &quot;../tools/getoptv.h&quot;
  86. #include &quot;../tools/memory.h&quot;
  87. #include &quot;../tools/symbol.h&quot;
  88. #include &quot;../tools/types.h&quot;
  89. #include &quot;../tools/flags.h&quot;
  90. #include &quot;../tools/files.h&quot;
  91. #include &quot;../tools/error.h&quot;
  92. #include &quot;../pib/pib.h&quot;
  93. #include &quot;../plc/rules.h&quot;
  94. /*====================================================================*
  95. * custom source files;
  96. *--------------------------------------------------------------------*/
  97. #ifndef MAKEFILE
  98. #include &quot;../tools/getoptv.c&quot;
  99. #include &quot;../tools/putoptv.c&quot;
  100. #include &quot;../tools/version.c&quot;
  101. #include &quot;../tools/lookup.c&quot;
  102. #include &quot;../tools/reword.c&quot;
  103. #include &quot;../tools/hexstring.c&quot;
  104. #include &quot;../tools/hexdecode.c&quot;
  105. #include &quot;../tools/fdchecksum32.c&quot;
  106. #include &quot;../tools/memout.c&quot;
  107. #include &quot;../tools/error.c&quot;
  108. #endif
  109. #ifndef MAKEFILE
  110. #include &quot;../pib/pibfile1.c&quot;
  111. #endif
  112. #ifndef MAKEFILE
  113. #include &quot;../plc/rules.c&quot;
  114. #endif
  115. /*====================================================================*
  116. * program constants;
  117. *--------------------------------------------------------------------*/
  118. #define PIB_MAX_AUTOCONN 16
  119. #define PIB_MAX_PRIORITY_MAPS 8
  120. #define PIB_AUTOCONN_COUNT_OFFSET 0x22C
  121. #define PIB_PRIORITY_COUNT_OFFSET 0x228
  122. #define PIB_AUTOCONN_OFFSET 0x310
  123. #define PIB_PRIORITY_MAPS_OFFSET 0x230
  124. /*====================================================================*
  125. *
  126. * signed Classifier (struct PIBClassifier * classifier);
  127. *
  128. * plc.h
  129. *
  130. * This function for program pibrump displays a single classifier;
  131. *
  132. * Contributor(s):
  133. * Nathaniel Houghton &lt;nhoughto@qca.qualcomm.com&gt;
  134. *
  135. *--------------------------------------------------------------------*/
  136. signed Classifier (struct PIBClassifier * classifier)
  137. {
  138. char buffer [sizeof (classifier-&gt;CR_VALUE) * 3 + 1];
  139. uint32_t val32;
  140. uint16_t val16;
  141. uint8_t val8;
  142. printf (&quot;%s %s&quot;, reword (classifier-&gt;CR_PID, fields, SIZEOF (fields)), reword (classifier-&gt;CR_OPERAND, operators, SIZEOF (operators)));
  143. switch (classifier-&gt;CR_PID)
  144. {
  145. case FIELD_ETH_SA:
  146. case FIELD_ETH_DA:
  147. printf (&quot; %s&quot;, hexstring (buffer, sizeof (buffer), classifier-&gt;CR_VALUE, ETHER_ADDR_LEN));
  148. break;
  149. case FIELD_IPV4_SA:
  150. case FIELD_IPV4_DA:
  151. putchar (' ');
  152. memout (classifier-&gt;CR_VALUE, IPv4_LEN, &quot;%d&quot;, 1, '.', 0, stdout);
  153. break;
  154. case FIELD_IPV6_SA:
  155. case FIELD_IPV6_DA:
  156. putchar (' ');
  157. memout (classifier-&gt;CR_VALUE, IPv6_LEN, &quot;%02x&quot;, 2, ':', 0, stdout);
  158. break;
  159. case FIELD_VLAN_UP:
  160. case FIELD_IPV6_TC:
  161. case FIELD_IPV4_TOS:
  162. case FIELD_IPV4_PROT:
  163. memcpy (&amp;val8, classifier-&gt;CR_VALUE, sizeof (val8));
  164. printf (&quot; 0x%02X&quot;, val8);
  165. break;
  166. case FIELD_VLAN_ID:
  167. case FIELD_TCP_SP:
  168. case FIELD_TCP_DP:
  169. case FIELD_UDP_SP:
  170. case FIELD_UDP_DP:
  171. case FIELD_IP_SP:
  172. case FIELD_IP_DP:
  173. memcpy (&amp;val16, classifier-&gt;CR_VALUE, sizeof (val16));
  174. val16 = ntohs (val16);
  175. printf (&quot; %d&quot;, val16);
  176. break;
  177. case FIELD_ETH_TYPE:
  178. memcpy (&amp;val16, classifier-&gt;CR_VALUE, sizeof (val16));
  179. printf (&quot; 0x%04X&quot;, val16);
  180. break;
  181. case FIELD_IPV6_FL:
  182. memcpy (&amp;val32, &amp;classifier-&gt;CR_VALUE [0], sizeof (val32));
  183. val32 = ntohl (val32);
  184. printf (&quot; 0x%08X&quot;, val32);
  185. break;
  186. case FIELD_HPAV_MME:
  187. memcpy (&amp;val8, &amp;classifier-&gt;CR_VALUE [0], sizeof (val8));
  188. memcpy (&amp;val16, &amp;classifier-&gt;CR_VALUE [1], sizeof (val16));
  189. printf (&quot; %02x:%04x&quot;, val8, val16);
  190. break;
  191. case FIELD_TCP_ACK:
  192. {
  193. code_t val;
  194. memcpy (&amp;val, classifier-&gt;CR_VALUE, sizeof (val));
  195. printf (&quot; %s&quot;, reword (val, states, SIZEOF (states)));
  196. }
  197. break;
  198. case FIELD_VLAN_TAG:
  199. {
  200. code_t val;
  201. memcpy (&amp;val, classifier-&gt;CR_VALUE, sizeof (val));
  202. printf (&quot; %s&quot;, reword (val, states, SIZEOF (states)));
  203. }
  204. break;
  205. default:
  206. printf (&quot; *****UNSUPPORTED CODE*****&quot;);
  207. break;
  208. }
  209. return (0);
  210. }
  211. /*====================================================================*
  212. *
  213. * signed AutoConnection (struct auto_connection * auto_connection, flag_t flags)
  214. *
  215. * plc.h
  216. *
  217. * This function for program pibrump displays a single AutoConnection
  218. * structure;
  219. *
  220. * Contributor(s):
  221. * Nathaniel Houghton &lt;nhoughto@qca.qualcomm.com&gt;
  222. *
  223. *--------------------------------------------------------------------*/
  224. signed AutoConnection (struct auto_connection * auto_connection)
  225. {
  226. int i;
  227. if (auto_connection-&gt;MACTION == ACTION_TAGTX)
  228. {
  229. printf (&quot;-T 0x%08X -V %d &quot;, ntohl (auto_connection-&gt;cspec.VLAN_TAG), LE16TOH (auto_connection-&gt;cspec.CSPEC_VERSION));
  230. }
  231. printf (&quot;%s&quot;, reword (auto_connection-&gt;MACTION, actions, SIZEOF (actions)));
  232. printf (&quot; %s &quot;, reword (auto_connection-&gt;MOPERAND, operands, SIZEOF (operands)));
  233. for (i = 0; i &lt; LE16TOH (auto_connection-&gt;NUM_CLASSIFIERS); ++i)
  234. {
  235. Classifier (&amp;auto_connection-&gt;CLASSIFIER [i]);
  236. putchar (' ');
  237. }
  238. printf (&quot;add perm\n&quot;);
  239. return (0);
  240. }
  241. /*====================================================================*
  242. *
  243. * signed ClassifierPriorityMap (struct classifier_priority_map * map)
  244. *
  245. * plc.h
  246. *
  247. * This function for program pibrump displays a single
  248. * ClassifierPriorityMap structure;
  249. *
  250. * Contributor(s):
  251. * Nathaniel Houghton &lt;nhoughto@qca.qualcomm.com&gt;
  252. *
  253. *--------------------------------------------------------------------*/
  254. signed ClassifierPriorityMap (struct classifier_priority_map * map)
  255. {
  256. printf (&quot;%s Any &quot;, reword (LE32TOH (map-&gt;Priority), actions, SIZEOF (actions)));
  257. Classifier (&amp;map-&gt;CLASSIFIER);
  258. printf (&quot; add perm\n&quot;);
  259. return (0);
  260. }
  261. /*====================================================================*
  262. *
  263. * int main (int argc, char const * argv[]);
  264. *
  265. *--------------------------------------------------------------------*/
  266. int main (int argc, char const * argv [])
  267. {
  268. static char const * optv [] =
  269. {
  270. &quot;eqv&quot;,
  271. &quot;pibfile&quot;,
  272. &quot;Atheros Classification Rule Dump Utility&quot;,
  273. &quot;e\tredirect stderr messages to stdout&quot;,
  274. &quot;q\tquiet mode&quot;,
  275. &quot;v\tverbose mode&quot;,
  276. (char const *) (0)
  277. };
  278. struct auto_connection auto_connection [PIB_MAX_AUTOCONN];
  279. struct classifier_priority_map classifier_priority_map [PIB_MAX_PRIORITY_MAPS];
  280. uint32_t AutoConnection_count;
  281. uint32_t PriorityMaps_count;
  282. unsigned i;
  283. flag_t flags = (flag_t)(0);
  284. struct _file_ pib;
  285. signed c;
  286. optind = 1;
  287. while ((c = getoptv (argc, argv, optv)) != -1)
  288. {
  289. switch ((char) (c))
  290. {
  291. case 'e':
  292. dup2 (STDOUT_FILENO, STDERR_FILENO);
  293. break;
  294. case 'q':
  295. _setbits (flags, PIB_SILENCE);
  296. break;
  297. case 'v':
  298. _setbits (flags, PIB_VERBOSE);
  299. break;
  300. default:
  301. break;
  302. }
  303. }
  304. argc -= optind;
  305. argv += optind;
  306. while ((argc) &amp;&amp; (* argv))
  307. {
  308. pib.name = * argv;
  309. if ((pib.file = open (pib.name, O_BINARY|O_RDONLY)) == -1)
  310. {
  311. error (1, errno, &quot;%s&quot;, pib.name);
  312. }
  313. if (pibfile1 (&amp;pib))
  314. {
  315. error (1, errno, &quot;Bad PIB file: %s&quot;, pib.name);
  316. }
  317. if (lseek (pib.file, PIB_AUTOCONN_COUNT_OFFSET, SEEK_SET) != PIB_AUTOCONN_COUNT_OFFSET)
  318. {
  319. error (1, errno, &quot;could not seek to AutoConnection count&quot;);
  320. }
  321. if (read (pib.file, &amp;AutoConnection_count, sizeof (AutoConnection_count)) != sizeof (AutoConnection_count))
  322. {
  323. error (1, errno, &quot;could not read AutoConnection count&quot;);
  324. }
  325. if (lseek (pib.file, PIB_AUTOCONN_OFFSET, SEEK_SET) != PIB_AUTOCONN_OFFSET)
  326. {
  327. error (1, errno, &quot;could not seek to AutoConnections&quot;);
  328. }
  329. if (read (pib.file, &amp;auto_connection, sizeof (auto_connection)) != sizeof (auto_connection))
  330. {
  331. error (1, errno, &quot;could not read AutoConnections&quot;);
  332. }
  333. if (lseek (pib.file, PIB_PRIORITY_COUNT_OFFSET, SEEK_SET) != PIB_PRIORITY_COUNT_OFFSET)
  334. {
  335. error (1, errno, &quot;could not seek to PriorityMaps count&quot;);
  336. }
  337. if (read (pib.file, &amp;PriorityMaps_count, sizeof (PriorityMaps_count)) != sizeof (PriorityMaps_count))
  338. {
  339. error (1, errno, &quot;could not read PriorityMaps count&quot;);
  340. }
  341. if (lseek (pib.file, PIB_PRIORITY_MAPS_OFFSET, SEEK_SET) != PIB_PRIORITY_MAPS_OFFSET)
  342. {
  343. error (1, errno, &quot;could not seek to Priority Map&quot;);
  344. }
  345. if (read (pib.file, &amp;classifier_priority_map, sizeof (classifier_priority_map)) != sizeof (classifier_priority_map))
  346. {
  347. error (1, errno, &quot;could not read Priority Map&quot;);
  348. }
  349. close (pib.file);
  350. if (_allclr (flags, PIB_SILENCE))
  351. {
  352. printf (&quot;# auto connection rules:\n&quot;);
  353. }
  354. for (i = 0; i &lt; AutoConnection_count; ++i)
  355. {
  356. AutoConnection (&amp;auto_connection [i]);
  357. }
  358. if (_allclr (flags, PIB_SILENCE))
  359. {
  360. printf (&quot;# priority mapping rules:\n&quot;);
  361. }
  362. for (i = 0; i &lt; PriorityMaps_count; ++i)
  363. {
  364. ClassifierPriorityMap (&amp;classifier_priority_map [i]);
  365. }
  366. argv++;
  367. argc--;
  368. }
  369. exit (0);
  370. }
  371. </pre>
  372. <div class='footerlink'>
  373. [<a href='pibruin.c.html' title=' pibruin.c '>PREV</a>]
  374. [<a href='toolkit.html' title=' Index '>HOME</a>]
  375. [<a href='pibscalers.c.html' title=' pibscalers.c '>NEXT</a>]
  376. </div>
  377. </body>
  378. </html>