linux-qubasis
linux oasis port as a qubes template
git clone https://9o.is/git/linux-qubasis.git
0026-nc-Portability-fixes-from-libressl-portable.patch
(5335B)
1 From 05fd24cc7b3f1b73a58d41d70ef725925007165c Mon Sep 17 00:00:00 2001
2 From: Michael Forney <mforney@mforney.org>
3 Date: Mon, 2 Dec 2019 21:11:04 -0800
4 Subject: [PATCH] nc: Portability fixes from libressl-portable
5
6 ---
7 usr.bin/nc/netcat.c | 55 +++++++++++++++++++++++++++++++++++++++------
8 1 file changed, 48 insertions(+), 7 deletions(-)
9
10 diff --git a/usr.bin/nc/netcat.c b/usr.bin/nc/netcat.c
11 index 8c60fd18826..b5129c2204d 100644
12 --- a/usr.bin/nc/netcat.c
13 +++ b/usr.bin/nc/netcat.c
14 @@ -93,9 +93,13 @@ int zflag; /* Port Scan Flag */
15 int Dflag; /* sodebug */
16 int Iflag; /* TCP receive buffer size */
17 int Oflag; /* TCP send buffer size */
18 +#ifdef TCP_MD5SIG
19 int Sflag; /* TCP MD5 signature option */
20 +#endif
21 int Tflag = -1; /* IP Type of Service */
22 +#ifdef SO_RTABLE
23 int rtableid = -1;
24 +#endif
25
26 int usetls; /* use TLS */
27 const char *Cflag; /* Public cert file */
28 @@ -268,12 +272,14 @@ main(int argc, char *argv[])
29 case 'u':
30 uflag = 1;
31 break;
32 +#ifdef SO_RTABLE
33 case 'V':
34 rtableid = (int)strtonum(optarg, 0,
35 RT_TABLEID_MAX, &errstr);
36 if (errstr)
37 errx(1, "rtable %s: %s", errstr, optarg);
38 break;
39 +#endif
40 case 'v':
41 vflag = 1;
42 break;
43 @@ -320,9 +326,11 @@ main(int argc, char *argv[])
44 case 'o':
45 oflag = optarg;
46 break;
47 +#ifdef TCP_MD5SIG
48 case 'S':
49 Sflag = 1;
50 break;
51 +#endif
52 case 'T':
53 errstr = NULL;
54 errno = 0;
55 @@ -346,9 +354,11 @@ main(int argc, char *argv[])
56 argc -= optind;
57 argv += optind;
58
59 +#ifdef SO_RTABLE
60 if (rtableid >= 0)
61 if (setrtable(rtableid) == -1)
62 err(1, "setrtable");
63 +#endif
64
65 /* Cruft to make sure options are clean, and used properly. */
66 if (argc == 1 && family == AF_UNIX) {
67 @@ -923,7 +933,10 @@ remote_connect(const char *host, const char *port, struct addrinfo hints,
68 char *ipaddr)
69 {
70 struct addrinfo *res, *res0;
71 - int s = -1, error, herr, on = 1, save_errno;
72 + int s = -1, error, herr, save_errno;
73 +#ifdef SO_BINDANY
74 + int on = 1;
75 +#endif
76
77 if ((error = getaddrinfo(host, port, &hints, &res0)))
78 errx(1, "getaddrinfo for host \"%s\" port %s: %s", host,
79 @@ -938,8 +951,10 @@ remote_connect(const char *host, const char *port, struct addrinfo hints,
80 if (sflag || pflag) {
81 struct addrinfo ahints, *ares;
82
83 +#ifdef SO_BINDANY
84 /* try SO_BINDANY, but don't insist */
85 setsockopt(s, SOL_SOCKET, SO_BINDANY, &on, sizeof(on));
86 +#endif
87 memset(&ahints, 0, sizeof(struct addrinfo));
88 ahints.ai_family = res->ai_family;
89 ahints.ai_socktype = uflag ? SOCK_DGRAM : SOCK_STREAM;
90 @@ -1031,8 +1046,11 @@ int
91 local_listen(const char *host, const char *port, struct addrinfo hints)
92 {
93 struct addrinfo *res, *res0;
94 - int s = -1, ret, x = 1, save_errno;
95 + int s = -1, save_errno;
96 int error;
97 +#ifdef SO_REUSEPORT
98 + int ret, x = 1;
99 +#endif
100
101 /* Allow nodename to be null. */
102 hints.ai_flags |= AI_PASSIVE;
103 @@ -1052,9 +1070,11 @@ local_listen(const char *host, const char *port, struct addrinfo hints)
104 res->ai_protocol)) == -1)
105 continue;
106
107 +#ifdef SO_REUSEPORT
108 ret = setsockopt(s, SOL_SOCKET, SO_REUSEPORT, &x, sizeof(x));
109 if (ret == -1)
110 err(1, NULL);
111 +#endif
112
113 set_common_sockopts(s, res->ai_family);
114
115 @@ -1559,11 +1579,13 @@ set_common_sockopts(int s, int af)
116 {
117 int x = 1;
118
119 +#ifdef TCP_MD5SIG
120 if (Sflag) {
121 if (setsockopt(s, IPPROTO_TCP, TCP_MD5SIG,
122 &x, sizeof(x)) == -1)
123 err(1, NULL);
124 }
125 +#endif
126 if (Dflag) {
127 if (setsockopt(s, SOL_SOCKET, SO_DEBUG,
128 &x, sizeof(x)) == -1)
129 @@ -1574,9 +1596,16 @@ set_common_sockopts(int s, int af)
130 IP_TOS, &Tflag, sizeof(Tflag)) == -1)
131 err(1, "set IP ToS");
132
133 +#ifdef IPV6_TCLASS
134 else if (af == AF_INET6 && setsockopt(s, IPPROTO_IPV6,
135 IPV6_TCLASS, &Tflag, sizeof(Tflag)) == -1)
136 err(1, "set IPv6 traffic class");
137 +#else
138 + else if (af == AF_INET6) {
139 + errno = ENOPROTOOPT;
140 + err(1, "set IPv6 traffic class not supported");
141 + }
142 +#endif
143 }
144 if (Iflag) {
145 if (setsockopt(s, SOL_SOCKET, SO_RCVBUF,
146 @@ -1600,13 +1629,17 @@ set_common_sockopts(int s, int af)
147 }
148
149 if (minttl != -1) {
150 +#ifdef IP_MINTTL
151 if (af == AF_INET && setsockopt(s, IPPROTO_IP,
152 IP_MINTTL, &minttl, sizeof(minttl)))
153 err(1, "set IP min TTL");
154 +#endif
155
156 - else if (af == AF_INET6 && setsockopt(s, IPPROTO_IPV6,
157 +#ifdef IPV6_MINHOPCOUNT
158 + if (af == AF_INET6 && setsockopt(s, IPPROTO_IPV6,
159 IPV6_MINHOPCOUNT, &minttl, sizeof(minttl)))
160 err(1, "set IPv6 min hop count");
161 +#endif
162 }
163 }
164
165 @@ -1831,14 +1864,22 @@ help(void)
166 \t-P proxyuser\tUsername for proxy authentication\n\
167 \t-p port\t Specify local port for remote connects\n\
168 \t-R CAfile CA bundle\n\
169 - \t-r Randomize remote ports\n\
170 - \t-S Enable the TCP MD5 signature option\n\
171 + \t-r Randomize remote ports\n"
172 +#ifdef TCP_MD5SIG
173 + "\
174 + \t-S Enable the TCP MD5 signature option\n"
175 +#endif
176 + "\
177 \t-s sourceaddr Local source address\n\
178 \t-T keyword TOS value or TLS options\n\
179 \t-t Answer TELNET negotiation\n\
180 \t-U Use UNIX domain socket\n\
181 - \t-u UDP mode\n\
182 - \t-V rtable Specify alternate routing table\n\
183 + \t-u UDP mode\n"
184 +#ifdef SO_RTABLE
185 + "\
186 + \t-V rtable Specify alternate routing table\n"
187 +#endif
188 + "\
189 \t-v Verbose\n\
190 \t-W recvlimit Terminate after receiving a number of packets\n\
191 \t-w timeout Timeout for connects and final net reads\n\
192 --
193 2.49.0
194