Skip to content

Instantly share code, notes, and snippets.

@djGrrr
Created June 15, 2023 18:50
Show Gist options
  • Save djGrrr/ff59c6ce094f103d3305dbcfeeb6421f to your computer and use it in GitHub Desktop.
Save djGrrr/ff59c6ce094f103d3305dbcfeeb6421f to your computer and use it in GitHub Desktop.
diff -ur /root/dhclient/bpf.c sbin/dhclient/bpf.c
--- /root/dhclient/bpf.c 2023-06-15 11:41:32.749372000 -0230
+++ sbin/dhclient/bpf.c 2023-06-15 16:12:19.135346000 -0230
@@ -365,7 +365,7 @@
if (to.s_addr == INADDR_BROADCAST)
assemble_hw_header(interface, buf, &bufp);
assemble_udp_ip_header(buf, &bufp, from.s_addr, to.s_addr,
- htons(REMOTE_PORT), (unsigned char *)&raw, len);
+ htons(REMOTE_PORT), (unsigned char *)&raw, len, interface);
iov[0].iov_base = buf;
iov[0].iov_len = bufp;
diff -ur /root/dhclient/clparse.c sbin/dhclient/clparse.c
--- /root/dhclient/clparse.c 2023-06-15 11:41:32.754958000 -0230
+++ sbin/dhclient/clparse.c 2023-06-15 12:23:19.363379000 -0230
@@ -47,6 +47,7 @@
#include "dhcpd.h"
#include "dhctoken.h"
+#include <netinet/ip.h>
struct client_config top_level_config;
static struct interface_info *dummy_interfaces;
@@ -77,6 +78,7 @@
/* Set some defaults... */
top_level_config.vlan_pcp = 0;
+ top_level_config.ip_tos = IPTOS_LOWDELAY;
top_level_config.timeout = 60;
top_level_config.select_interval = 0;
top_level_config.reboot_timeout = 10;
@@ -264,6 +266,10 @@
case VLAN_PCP:
parse_lease_time(cfile, &tmp);
config->vlan_pcp = (u_int)tmp;
+ return;
+ case IP_TYPE_OF_SERVICE:
+ parse_lease_time(cfile, &tmp);
+ config->ip_tos = (u_int)tmp;
return;
case BACKOFF_CUTOFF:
parse_lease_time(cfile, &config->backoff_cutoff);
diff -ur /root/dhclient/conflex.c sbin/dhclient/conflex.c
--- /root/dhclient/conflex.c 2023-06-15 11:41:32.753160000 -0230
+++ sbin/dhclient/conflex.c 2023-06-15 12:23:39.691000000 -0230
@@ -417,6 +417,8 @@
return (INITIAL_INTERVAL);
if (!strcasecmp(atom + 1, "nterface"))
return (INTERFACE);
+ if (!strcasecmp(atom + 1, "p-tos"))
+ return (IP_TYPE_OF_SERVICE);
break;
case 'l':
if (!strcasecmp(atom + 1, "ease"))
diff -ur /root/dhclient/dhclient.conf.5 sbin/dhclient/dhclient.conf.5
--- /root/dhclient/dhclient.conf.5 2023-06-15 11:41:32.754695000 -0230
+++ sbin/dhclient/dhclient.conf.5 2023-06-15 12:14:24.848188000 -0230
@@ -491,6 +491,10 @@
This requires the
.Va net.link.vlan.mtag_pcp
sysctl to be set to 1.
+.It Ic ip-tos Ar code ;
+The
+.Ic ip-tos
+statement sets the TOS (Type Of Service) value for the IP header.
.El
.Sh EXAMPLES
The following configuration file is used on a laptop
diff -ur /root/dhclient/dhcpd.h sbin/dhclient/dhcpd.h
--- /root/dhclient/dhcpd.h 2023-06-15 11:41:32.753355000 -0230
+++ sbin/dhclient/dhcpd.h 2023-06-15 16:13:32.942743000 -0230
@@ -160,6 +160,7 @@
u_int8_t requested_options[256];
int requested_option_count;
u_int vlan_pcp;
+ u_int ip_tos;
time_t timeout;
time_t initial_interval;
time_t retry_interval;
@@ -421,7 +422,7 @@
/* packet.c */
void assemble_hw_header(struct interface_info *, unsigned char *, int *);
void assemble_udp_ip_header(unsigned char *, int *, u_int32_t, u_int32_t,
- unsigned int, unsigned char *, int);
+ unsigned int, unsigned char *, int, struct interface_info *);
ssize_t decode_hw_header(unsigned char *, int, struct hardware *);
ssize_t decode_udp_ip_header(unsigned char *, int, struct sockaddr_in *,
unsigned char *, int);
diff -ur /root/dhclient/dhctoken.h sbin/dhclient/dhctoken.h
--- /root/dhclient/dhctoken.h 2023-06-15 11:41:32.751929000 -0230
+++ sbin/dhclient/dhctoken.h 2023-06-15 12:22:58.524456000 -0230
@@ -134,6 +134,7 @@
#define TOKEN_NOT 334
#define ALWAYS_REPLY_RFC1048 335
#define VLAN_PCP 336
+#define IP_TYPE_OF_SERVICE 337
#define is_identifier(x) ((x) >= FIRST_TOKEN && \
(x) != STRING && \
diff -ur /root/dhclient/packet.c sbin/dhclient/packet.c
--- /root/dhclient/packet.c 2023-06-15 11:41:32.749546000 -0230
+++ sbin/dhclient/packet.c 2023-06-15 16:15:58.529029000 -0230
@@ -111,14 +111,15 @@
void
assemble_udp_ip_header(unsigned char *buf, int *bufix, u_int32_t from,
- u_int32_t to, unsigned int port, unsigned char *data, int len)
+ u_int32_t to, unsigned int port, unsigned char *data, int len,
+ struct interface_info *interface)
{
struct ip ip;
struct udphdr udp;
ip.ip_v = 4;
ip.ip_hl = 5;
- ip.ip_tos = IPTOS_LOWDELAY;
+ ip.ip_tos = interface->client->config->ip_tos;
ip.ip_len = htons(sizeof(ip) + sizeof(udp) + len);
ip.ip_id = 0;
ip.ip_off = 0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment