| 1 |
== Configure common reply options |
| 2 |
|
| 3 |
FreeRADIUS includes a powerful xref:index.adoc[policy language] called |
| 4 |
"unlang". |
| 5 |
|
| 6 |
Statements in unlang may be used to call further policies, update attribute |
| 7 |
lists and invoke modules. There are also control flow statements (if, |
| 8 |
switch, etc.) typical of most imperative languages. |
| 9 |
|
| 10 |
FreeRADIUS has a number attribute lists that it maintains as it processes |
| 11 |
packets within the virtual server sections. Most relevant to DHCP are |
| 12 |
`request`, `control` and `reply`. |
| 13 |
|
| 14 |
The DHCP options from the current request packet are provided in the |
| 15 |
`request` list. This includes fixed DHCP parameters such as |
| 16 |
`DHCP-Client-Hardware-Address`, optional parameters such as |
| 17 |
`DHCP-Requested-IP-Address`, and parameters synthesised by FreeRADIUS such as |
| 18 |
`DHCP-Message-Type` and `DHCP-Network-Subnet`. |
| 19 |
|
| 20 |
DHCP options can be set by updating their value in the `reply` list. This |
| 21 |
forms the basis of the packet returned to the client. |
| 22 |
|
| 23 |
In the default DHCP server configuration, a "policy" (akin to a subroutine) is |
| 24 |
used to set common options for reply packets. The policy is found in |
| 25 |
`<raddb>/policy.d/dhcp`. |
| 26 |
|
| 27 |
Look at the contents of the `dhcp_common` section and set any global options |
| 28 |
applicable to all clients in this policy. |
| 29 |
|
| 30 |
[source,unlang] |
| 31 |
---- |
| 32 |
dhcp_common { |
| 33 |
update reply { |
| 34 |
&DHCP-Domain-Name-Server := 8.8.8.8 |
| 35 |
&DHCP-Domain-Name-Server += 8.8.4.4 |
| 36 |
&DHCP-Subnet-Mask := 255.255.255.0 |
| 37 |
&DHCP-Router-Address := 192.0.2.1 |
| 38 |
... |
| 39 |
} |
| 40 |
} |
| 41 |
---- |
| 42 |
|
| 43 |
Note, FreeRADIUS has four main operators for assigning values to attributes: |
| 44 |
|
| 45 |
`=`:: Add the attribute to the list, if and only if an attribute of the same |
| 46 |
name is not already present in that list. |
| 47 |
`:=`:: Add the attribute to the list. If any attribute of the same name is |
| 48 |
already present in that list it is replaced with the new one. |
| 49 |
`+=`:: Add the attribute to the tail of the list, even if attributes of the |
| 50 |
same name are already present in the list. |
| 51 |
`^=`:: Add the attribute to the head of the list, even if attributes of the |
| 52 |
same name are already present in the list. |
| 53 |
|
| 54 |
These operators allow for attributes to be set to default values and then |
| 55 |
overwritten, e.g. setting a default lease time, but then overwriting it for |
| 56 |
a particular group of clients. |
| 57 |
|
| 58 |
Attributes in the `control` list are not returned in the DHCP reply packets |
| 59 |
but instead govern aspects of server's behaviour. |
| 60 |
|
| 61 |
To use an SQL backend for either static or dynamic IP allocation, un-comment |
| 62 |
the block: |
| 63 |
|
| 64 |
[source,unlang] |
| 65 |
---- |
| 66 |
update control { |
| 67 |
&Pool-Name := "local" |
| 68 |
} |
| 69 |
dhcp_sqlippool |
| 70 |
---- |
| 71 |
|
| 72 |
The `Pool-Name` control attribute is used in looking up addresses in the |
| 73 |
database. The line containing `dhcp_sqlippool` is a call to invoke an |
| 74 |
instance of a module with that name. This module is responsible for assigning a |
| 75 |
free IP address into the `DHCP-Your-IP-Address` reply attribute from the pool |
| 76 |
identified by `Pool-Name`. |
| 77 |
|
| 78 |
Here `Pool-Name` is being set to a constant value (`local`) indicating |
| 79 |
that a single pool is to be used. If you have multiple pools, then replace this |
| 80 |
`update` block with logic to map clients to the correct pool, as described below. |