PrintRule.c.html 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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. PrintRule.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='plcwait.c.html' title=' plcwait.c '>PREV</a>]
  17. [<a href='toolkit.html' title=' Index '>HOME</a>]
  18. [<a href='pseudo.c.html' title=' pseudo.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. * signed PrintRule (uint32_t CR_PID, uint32_t CR_OPERAND, uint8_t CR_VALUE []);
  64. *
  65. * rules.h
  66. *
  67. * print one classifier rule on stdout;
  68. *
  69. * some classifier rule structures have an 8-bit PID and OPERAND
  70. * while others have a 32-bit PID and OPERAND; this function is
  71. * the common demominator;
  72. *
  73. * Contributor(s):
  74. * Nathaniel Houghton &lt;nhoughto@qca.qualcomm.com&gt;
  75. * Charles Maier &lt;cmaier@qca.qualcomm.com&gt;
  76. *
  77. *--------------------------------------------------------------------*/
  78. #ifndef PRINTRULE_SOURCE
  79. #define PRINTRULE_SOURCE
  80. #include &lt;string.h&gt;
  81. #include &quot;../plc/rules.h&quot;
  82. #include &quot;../tools/error.h&quot;
  83. signed PrintRule (uint32_t CR_PID, uint32_t CR_OPERAND, uint8_t CR_VALUE [])
  84. {
  85. char buffer [CLASSIFIER_STRING];
  86. uint32_t val32;
  87. uint16_t val16;
  88. uint8_t val8;
  89. const char * p1;
  90. const char * p2;
  91. p1 = reword (CR_PID, fields, SIZEOF (fields));
  92. if (p1 == NULL)
  93. {
  94. error (1, 0, &quot;invalid classifier PID&quot;);
  95. }
  96. p2 = reword (CR_OPERAND, operators, SIZEOF (operators));
  97. if (p2 == NULL)
  98. {
  99. error (1, 0, &quot;invalid classifier operand&quot;);
  100. }
  101. printf (&quot;%s %s&quot;, p1, p2);
  102. switch (CR_PID)
  103. {
  104. case FIELD_ETH_SA:
  105. case FIELD_ETH_DA:
  106. printf (&quot; %s&quot;, hexstring (buffer, sizeof (buffer), CR_VALUE, ETHER_ADDR_LEN));
  107. break;
  108. case FIELD_IPV4_SA:
  109. case FIELD_IPV4_DA:
  110. putchar (' ');
  111. memout (CR_VALUE, IPv4_LEN, &quot;%d&quot;, 1, '.', 0, stdout);
  112. break;
  113. case FIELD_IPV6_SA:
  114. case FIELD_IPV6_DA:
  115. putchar (' ');
  116. memout (CR_VALUE, IPv6_LEN, &quot;%02x&quot;, 2, ':', 0, stdout);
  117. break;
  118. case FIELD_VLAN_UP:
  119. case FIELD_IPV6_TC:
  120. case FIELD_IPV4_TOS:
  121. case FIELD_IPV4_PROT:
  122. memcpy (&amp; val8, CR_VALUE, sizeof (val8));
  123. printf (&quot; 0x%02X&quot;, val8);
  124. break;
  125. case FIELD_VLAN_ID:
  126. case FIELD_TCP_SP:
  127. case FIELD_TCP_DP:
  128. case FIELD_UDP_SP:
  129. case FIELD_UDP_DP:
  130. case FIELD_IP_SP:
  131. case FIELD_IP_DP:
  132. memcpy (&amp; val16, CR_VALUE, sizeof (val16));
  133. val16 = ntohs (val16);
  134. printf (&quot; %d&quot;, val16);
  135. break;
  136. case FIELD_ETH_TYPE:
  137. memcpy (&amp; val16, CR_VALUE, sizeof (val16));
  138. val16 = ntohs (val16);
  139. printf (&quot; 0x%04X&quot;, val16);
  140. break;
  141. case FIELD_IPV6_FL:
  142. memcpy (&amp; val32, &amp; CR_VALUE [0], sizeof (val32));
  143. val32 = ntohl (val32);
  144. printf (&quot; 0x%08X&quot;, val32);
  145. break;
  146. case FIELD_HPAV_MME:
  147. memcpy (&amp; val8, &amp; CR_VALUE [0], sizeof (val8));
  148. memcpy (&amp; val16, &amp; CR_VALUE [1], sizeof (val16));
  149. printf (&quot; %02x:%04x&quot;, val8, val16);
  150. break;
  151. case FIELD_TCP_ACK:
  152. {
  153. code_t val;
  154. const char * p;
  155. memcpy (&amp; val, CR_VALUE, sizeof (val));
  156. p = reword (val, states, SIZEOF (states));
  157. if (p == NULL)
  158. {
  159. error (1, 0, &quot;invalid TCP ACK flag&quot;);
  160. }
  161. printf (&quot; %s&quot;, p);
  162. }
  163. break;
  164. case FIELD_VLAN_TAG:
  165. {
  166. code_t val;
  167. const char * p;
  168. memcpy (&amp; val, CR_VALUE, sizeof (val));
  169. p = reword (val, states, SIZEOF (states));
  170. if (p == NULL)
  171. {
  172. error (1, 0, &quot;invalid VLAN tag flag&quot;);
  173. }
  174. printf (&quot; %s&quot;, p);
  175. }
  176. break;
  177. default:
  178. printf (&quot; *****UNSUPPORTED CODE*****&quot;);
  179. break;
  180. }
  181. return (0);
  182. }
  183. #endif
  184. </pre>
  185. <div class='footerlink'>
  186. [<a href='plcwait.c.html' title=' plcwait.c '>PREV</a>]
  187. [<a href='toolkit.html' title=' Index '>HOME</a>]
  188. [<a href='pseudo.c.html' title=' pseudo.c '>NEXT</a>]
  189. </div>
  190. </body>
  191. </html>