dhcpd code changes

Jeffrey Hutzelman jhutz at cmu.edu
Wed Nov 4 19:00:32 UTC 2009


--On Wednesday, November 04, 2009 06:31:06 AM +0530 Ashmath Khan 
<hashmat.email at gmail.com> wrote:

> And can somebody please let me know in which file is exactly the conf
> rules are evaluated and applied on the incoming packets ?

The answer to this is fairly complex, but I'll give it a try.  Bear in mind 
I only have a fairly old tree (3.0.x) available for reference, so things 
may have been rearranged somewhat since then...

- Lexical analysis takes place in common/conflex.c, with the assistance
  of some tables defined in common/tables.c and server/stables.c

- Parsing takes place largely in common/parse.c, but some bits unique to
  the server take place in server/confpars.c, so you need to start there.

- Statement execution happens in common/execute.c

- Expression evaluation happens in common/tree.c

- The actual work of processing incoming DHCP requests, including deciding
  whether to grant access, what address to assign, options evaluation, and
  determining which statements to execute, happens mostly in server/dhcp.c.

The sorts of enhancements you were describing in your previous message 
ought to be possible modifying only common code.  For example, to add 
support for inequalities, you'd need to do the following:

- Add values for the new operators to the expr_op enum in includes/tree.h
- Modify parse_expression() in common/parse.c to recognize <, >, <=, and
  >= as operators (for <= and >=, look at how it already handles BANG to
  distinguish ! from !=) and turn them into expressions using the new
  operators
- Add cases to the various functions in common/tree.c to handle recognizing
  the new operators as boolean expressions, evaluating them, and rejecting
  them when another expression type is called for.
- Add cases to print_subexpression() in common/print.c to handle printing
  expressions involving the new operators.  Don't forget this, or you'll
  get incorrect lease file entries for leases which have triggers using
  the new operators.

-- Jeffrey T. Hutzelman (N3NHS) <jhutz+ at cmu.edu>
   Carnegie Mellon University - Pittsburgh, PA




More information about the dhcp-hackers mailing list