List of commits:
Subject Hash Author Date (UTC)
Added KA. ec9b4556e51ca9a807400910f8ca6d698f9ad670 Catalin(ux) M. BOIE 2010-12-14 16:53:58
Bump up the version to 0.5. f7ba7f0feb49ac4942d85903d31e085f1ffa6149 Catalin(ux) M. BOIE 2010-11-07 23:16:25
Duilder updates. 4d3691f340591f68f9b0ae704da24b4352957f05 Catalin(ux) M. BOIE 2010-11-07 23:15:29
Added support to force TOS by using env var FORCE_NET_TOS. 319cfbee315a0c6889791b122fdb8069aa2ffdf1 Catalin(ux) M. BOIE 2010-11-07 23:14:23
No need for duilder_release. I will use a global one. 15a59294aa3922e58bff8aaa9de7cc06dc44fe1e Catalin(ux) M. BOIE 2010-10-27 20:43:15
TODO in. 9ea8407b8a2767debcf7597bbfc1bddfe44c78eb Catalin(ux) M. BOIE 2010-10-27 20:21:13
Typo. 2282d895e91cf2b02a7b67d933af2c68db5798b6 Catalin(ux) M. BOIE 2010-10-27 19:54:40
Aded license information to README file. fe8071fd2d9f912136fb7fa22f289ddc63cf0f14 Catalin(ux) M. BOIE 2010-10-27 19:46:48
Improved description. 1f17958175bf3f2a656a365fdafca21118737cf1 Catalin(ux) M. BOIE 2010-10-27 19:43:33
Silence compiler useless warning. 117e169b70197ac7e62907f855eb475a0a43fe07 Catalin(ux) M. BOIE 2010-10-27 19:24:45
Bump up the version to 0.4. 59371ee292d38d489719f105a9ff16c923be09d0 Catalin(ux) M. BOIE 2010-10-27 19:16:53
Corrected documentation. cf9d535fcb9d433b8a66c3c5283d9d9d64ae7240 Catalin(ux) M. BOIE 2010-10-27 19:16:29
Nothing to install in /usr/bin! d6eecf1bb4cfcf3d4bc08d8e87cac05f567fd51c Catalin(ux) M. BOIE 2010-10-27 19:13:54
Bump version to 0.3. 3531182e79370861cf73083948494eb4a8ced776 Catalin(ux) M. BOIE 2010-10-27 19:13:01
Store latest version/revision into LATEST_VER/REV for easy web update. 2d3036b2a52f2825cb7be39dc3039c0c6637b4f0 Catalin(ux) M. BOIE 2010-10-27 13:03:22
Fixed install command. 85e4aa9778fa4f10df5f313aff4444f7ec1d2619 Catalin(ux) M. BOIE 2010-10-27 12:29:47
First version. 2d1ffe53a6cfd146f91157baeadb101a59fdd556 Catalin(ux) M. BOIE 2010-10-27 12:21:37
Commit ec9b4556e51ca9a807400910f8ca6d698f9ad670 - Added KA.
Signed-off-by: Catalin(ux) M. BOIE <catab@embedromix.ro>
Author: Catalin(ux) M. BOIE
Author date (UTC): 2010-12-14 16:53
Committer name: Catalin(ux) M. BOIE
Committer date (UTC): 2010-12-19 19:37
Parent(s): f7ba7f0feb49ac4942d85903d31e085f1ffa6149
Signing key:
Tree: a8c54b86d8d2612df0681370b92c7f2fc0815d8b
File Lines added Lines deleted
force_bind.c 59 11
test_ka1.sh 7 0
File force_bind.c changed (mode: 100644) (index a5207a6..2e5a072)
28 28 #include <fcntl.h> #include <fcntl.h>
29 29 #include <sys/socket.h> #include <sys/socket.h>
30 30 #include <arpa/inet.h> #include <arpa/inet.h>
31 #include <netinet/in.h>
32 #include <netinet/tcp.h>
31 33
32 34
33 35 static int (*old_bind)(int sockfd, const struct sockaddr *addr, socklen_t addrlen) = NULL; static int (*old_bind)(int sockfd, const struct sockaddr *addr, socklen_t addrlen) = NULL;
 
