Skip to content

Commit

Permalink
udhcp: set DHCP messages CoS priority to 6
Browse files Browse the repository at this point in the history
  • Loading branch information
clementperon committed Jan 27, 2023
1 parent 6a9bfb4 commit 49dfbf6
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 0 deletions.
8 changes: 8 additions & 0 deletions networking/udhcp/Config.src
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,14 @@ config UDHCPC_DEFAULT_DECLINE_SCRIPT
The script is called after client receives offer from server.
Decline script returns 0 when offer should be accepted.

config FEATURE_UDHCPC_COS
bool "Support Class of Service for DHCP Client"
default y
depends on UDHCPC
help
If selected, udhcpc will set -y socket priority.
script returns 1.

config UDHCP_DEBUG
int "Maximum verbosity level (0..9)"
default 2
Expand Down
6 changes: 6 additions & 0 deletions networking/udhcp/d6_dhcpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ static const char udhcpc6_longopts[] ALIGN1 =
)
/// IF_FEATURE_UDHCPC_ARPING("arping\0" No_argument "a")
IF_FEATURE_UDHCP_PORT("client-port\0" Required_argument "P")
IF_FEATURE_UDHCPC_COS("cos\0" Required_argument "y")
;
#endif
/* Must match getopt32 option string order */
Expand Down Expand Up @@ -1152,6 +1153,9 @@ static void client_background(void)
////usage: IF_FEATURE_UDHCPC_ARPING(
////usage: "\n -a Use arping to validate offered address"
////usage: )
//usage: IF_FEATURE_UDHCPC_COS(
//usage: "\n -y PRIORITY CoS value 0 .. 7, default 0"
//usage: )
//usage: "\n -l Send 'information request' instead of 'solicit'"
//usage: "\n (used for servers which do not assign IPv6 addresses)"
//usage: "\n -r IPv6 Request this address ('no' to not request any IP)"
Expand Down Expand Up @@ -1213,6 +1217,7 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv)
USE_FOR_MMU("b")
///IF_FEATURE_UDHCPC_ARPING("a")
IF_FEATURE_UDHCP_PORT("P:")
IF_FEATURE_UDHCPC_COS("y:+")
"v"
"\0" IF_UDHCP_VERBOSE("vv") /* -v is a counter */
, udhcpc6_longopts
Expand All @@ -1222,6 +1227,7 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv)
, &list_O
, &list_x
IF_FEATURE_UDHCP_PORT(, &str_P)
IF_FEATURE_UDHCPC_COS(, &sk_prio)
IF_UDHCP_VERBOSE(, &dhcp_verbose)
);
requested_ipv6 = NULL;
Expand Down
8 changes: 8 additions & 0 deletions networking/udhcp/d6_packet.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,14 @@ int FAST_FUNC d6_send_raw_packet_from_client_data_ifindex(
packet.ip6.ip6_hlim = 1; /* observed Windows machines to use hlim=1 */
packet.ip6.ip6_nxt = IPPROTO_UDP;

IF_FEATURE_UDHCPC_COS(
if (sk_prio) {
if (setsockopt(fd, SOL_SOCKET, SO_PRIORITY, &sk_prio, sizeof(sk_prio))) {
log1s("raw: SO_PRIORITY (dscp v6) setsockopt() failed");
}
})


d6_dump_packet(d6_pkt);
result = sendto(fd, &packet, offsetof(struct ip6_udp_d6_packet, data) + d6_pkt_size,
/*flags:*/ 0,
Expand Down
6 changes: 6 additions & 0 deletions networking/udhcp/dhcpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ static const char udhcpc_longopts[] ALIGN1 =
IF_FEATURE_UDHCPC_ARPING("arping\0" Optional_argument "a")
IF_FEATURE_UDHCP_PORT("client-port\0" Required_argument "P")
IF_FEATURE_UDHCPC_DECLINE("decline-script\0" Required_argument "d")
IF_FEATURE_UDHCPC_COS("cos\0" Required_argument "y")
;
#endif
/* Must match getopt32 option string order */
Expand Down Expand Up @@ -1241,6 +1242,9 @@ static int udhcp_run_decline_script(struct dhcp_packet *packet)
//usage: IF_FEATURE_UDHCPC_ARPING(
//usage: "\n -a[MSEC] Validate offered address with ARP ping"
//usage: )
//usage: IF_FEATURE_UDHCPC_COS(
//usage: "\n -y PRIORITY CoS value 0 .. 7, default 0"
//usage: )
//usage: "\n -r IP Request this IP address"
//usage: "\n -o Don't request any options (unless -O is given)"
//usage: "\n -O OPT Request option OPT from server (cumulative)"
Expand Down Expand Up @@ -1307,6 +1311,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
IF_FEATURE_UDHCPC_ARPING("a::")
IF_FEATURE_UDHCP_PORT("P:")
IF_FEATURE_UDHCPC_DECLINE("d:")
IF_FEATURE_UDHCPC_COS("y:+")
"v"
"\0" IF_UDHCP_VERBOSE("vv") /* -v is a counter */
, udhcpc_longopts
Expand All @@ -1320,6 +1325,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
IF_FEATURE_UDHCPC_ARPING(, &str_a)
IF_FEATURE_UDHCP_PORT(, &str_P)
IF_FEATURE_UDHCPC_DECLINE(, &client_data.decline_script)
IF_FEATURE_UDHCPC_COS(, &sk_prio)
IF_UDHCP_VERBOSE(, &dhcp_verbose)
);
if (opt & OPT_F) {
Expand Down
2 changes: 2 additions & 0 deletions networking/udhcp/dhcpc.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

PUSH_AND_SET_FUNCTION_VISIBILITY_TO_HIDDEN

IF_FEATURE_UDHCPC_COS(extern uint32_t sk_prio;)

struct client_data_t {
uint8_t client_mac[6]; /* Our mac address */
IF_FEATURE_UDHCP_PORT(uint16_t port;)
Expand Down
9 changes: 9 additions & 0 deletions networking/udhcp/packet.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#include <netinet/if_ether.h>
#include <netpacket/packet.h>

IF_FEATURE_UDHCPC_COS(uint32_t sk_prio;)

#if ENABLE_UDHCPC || ENABLE_UDHCPD
void FAST_FUNC udhcp_init_header(struct dhcp_packet *packet, char type)
{
Expand Down Expand Up @@ -174,6 +176,13 @@ int FAST_FUNC udhcp_send_raw_packet(struct dhcp_packet *dhcp_pkt,
packet.ip.ttl = IPDEFTTL;
packet.ip.check = inet_cksum(&packet.ip, sizeof(packet.ip));

IF_FEATURE_UDHCPC_COS(
if (sk_prio) {
if (setsockopt(fd, SOL_SOCKET, SO_PRIORITY, &sk_prio, sizeof(sk_prio))) {
log1s("raw: SO_PRIORITY (dscp v6) setsockopt() failed");
}
})

udhcp_dump_packet(dhcp_pkt);
result = sendto(fd, &packet, IP_UDP_DHCP_SIZE - padding, /*flags:*/ 0,
(struct sockaddr *) &dest_sll, sizeof(dest_sll));
Expand Down

0 comments on commit 49dfbf6

Please sign in to comment.