#
server dhcp {
-# This is part RADIUS legacy (sorry). Clients have to be defined for
-# DHCP. This is not normal practice for a DHCP server, but it does
-# enable a simple filter list of "known clients".
-#
-
-# DHCP packets are normally sent with source IP address 0.0.0.0.
-# If you want to accept packets from any IP, uncomment the "netmask"
-# entry below, and delete the other "client" sections in this file.
-client any {
- ipaddr = 0.0.0.0
- #netmask = 0
- dhcp = yes
-}
-
-# For local testing.
-client localnet {
- ipaddr = 127.0.0.0
- netmask = 8
- dhcp = yes
-}
-
# Define a DHCP socket.
#
# The default port below is 6700, so you don't break your network.
#ifdef WITH_DHCP
+/*
+ * Same layout, etc. as listen_socket_t.
+ */
+typedef struct dhcp_socket_t {
+ /*
+ * For normal sockets.
+ */
+ fr_ipaddr_t ipaddr;
+ int port;
+#ifdef SO_BINDTODEVICE
+ const char *interface;
+#endif
+ int suppress_responses;
+ RADCLIENT dhcp_client;
+} dhcp_socket_t;
+
static int dhcp_process(REQUEST *request)
{
int rcode;
{
int rcode;
int on = 1;
- listen_socket_t *sock;
+ dhcp_socket_t *sock;
+ RADCLIENT *client;
+ CONF_PAIR *cp;
rcode = common_socket_parse(cs, this);
if (rcode != 0) return rcode;
return -1;
}
+ /*
+ * Undocumented extension for testing without
+ * destroying your network!
+ */
+ sock->suppress_responses = FALSE;
+ cp = cf_pair_find(cs, "suppress_responses");
+ if (cp) {
+ const char *value;
+
+ value = cf_pair_value(cp);
+
+ if (value && (strcmp(value, "yes") == 0)) {
+ sock->suppress_responses = TRUE;
+ }
+ }
+
+ /*
+ * Initialize the fake client.
+ */
+ client = &sock->dhcp_client;
+ memset(client, 0, sizeof(*client));
+ client->ipaddr.af = AF_INET;
+ client->ipaddr.ipaddr.ip4addr.s_addr = INADDR_NONE;
+ client->prefix = 0;
+ client->longname = client->shortname = "dhcp";
+ client->secret = client->shortname;
+ client->nastype = strdup("none");
+
return 0;
}
RAD_REQUEST_FUNP *pfun, REQUEST **prequest)
{
RADIUS_PACKET *packet;
- RADCLIENT *client;
+ dhcp_socket_t *sock;
packet = fr_dhcp_recv(listener->fd);
if (!packet) {
return 0;
}
- if ((client = client_listener_find(listener,
- &packet->src_ipaddr,
- packet->src_port)) == NULL) {
- rad_free(&packet);
- return 0;
- }
-
- if (!received_request(listener, packet, prequest, client)) {
+ sock = listener->data;
+ if (!received_request(listener, packet, prequest, &sock->dhcp_client)) {
rad_free(&packet);
return 0;
}
*/
static int dhcp_socket_send(rad_listen_t *listener, REQUEST *request)
{
+ dhcp_socket_t *sock;
+
rad_assert(request->listener == listener);
rad_assert(listener->send == dhcp_socket_send);
return -1;
}
+ sock = listener->data;
+ if (sock->suppress_responses) return 0;
+
+ /*
+ * Don't send anything
+ */
return fr_dhcp_send(request->reply);
}