ParseRule.c.html 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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. ParseRule.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='output.c.html' title=' output.c '>PREV</a>]
  17. [<a href='toolkit.html' title=' Index '>HOME</a>]
  18. [<a href='pcapdevs.c.html' title=' pcapdevs.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 ParseRule (int * argcp, char const * argvp [], struct rule * rule, struct cspec * cspec);
  64. *
  65. * rules.h
  66. *
  67. * This module takes an argument vector and an argument count
  68. * and fills in a classification rule structure that is suitable for
  69. * sending in a VS_CLASSIFICATION MME;
  70. *
  71. * This module is currently used by plcrule and pibruin;
  72. *
  73. *
  74. * Contributor(s):
  75. * Charles Maier &lt;cmaier@qca.qualcomm.com&gt;
  76. * Nathaniel Houghton &lt;nhoughto@qca.qualcomm.com&gt;
  77. *
  78. *--------------------------------------------------------------------*/
  79. #include &lt;memory.h&gt;
  80. #include &lt;errno.h&gt;
  81. #include &quot;../tools/memory.h&quot;
  82. #include &quot;../tools/number.h&quot;
  83. #include &quot;../tools/error.h&quot;
  84. #include &quot;../ether/ether.h&quot;
  85. #include &quot;../plc/rules.h&quot;
  86. signed ParseRule (int * argcp, char const ** argvp [], struct MMERule * rule, struct cspec * cspec)
  87. {
  88. int argc = * argcp;
  89. char const ** argv = * argvp;
  90. union
  91. {
  92. uint32_t wide;
  93. uint16_t word;
  94. uint8_t byte [4];
  95. }
  96. temp;
  97. signed code;
  98. struct MMEClassifier * classifier = (struct MMEClassifier *) (&amp; rule-&gt;CLASSIFIER);
  99. if ((code = lookup (* argv++, actions, SIZEOF (actions))) == -1)
  100. {
  101. assist (* -- argv, CLASSIFIER_ACTION_NAME, actions, SIZEOF (actions));
  102. }
  103. rule-&gt;MACTION = (uint8_t) (code);
  104. argc--;
  105. if ((code = lookup (* argv++, operands, SIZEOF (operands))) == -1)
  106. {
  107. assist (* -- argv, CLASSIFIER_OPERAND_NAME, operands, SIZEOF (operands));
  108. }
  109. rule-&gt;MOPERAND = (uint8_t) (code);
  110. argc--;
  111. while ((* argv) &amp;&amp; (lookup (* argv, controls, SIZEOF (controls)) == -1))
  112. {
  113. if ((code = lookup (* argv++, fields, SIZEOF (fields))) == -1)
  114. {
  115. assist (* -- argv, CLASSIFIER_FIELD_NAME, fields, SIZEOF (fields));
  116. }
  117. classifier-&gt;CR_PID = (uint8_t) (code);
  118. argc--;
  119. if ((code = lookup (* argv++, operators, SIZEOF (operators))) == -1)
  120. {
  121. assist (* -- argv, CLASSIFIER_OPERATOR_NAME, operators, SIZEOF (operators));
  122. }
  123. classifier-&gt;CR_OPERAND = (uint8_t) (code);
  124. argc--;
  125. if (! argc || ! * argv)
  126. {
  127. error (1, ENOTSUP, &quot;I have %s '%s' but no value&quot;, CLASSIFIER_OPERATOR_NAME, * -- argv);
  128. }
  129. switch (classifier-&gt;CR_PID)
  130. {
  131. case FIELD_ETH_SA:
  132. case FIELD_ETH_DA:
  133. bytespec (* argv++, classifier-&gt;CR_VALUE, ETHER_ADDR_LEN);
  134. break;
  135. case FIELD_IPV4_SA:
  136. case FIELD_IPV4_DA:
  137. ipv4spec (* argv++, classifier-&gt;CR_VALUE);
  138. break;
  139. case FIELD_IPV6_SA:
  140. case FIELD_IPV6_DA:
  141. ipv6spec (* argv++, classifier-&gt;CR_VALUE);
  142. break;
  143. case FIELD_VLAN_UP:
  144. case FIELD_IPV6_TC:
  145. case FIELD_IPV4_TOS:
  146. case FIELD_IPV4_PROT:
  147. classifier-&gt;CR_VALUE [0] = (uint8_t) (basespec (* argv++, 0, sizeof (classifier-&gt;CR_VALUE [0])));
  148. break;
  149. case FIELD_VLAN_ID:
  150. case FIELD_TCP_SP:
  151. case FIELD_TCP_DP:
  152. case FIELD_UDP_SP:
  153. case FIELD_UDP_DP:
  154. case FIELD_IP_SP:
  155. case FIELD_IP_DP:
  156. temp.word = (uint16_t) (basespec (* argv++, 0, sizeof (temp.word)));
  157. temp.word = htons (temp.word);
  158. memcpy (classifier-&gt;CR_VALUE, &amp; temp, sizeof (temp.word));
  159. break;
  160. case FIELD_ETH_TYPE:
  161. temp.word = (uint16_t) (basespec (* argv++, 0, sizeof (temp.word)));
  162. temp.word = htons (temp.word);
  163. memcpy (classifier-&gt;CR_VALUE, &amp; temp, sizeof (temp.word));
  164. break;
  165. case FIELD_IPV6_FL:
  166. temp.wide = (uint32_t) (basespec (* argv++, 0, sizeof (temp.wide))) &amp; 0x000FFFFF;
  167. temp.wide = htonl (temp.wide);
  168. memcpy (classifier-&gt;CR_VALUE, &amp; temp.byte [1], 3);
  169. break;
  170. case FIELD_HPAV_MME:
  171. bytespec (* argv++, classifier-&gt;CR_VALUE, sizeof (uint16_t) + sizeof (uint8_t));
  172. temp.byte [0] = classifier-&gt;CR_VALUE [1];
  173. classifier-&gt;CR_VALUE [1] = classifier-&gt;CR_VALUE [2];
  174. classifier-&gt;CR_VALUE [2] = temp.byte [0];
  175. break;
  176. case FIELD_TCP_ACK:
  177. if ((code = lookup (* argv++, states, SIZEOF (states))) == -1)
  178. {
  179. assist (* -- argv, CLASSIFIER_STATE_NAME, states, SIZEOF (states));
  180. }
  181. memset (classifier-&gt;CR_VALUE, 0, sizeof (classifier-&gt;CR_VALUE));
  182. break;
  183. case FIELD_VLAN_TAG:
  184. if ((code = lookup (* argv++, states, SIZEOF (states))) == -1)
  185. {
  186. assist (* -- argv, CLASSIFIER_STATE_NAME, states, SIZEOF (states));
  187. }
  188. memset (classifier-&gt;CR_VALUE, 0, sizeof (classifier-&gt;CR_VALUE));
  189. classifier-&gt;CR_OPERAND ^= code;
  190. break;
  191. default:
  192. error (1, ENOTSUP, &quot;%s&quot;, argv [- 2]);
  193. break;
  194. }
  195. rule-&gt;NUM_CLASSIFIERS++;
  196. classifier++;
  197. argc--;
  198. }
  199. memcpy (classifier, cspec, sizeof (* cspec));
  200. if ((code = lookup (* argv++, controls, SIZEOF (controls))) == -1)
  201. {
  202. assist (* -- argv, CLASSIFIER_CONTROL_NAME, controls, SIZEOF (controls));
  203. }
  204. rule-&gt;MCONTROL = (uint8_t) (code);
  205. argc--;
  206. if ((code = lookup (* argv++, volatilities, SIZEOF (volatilities))) == -1)
  207. {
  208. assist (* -- argv, CLASSIFIER_VOLATILITY_NAME, volatilities, SIZEOF (volatilities));
  209. }
  210. rule-&gt;MVOLATILITY = (uint8_t) (code);
  211. argc--;
  212. * argcp = argc;
  213. * argvp = argv;
  214. return (0);
  215. }
  216. </pre>
  217. <div class='footerlink'>
  218. [<a href='output.c.html' title=' output.c '>PREV</a>]
  219. [<a href='toolkit.html' title=' Index '>HOME</a>]
  220. [<a href='pcapdevs.c.html' title=' pcapdevs.c '>NEXT</a>]
  221. </div>
  222. </body>
  223. </html>