classify.xml 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
  3. "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd" [
  4. <!ENTITY mdash "&#x2014;" >
  5. ]>
  6. <chapter id="classify">
  7. <title>Client Classification</title>
  8. <section>
  9. <title>Client Classification Overview</title>
  10. <para>
  11. In certain cases it is useful to differentiate between different
  12. types of clients and treat them accordingly. There are many reasons
  13. why one might want to treat clients different some common reasons
  14. include:
  15. <itemizedlist>
  16. <listitem><para>
  17. The clients represent different pieces of topology, for example a cable
  18. modem vs the clients behind that modem.
  19. </para></listitem>
  20. <listitem><para>
  21. The clients have different behavior, for example a smart phone vs a lapttop
  22. vs a desktop.
  23. </para></listitem>
  24. <listitem><para>
  25. The clients require different values for some options, for example a docsis3.0
  26. cable modem vs a docsis2.0 cable modem.
  27. </para></listitem>
  28. </itemizedlist>
  29. </para>
  30. <para>
  31. It is envisaged that client classification will be used for changing the
  32. behavior of almost any part of the DHCP message processing, including assigning
  33. leases from different pools, assigning different options (or different values of
  34. the same options) etc. For now, there are only two mechanisms that take
  35. advantage of client classification: subnet selection and assigning different
  36. options. For cable modems there are specific options for use with the TFTP
  37. server address and the boot file field.
  38. </para>
  39. <para>
  40. The process of doing classification is conducted in three steps. The first step
  41. is to assess an incoming packet and assign it to zero or more classes. The
  42. second step is to choose a subnet, possibly based on the class information.
  43. The third step is to assign options again possibly based on the class
  44. information.
  45. </para>
  46. <para>
  47. When determining which options to include in the response the server will
  48. examine the union of options from all of the assigned classes. In the case two
  49. or more classes include an option the value from the first class will be used.
  50. Similarly if two or more classes are associated with a subnet the first subnet
  51. will be used. In the future the processing order of the various classes may
  52. be specified but for now it is being left unspecified and may change in
  53. future releases.
  54. </para>
  55. <para>
  56. For example imagine two classes. Class "foo" defines values for an NTP server
  57. (option 42 in DHCPv4) and an SMTP server (option 69 in DHCPv4) while class
  58. "bar" defines values for an NTP server and a POP3 server (option 70 in DHCPv4).
  59. The server will examine the three options NTP, SMTP and POP3 and return any
  60. of them that the client requested. As the NTP server was defined twice the
  61. server will choose only one of the values for the reply.
  62. </para>
  63. <para>
  64. There are two methods of doing classification. The first is automatic and relies
  65. on examining the values in the vendor class options. Information from these
  66. options is extracted and a class name is constructed from it and added to
  67. the class list for the packet. The second allows you to specify an expression
  68. that is evaluated for each packet. If the result is true the packet is
  69. a member of the class.
  70. </para>
  71. <note>
  72. <para>
  73. The power of the expressions in the classification step is deliberately
  74. limited in order to minimize the amount of time required to process each
  75. expression. The expression for each class must be executed on each packet,
  76. if they are overly complex or time consuming they may impact the performance
  77. of the server. If you need complex or time consuming expressions you
  78. should write a hook to perform the necessary work.
  79. </para>
  80. </note>
  81. <note>
  82. <para>
  83. Care should be taken with client classification as it is easy for
  84. clients that do not meet class criteria to be denied any service altogether.
  85. </para>
  86. </note>
  87. </section>
  88. <section id="classification-using-vendor">
  89. <title>Using Vendor Class Information In Classification</title>
  90. <para>
  91. The server checks whether an incoming DHCPv4 packet includes
  92. the vendor class identifier option (60) or an incoming DHCPv6 packet
  93. includes the vendor class option (16). If it does, the content of that
  94. option is prepended with &quot;VENDOR_CLASS_&quot; then it is interpreted
  95. as a class. For example, modern cable modems will send this option with
  96. value &quot;docsis3.0&quot; and as a result the packet will belong to
  97. class &quot;VENDOR_CLASS_docsis3.0&quot;.
  98. </para>
  99. </section>
  100. <section id="classification-using-expressions">
  101. <title>Using Expressions In Classification</title>
  102. <para>
  103. The expression portion of classification contains operators and values.
  104. Values are currently strings and operators take a string or strings and
  105. return another string. When all the operations have completed
  106. the result should be a value of &quot;true&quot; or &quot;false&quot;.
  107. The packet belongs to
  108. the class (and the class name is added to the list of classes) if the result
  109. is &quot;true&quot;. Expressions are written in standard format and can be nested.
  110. </para>
  111. <para>
  112. Expressions are pre-processed during the parsing of the configuration file
  113. and converted to an internal representation. This allows certain types of
  114. errors (such as incorrect syntax) to be caught and logged. Other errors
  115. (for example mistakes when setting up the values for a substring) won't be
  116. caught and may affect the classification. In general if an expression has
  117. a problem a log message will be emitted at the debug level and the result
  118. will be an empty string.
  119. </para>
  120. <para>
  121. The expressions are a work in progress and the supported operators and
  122. values are limited. The expectation is that additional operators and values
  123. will be added over time, however it is expected the basic mechanisms will
  124. remain the same.
  125. </para>
  126. <para>
  127. <table frame="all" id="classification-values-list">
  128. <title>List of Classification Values</title>
  129. <tgroup cols='3'>
  130. <colspec colname='name' />
  131. <colspec colname='example' />
  132. <colspec colname='description' />
  133. <thead>
  134. <row>
  135. <entry>Name</entry>
  136. <entry>Example</entry>
  137. <entry>Description</entry>
  138. </row>
  139. </thead>
  140. <tbody>
  141. <row><entry>String</entry><entry>'example'</entry><entry>A string</entry></row>
  142. <row><entry>Hex String</entry><entry>0XABCD</entry><entry>A hexadecimal string</entry></row>
  143. <row><entry>Integer</entry><entry>123</entry><entry>An integer value</entry></row>
  144. <row><entry>Option</entry><entry>option[code]</entry><entry>The value of the option with code "code" from the packet</entry></row>
  145. </tbody>
  146. </tgroup>
  147. </table>
  148. </para>
  149. <para>
  150. Hex Strings are converted into a string as expected. The starting &quot;0X&quot; or
  151. &quot;0x&quot; is removed and if the string is an odd number of characters a
  152. &quot;0&quot; is prepended to it.
  153. </para>
  154. <para>
  155. Option extracts the value of the given option from the incoming packet. If the
  156. packet doesn't contain the option it returns an empty string.
  157. </para>
  158. <para>
  159. <table frame="all" id="classification-expressions-list">
  160. <title>List of Classification Expressions</title>
  161. <tgroup cols='3'>
  162. <colspec colname='name' />
  163. <colspec colname='example' />
  164. <colspec colname='description' />
  165. <thead>
  166. <row>
  167. <entry>Name</entry>
  168. <entry>Example</entry>
  169. <entry>Description</entry>
  170. </row>
  171. </thead>
  172. <tbody>
  173. <row><entry>Equal</entry> <entry>'foo' == 'bar'</entry><entry>Compare the two values and return "true" or "false"</entry></row>
  174. <row><entry>Substring</entry><entry>substring('foobar',0,3)</entry><entry>Return the requested substring</entry></row>
  175. </tbody>
  176. </tgroup>
  177. </table>
  178. </para>
  179. <para>
  180. The substring operator substring(value, start, length) accepts both positive and
  181. negative values for the starting position and the length. For start a value of
  182. 0 is the first byte in the string while -1 is the last byte. If the starting
  183. point is outside of the original string an empty string is returned. Length
  184. is the number of bytes to extract. A negative number means to count towards
  185. the beginning of the string but doesn't include the byte pointed to by start.
  186. The special value "all" means to return all bytes from start to the end of the
  187. string. If length is longer than the remaining portion of the string then
  188. the entire remaining portion is returned.
  189. </para>
  190. </section>
  191. <section id="classification-configuring">
  192. <title>Configuring Classes</title>
  193. <para>
  194. A class contains three items: a name, a test expression and option data.
  195. The name must exist and must be unique amongst all classes. The test
  196. expression and option data are optional.
  197. </para>
  198. <para>
  199. The test expression is a string containing the logical expression used to
  200. determine membership in the class. The entire expression is in double
  201. quotes.
  202. </para>
  203. <para>
  204. The option data is a list which defines any options that should be assigned
  205. to members of this class.
  206. </para>
  207. <para>
  208. <screen>
  209. "Dhcp4": {
  210. "subnet4": [
  211. {
  212. "subnet": "192.0.2.0/24",
  213. "pools": [ { "pool": "192.0.2.10 - 192.0.2.20" } ],
  214. "client-class": "Client_foo"
  215. }
  216. ],
  217. "client-class": [
  218. <userinput>
  219. {
  220. "name": "Client_foo",
  221. "test": "substring(option[61],0,3) == 'foo'",
  222. "option-data": [
  223. {
  224. "name": "doamin-name-servers",
  225. "code": 6,
  226. "space": "dhcp4",
  227. "csv-format": true,
  228. "data": "192.0.2.1, 192.0.2.2"
  229. }
  230. ]
  231. }
  232. </userinput>
  233. ...
  234. }</screen>
  235. </para>
  236. <para>
  237. In this example the class named &quot;Client_foo&quot; is defined. It is comprised
  238. of all clients who's client ids (option 61) start with the string &quot;foo&quot;.
  239. They will be given an address from 192.0.2.10 to 192.0.2.20 and 192.0.2.1
  240. and 192.0.2.2 as their domain name servers.
  241. </para>
  242. </section>
  243. <section id="classification-subnets">
  244. <title>Configuring Subnets With Class Information</title>
  245. <para>
  246. In certain cases it beneficial to restrict access to certain subnets
  247. only to clients that belong to a given subnet. For details on client
  248. classes, see <xref linkend="classification-using-vendor"/> and
  249. <xref linkend="classification-using-expressions"/>
  250. Let's assume that the server is connected to a network segment that uses
  251. the 192.0.2.0/24 prefix. The Administrator of that network has decided
  252. that addresses from range 192.0.2.10 to 192.0.2.20 are going to be
  253. managed by the DHCP4 server. Only clients belonging to client class
  254. Client_foo are allowed to use this subnet. Such a
  255. configuration can be achieved in the following way:
  256. <screen>
  257. "Dhcp4": {
  258. "subnet4": [
  259. <userinput>
  260. {
  261. "subnet": "192.0.2.0/24",
  262. "pools": [ { "pool": "192.0.2.10 - 192.0.2.20" } ],
  263. "client-class": "Client_foo"
  264. }
  265. </userinput>
  266. ],
  267. "client-class": [
  268. {
  269. "name": "Client_foo",
  270. "test": "substring(option[61],0,3) == 'foo'",
  271. "option-data": [
  272. {
  273. "name": "doamin-name-servers",
  274. "code": 6,
  275. "space": "dhcp4",
  276. "csv-format": true,
  277. "data": "192.0.2.1, 192.0.2.2"
  278. }
  279. ]
  280. }
  281. ...
  282. }</screen>
  283. </para>
  284. </section>
  285. <section>
  286. <title>Using Classes</title>
  287. <para>
  288. Currently classes can be used for two functions. They can supply options
  289. to the members class and they can choose a subnet for the members of the class.
  290. </para>
  291. <para>
  292. When supplying options class options defined as part of the class definition
  293. are considred &quot;class globals&quot;. They will override any global options that
  294. may be defined and in turn will be overridden by any options defined for an
  295. individual subnet.
  296. </para>
  297. </section>
  298. <section>
  299. <title>Classes and Hooks</title>
  300. <para>
  301. You may use a hook to classify your packets. This may be useful if the
  302. expression would either be complex or time consuming and be easier or
  303. better to write as code. Once the hook has added the proper class name
  304. to the packet the rest of the classification system will work as normal
  305. in choosing a subnet and selecting options. For a description of the
  306. hooks see <xref linkend="hooks-libraries"/>, for a description on
  307. configuring he classes see <xref linkend="classification-configuring"/>
  308. and <xref linkend="classification-subnets"/>.
  309. </para>
  310. </section>
  311. </chapter>