Subject: [PATCH] Orange EdgeOS: dhclient patch Heavily inspired from https://github.com/shisva/USG_Orange --- common/discover.c | 4 ++++ common/lpf.c | 8 ++++++++ common/raw.c | 4 ++++ common/socket.c | 8 ++++++++ minires/res_send.c | 13 +++++++++++++ omapip/connection.c | 4 ++++ omapip/listener.c | 4 ++++ omapip/mrtrace.c | 10 ++++++++-- 8 files changed, 53 insertions(+), 2 deletions(-) diff --git a/common/discover.c b/common/discover.c index 706a08c..d487794 100644 --- a/common/discover.c +++ b/common/discover.c @@ -248,6 +248,10 @@ begin_iface_scan(struct iface_conf_list *ifaces) { return 0; } + /* Set Kernel Priority to 6 */ + int val = 6; + setsockopt(ifaces->sock, SOL_SOCKET, SO_PRIORITY, &val, sizeof(val)); + memset(&lifnum, 0, sizeof(lifnum)); #ifdef ISC_PLATFORM_HAVELIFNUM lifnum.lifn_family = AF_UNSPEC; diff --git a/common/lpf.c b/common/lpf.c index fcf7db1..3800ca3 100644 --- a/common/lpf.c +++ b/common/lpf.c @@ -89,6 +89,10 @@ int if_register_lpf (info) log_fatal ("Open a socket for LPF: %m"); } + /* Set Kernel Priority to 6 */ + int val = 6; + setsockopt(sock, SOL_SOCKET, SO_PRIORITY, &val, sizeof (val)); + memset (&ifr, 0, sizeof ifr); strncpy (ifr.ifr_name, (const char *)info -> ifp, sizeof ifr.ifr_name); ifr.ifr_name[IFNAMSIZ-1] = '\0'; @@ -495,6 +499,10 @@ get_hw_addr(const char *name, struct hardware *hw) { log_fatal("Can't create socket for \"%s\": %m", name); } + /* Set Kernel Priority to 6 */ + int val = 6; + setsockopt(sock, SOL_SOCKET, SO_PRIORITY, &val, sizeof(val)); + memset(&tmp, 0, sizeof(tmp)); strcpy(tmp.ifr_name, name); if (ioctl(sock, SIOCGIFHWADDR, &tmp) < 0) { diff --git a/common/raw.c b/common/raw.c index a15f8ee..b588f1b 100644 --- a/common/raw.c +++ b/common/raw.c @@ -66,6 +66,10 @@ void if_register_send (info) if ((sock = socket (AF_INET, SOCK_RAW, IPPROTO_RAW)) < 0) log_fatal ("Can't create dhcp socket: %m"); + /* Set Kernel Priority to 6 */ + int val = 6; + setsockopt(sock, SOL_SOCKET, SO_PRIORITY, &val, sizeof(val)); + /* Set the BROADCAST option so that we can broadcast DHCP responses. */ flag = 1; if (setsockopt (sock, SOL_SOCKET, SO_BROADCAST, diff --git a/common/socket.c b/common/socket.c index 3fe3d09..8f94a63 100644 --- a/common/socket.c +++ b/common/socket.c @@ -189,6 +189,10 @@ if_register_socket(struct interface_info *info, int family, log_fatal("Can't create dhcp socket: %m"); } + /* Set Kernel Priority to 6 */ + int val = 6; + setsockopt(sock, SOL_SOCKET, SO_PRIORITY, &val, sizeof(val)); + /* Set the REUSEADDR option so that we don't fail to start if we're being restarted. */ flag = 1; @@ -1174,6 +1178,10 @@ get_hw_addr(const char *name, struct hardware *hw) { } flag_check: + /* Set Kernel Priority to 6 */ + int val = 6; + setsockopt(sock, SOL_SOCKET, SO_PRIORITY, &val, sizeof(val)); + if (lifr.lifr_flags & (IFF_VIRTUAL|IFF_IPMP)) { hw->hlen = sizeof (hw->hbuf); srandom((long)gethrtime()); diff --git a/minires/res_send.c b/minires/res_send.c index dca3db6..0d5e1fd 100644 --- a/minires/res_send.c +++ b/minires/res_send.c @@ -375,6 +375,11 @@ res_nsend(res_state statp, "socket(vc)", errno); return (-1); } + + /* Set Kernel Priority to 6 */ + int val = 6; + setsockopt(statp->_sock, SOL_SOCKET, SO_PRIORITY, &val, sizeof(val)); + errno = 0; if (connect(statp->_sock, (struct sockaddr *)nsap, @@ -533,6 +538,10 @@ res_nsend(res_state statp, "socket(dg)", errno); return terrno; } + /* Set Kernel Priority to 6 */ + int val = 6; + setsockopt(statp->_sock, SOL_SOCKET, SO_PRIORITY, &val, sizeof(val)); + statp->_flags &= ~RES_F_CONN; } #ifndef CANNOT_CONNECT_DGRAM @@ -600,6 +609,10 @@ res_nsend(res_state statp, len = sizeof(local_addr); s1 = socket(PF_INET, SOCK_DGRAM, 0); + /* Set Kernel Priority to 6 */ + int val = 6; + setsockopt(s1, SOL_SOCKET, SO_PRIORITY, &val, sizeof(val)); + result = getsockname(statp->_sock, (struct sockaddr *)&local_addr, &len); diff --git a/omapip/connection.c b/omapip/connection.c index fcaee61..03039ef 100644 --- a/omapip/connection.c +++ b/omapip/connection.c @@ -147,6 +147,10 @@ isc_result_t omapi_connect_list (omapi_object_t *c, return ISC_R_UNEXPECTED; } + /* Set Kernel Priority to 6 */ + int val = 6; + setsockopt(obj -> socket, SOL_SOCKET, SO_PRIORITY, &val, sizeof(val)); + /* Set up the local address, if any. */ if (local_addr) { /* Only do TCPv4 so far. */ diff --git a/omapip/listener.c b/omapip/listener.c index 9cd1ee4..9ee5fed 100644 --- a/omapip/listener.c +++ b/omapip/listener.c @@ -126,6 +126,10 @@ isc_result_t omapi_listen_addr (omapi_object_t *h, goto error_exit; } + /* Set Kernel Priority to 6 */ + int val = 6; + setsockopt(obj -> socket, SOL_SOCKET, SO_PRIORITY, &val, sizeof(val)); + #if defined (HAVE_SETFD) if (fcntl (obj -> socket, F_SETFD, 1) < 0) { status = ISC_R_UNEXPECTED; diff --git a/omapip/mrtrace.c b/omapip/mrtrace.c index d74bc32..702b7f9 100644 --- a/omapip/mrtrace.c +++ b/omapip/mrtrace.c @@ -343,10 +343,16 @@ int trace_mr_connect (int s, struct sockaddr *name, SOCKLEN_T namelen) int trace_mr_socket (int domain, int type, int protocol) { #if defined (TRACING) - if (!trace_playback ()) + if (!trace_playback ()) { #endif - return socket (domain, type, protocol); + int sock = socket (domain, type, protocol); + /* Set Kernel Priority to 6 */ + int val = 6; + setsockopt(sock, SOL_SOCKET, SO_PRIORITY, &val, sizeof(val)); + + return sock; #if defined (TRACING) + } return 100; #endif } --