[PATCH][RFC] udhcp: add option to set CoS priority
Clément Péron
peron.clem at gmail.com
Fri Jan 13 09:48:42 UTC 2023
Some ISP, like the French ISP Orange uses DHCP messages with
a CoS Priority of 6 otherwise they are not processed.
Add an option to allow setting this property.
Signed-off-by: Clément Péron <peron.clem at gmail.com>
---
networking/udhcp/Config.src | 8 ++++++++
networking/udhcp/d6_dhcpc.c | 6 ++++++
networking/udhcp/d6_packet.c | 14 ++++++++++++++
networking/udhcp/dhcpc.c | 12 +++++++++++-
networking/udhcp/dhcpc.h | 2 ++
networking/udhcp/packet.c | 16 ++++++++++++++++
6 files changed, 57 insertions(+), 1 deletion(-)
diff --git a/networking/udhcp/Config.src b/networking/udhcp/Config.src
index 7ba7f48fc..49d5d7ef1 100644
--- a/networking/udhcp/Config.src
+++ b/networking/udhcp/Config.src
@@ -137,6 +137,14 @@ config UDHCP_DEBUG
Bigger values result in bigger code. Levels above 1
are very verbose and useful for debugging only.
+config FEATURE_UDHCPC_COS
+ bool "Enable '-y priority' option for udhcpc"
+ default n
+ depends on UDHCPC || UDHCPC6
+ help
+ At the cost of ~300 bytes, enables -y priority option.
+ This feature is typically not needed.
+
config UDHCPC_SLACK_FOR_BUGGY_SERVERS
int "DHCP options slack buffer size"
default 80
diff --git a/networking/udhcp/d6_dhcpc.c b/networking/udhcp/d6_dhcpc.c
index cdd06188e..675914432 100644
--- a/networking/udhcp/d6_dhcpc.c
+++ b/networking/udhcp/d6_dhcpc.c
@@ -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 */
@@ -1153,6 +1154,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)"
@@ -1214,6 +1218,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
@@ -1223,6 +1228,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;
diff --git a/networking/udhcp/d6_packet.c b/networking/udhcp/d6_packet.c
index 142de9b43..425037ada 100644
--- a/networking/udhcp/d6_packet.c
+++ b/networking/udhcp/d6_packet.c
@@ -68,6 +68,13 @@ int FAST_FUNC d6_send_raw_packet_from_client_data_ifindex(
goto ret_msg;
}
+ IF_FEATURE_UDHCPC_COS(
+ if (sk_prio) {
+ if (setsockopt_int(fd, SOL_SOCKET, SO_PRIORITY, sk_prio)) {
+ log1s("raw: SO_PRIORITY setsockopt() failed");
+ }
+ })
+
memset(&dest_sll, 0, sizeof(dest_sll));
memset(&packet, 0, offsetof(struct ip6_udp_d6_packet, data));
packet.data = *d6_pkt; /* struct copy */
@@ -153,6 +160,13 @@ int FAST_FUNC d6_send_kernel_packet_from_client_data_ifindex(
}
setsockopt_reuseaddr(fd);
+ IF_FEATURE_UDHCPC_COS(
+ if (sk_prio) {
+ if (setsockopt_int(fd, SOL_SOCKET, SO_PRIORITY, sk_prio)) {
+ log1s("raw: SO_PRIORITY setsockopt() failed");
+ }
+ })
+
memset(&sa, 0, sizeof(sa));
sa.sin6_family = AF_INET6;
sa.sin6_port = htons(source_port);
diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c
index c757fb37c..7ff5ffde8 100644
--- a/networking/udhcp/dhcpc.c
+++ b/networking/udhcp/dhcpc.c
@@ -1085,6 +1085,13 @@ static int udhcp_raw_socket(int ifindex)
}
#endif
+IF_FEATURE_UDHCPC_COS(
+ if (sk_prio) {
+ if (setsockopt_int(fd, SOL_SOCKET, SO_PRIORITY, sk_prio)) {
+ log1s("raw: SO_PRIORITY setsockopt() failed");
+ }
+ })
+
if (setsockopt_1(fd, SOL_PACKET, PACKET_AUXDATA) != 0) {
if (errno != ENOPROTOOPT)
log1s("can't set PACKET_AUXDATA on raw socket");
@@ -1162,7 +1169,7 @@ static void client_background(void)
//usage:#endif
//usage:#define udhcpc_trivial_usage
//usage: "[-fbq"IF_UDHCP_VERBOSE("v")"RB]"IF_FEATURE_UDHCPC_ARPING(" [-a[MSEC]]")" [-t N] [-T SEC] [-A SEC|-n]\n"
-//usage: " [-i IFACE]"IF_FEATURE_UDHCP_PORT(" [-P PORT]")" [-s PROG] [-p PIDFILE]\n"
+//usage: " [-i IFACE]"IF_FEATURE_UDHCP_PORT(" [-P PORT]")" "IF_FEATURE_UDHCPC_COS(" [-y PRIORITY]")" [-s PROG] [-p PIDFILE]\n"
//usage: " [-oC] [-r IP] [-V VENDOR] [-F NAME] [-x OPT:VAL]... [-O OPT]..."
//usage:#define udhcpc_full_usage "\n"
//usage: "\n -i IFACE Interface to use (default "CONFIG_UDHCPC_DEFAULT_INTERFACE")"
@@ -1186,6 +1193,9 @@ static void client_background(void)
//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)"
diff --git a/networking/udhcp/dhcpc.h b/networking/udhcp/dhcpc.h
index 19b054b32..c033eb13f 100644
--- a/networking/udhcp/dhcpc.h
+++ b/networking/udhcp/dhcpc.h
@@ -7,6 +7,8 @@
PUSH_AND_SET_FUNCTION_VISIBILITY_TO_HIDDEN
+IF_FEATURE_UDHCPC_COS(extern int sk_prio;)
+
struct client_data_t {
uint8_t client_mac[6]; /* Our mac address */
IF_FEATURE_UDHCP_PORT(uint16_t port;)
diff --git a/networking/udhcp/packet.c b/networking/udhcp/packet.c
index 529978189..0babf451f 100644
--- a/networking/udhcp/packet.c
+++ b/networking/udhcp/packet.c
@@ -12,6 +12,8 @@
#include <netinet/if_ether.h>
#include <netpacket/packet.h>
+IF_FEATURE_UDHCPC_COS(int sk_prio;)
+
#if ENABLE_UDHCPC || ENABLE_UDHCPD
void FAST_FUNC udhcp_init_header(struct dhcp_packet *packet, char type)
{
@@ -121,6 +123,13 @@ int FAST_FUNC udhcp_send_raw_packet(struct dhcp_packet *dhcp_pkt,
goto ret_msg;
}
+ IF_FEATURE_UDHCPC_COS(
+ if (sk_prio) {
+ if (setsockopt_int(fd, SOL_SOCKET, SO_PRIORITY, sk_prio)) {
+ log1s("raw: SO_PRIORITY setsockopt() failed");
+ }
+ })
+
memset(&dest_sll, 0, sizeof(dest_sll));
memset(&packet, 0, offsetof(struct ip_udp_dhcp_packet, data));
packet.data = *dhcp_pkt; /* struct copy */
@@ -207,6 +216,13 @@ int FAST_FUNC udhcp_send_kernel_packet(struct dhcp_packet *dhcp_pkt,
}
setsockopt_reuseaddr(fd);
+ IF_FEATURE_UDHCPC_COS(
+ if (sk_prio) {
+ if (setsockopt_int(fd, SOL_SOCKET, SO_PRIORITY, sk_prio)) {
+ log1s("raw: SO_PRIORITY setsockopt() failed");
+ }
+ })
+
/* If interface carrier goes down, unless we
* bind socket to a particular netdev, the packet
* can go out through another interface, eg. via
--
2.34.1
More information about the busybox
mailing list