... ... static int (*old_setsockopt)(int sockfd, int level, int optname, const void *op
35 37 static int (*old_socket)(int domain, int type, int protocol); static int (*old_socket)(int domain, int type, int protocol);
36 38 static char *force_address = NULL; static char *force_address = NULL;
37 39 static int force_port = -1; static int force_port = -1;
38 static char set_tos = 0;
39 static unsigned char tos;
40 static unsigned int set_tos = 0, tos;
41 static unsigned int set_keepalive = 0, keepalive;
40 42
41 43 /* Functions */ /* Functions */
42 44
45 static void set_ka(int sock)
46 {
47 int flag, ret;
48
49 flag = (keepalive > 0) ? 1 : 0;
50 ret = old_setsockopt(sock, SOL_SOCKET, SO_KEEPALIVE, &flag, sizeof(flag));
51 syslog(LOG_INFO, "force_bind: changing SO_KEEPALIVE to 1 (ret=%d).\n", ret);
52 }
53
54 static void set_ka_idle(int sock)
55 {
56 int ret;
57
58 ret = old_setsockopt(sock, IPPROTO_TCP, TCP_KEEPIDLE, &keepalive, sizeof(keepalive));
59 syslog(LOG_INFO, "force_bind: changing TCP_KEEPIDLE to %us (ret=%d).\n",
60 keepalive, ret);
61 }
62
43 63 void init(void) void init(void)
44 64 { {
45 65 static unsigned char inited = 0; static unsigned char inited = 0;
 
... ... void init(void)
73 93 tos); tos);
74 94 } }
75 95
96 /* keep alive */
97 x = getenv("FORCE_NET_KA");
98 if (x != NULL) {
99 set_keepalive = 1;
100 keepalive = strtoul(x, NULL, 0);
101 syslog(LOG_INFO, "force_bind: Force KA to %u.\n",
102 keepalive);
103 }
104
76 105 old_bind = dlsym(RTLD_NEXT, "bind"); old_bind = dlsym(RTLD_NEXT, "bind");
77 106 if (old_bind == NULL) { if (old_bind == NULL) {
78 107 syslog(LOG_ERR, "force_bind: Cannot resolve 'bind'!\n"); syslog(LOG_ERR, "force_bind: Cannot resolve 'bind'!\n");
 
... ... int setsockopt(int sockfd, int level, int optname, const void *optval,
145 174 { {
146 175 init(); init();
147 176
148 switch (optname) {
149 case IP_TOS:
150 if (set_tos == 1) {
151 syslog(LOG_INFO, "force_bind: changing TOS from %hhu to %hhu.\n",
152 *(char *)optval, tos);
153 optval = &tos;
154 }
155 break;
177 if (level == SOL_SOCKET) {
178 if ((optname == SO_KEEPALIVE) && (set_keepalive == 1)) {
179 set_ka(sockfd);
180 return 0;
181 }
182 }
183
184 if (level == IPPROTO_IP) {
185 if ((optname == IP_TOS) && (set_tos == 1)) {
186 syslog(LOG_INFO, "force_bind: changing TOS from %hhu to %hhu.\n",
187 *(char *)optval, tos);
188 optval = &tos;
189 optlen = sizeof(tos);
190 }
156 191 } }
157 192
193 if (level == IPPROTO_TCP) {
194 if ((optname == TCP_KEEPIDLE) && (set_keepalive == 1)) {
195 set_ka_idle(sockfd);
196 return 0;
197 }
198 }
158 199
159 200 return old_setsockopt(sockfd, level, optname, optval, optlen); return old_setsockopt(sockfd, level, optname, optval, optlen);
160 201 } }
 
... ... int socket(int domain, int type, int protocol)
173 214 return -1; return -1;
174 215
175 216 if (set_tos == 1) if (set_tos == 1)
176 setsockopt(sock, IPPROTO_IP, IP_TOS, &tos, 1);
217 setsockopt(sock, IPPROTO_IP, IP_TOS, &tos, sizeof(tos));
218
219 if (set_keepalive == 1) {
220 set_ka(sock);
221
222 if (type == SOCK_STREAM)
223 set_ka_idle(sock);
224 }
177 225
178 226 return sock; return sock;
179 227 } }
File test_ka1.sh added (mode: 100755) (index 0000000..3abe306)
1 #!/bin/sh
2
3 export FORCE_NET_TOS="0xff"
4
5 export LD_PRELOAD="${LD_PRELOAD}:./force_bind.so"
6
7 exec ./test_bind "$@"
Hints:
Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://rocketgit.com/user/catalinux/force_bind

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@ssh.rocketgit.com/user/catalinux/force_bind

Clone this repository using git:
git clone git://git.rocketgit.com/user/catalinux/force_bind

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a merge request:
... clone the repository ...
... make some changes and some commits ...
git push origin main