svn commit: r283817 - head/contrib/traceroute
Michael Tuexen
tuexen at FreeBSD.org
Sun May 31 12:03:39 UTC 2015
Author: tuexen
Date: Sun May 31 12:03:38 2015
New Revision: 283817
URL: https://svnweb.freebsd.org/changeset/base/283817
Log:
Don't send illegal packets when using UDP-Lite.
MFC after: 3 days
Modified:
head/contrib/traceroute/traceroute.8
head/contrib/traceroute/traceroute.c
Modified: head/contrib/traceroute/traceroute.8
==============================================================================
--- head/contrib/traceroute/traceroute.8 Sun May 31 11:56:59 2015 (r283816)
+++ head/contrib/traceroute/traceroute.8 Sun May 31 12:03:38 2015 (r283817)
@@ -65,7 +65,7 @@ Turn on AS# lookups and use the giv
default.
.It Fl e
Firewall evasion mode.
-Use fixed destination ports for UDP, TCP and SCTP probes.
+Use fixed destination ports for UDP, UDP-Lite, TCP and SCTP probes.
The destination port does NOT increment with each packet sent.
.It Fl f Ar first_ttl
Set the initial time-to-live used in the first outgoing probe packet.
@@ -110,18 +110,21 @@ Print hop addresses numerically rather t
path).
.It Fl P Ar proto
Send packets of specified IP protocol. The currently supported protocols
-are: UDP, TCP, SCTP, GRE and ICMP. Other protocols may also be specified
-(either by name or by number), though
+are: UDP, UDP-Lite, TCP, SCTP, GRE and ICMP. Other protocols may also be
+specified (either by name or by number), though
.Nm
does not implement any special knowledge of their packet formats. This
option is useful for determining which router along a path may be
blocking packets based on IP protocol number. But see BUGS below.
.It Fl p Ar port
-Protocol specific. For UDP, TCP and SCTP, sets
+Protocol specific. For UDP, UDP-Lite, TCP and SCTP, sets
the base
.Ar port
number used in probes (default is 33434).
-Traceroute hopes that nothing is listening on UDP ports
+Traceroute hopes that nothing is listening on UDP ports (or UDP-Lite ports
+if used by
+.Nm
+and supported by the peer)
.Em base
to
.Em base + nhops * nprobes - 1
Modified: head/contrib/traceroute/traceroute.c
==============================================================================
--- head/contrib/traceroute/traceroute.c Sun May 31 11:56:59 2015 (r283816)
+++ head/contrib/traceroute/traceroute.c Sun May 31 12:03:38 2015 (r283817)
@@ -371,7 +371,7 @@ u_short in_cksum(u_short *, int);
u_int32_t sctp_crc32c(const void *, u_int32_t);
char *inetname(struct in_addr);
int main(int, char **);
-u_short p_cksum(struct ip *, u_short *, int);
+u_short p_cksum(struct ip *, u_short *, int, int);
int packet_ok(u_char *, int, struct sockaddr_in *, int);
char *pr_type(u_char);
void print(u_char *, int, struct sockaddr_in *);
@@ -391,6 +391,8 @@ int usleep(u_int);
void udp_prep(struct outdata *);
int udp_check(const u_char *, int);
+void udplite_prep(struct outdata *);
+int udplite_check(const u_char *, int);
void tcp_prep(struct outdata *);
int tcp_check(const u_char *, int);
void sctp_prep(struct outdata *);
@@ -428,6 +430,15 @@ struct outproto protos[] = {
udp_check
},
{
+ "udplite",
+ "spt dpt cov sum",
+ IPPROTO_UDPLITE,
+ sizeof(struct udphdr),
+ 32768 + 666,
+ udplite_prep,
+ udplite_check
+ },
+ {
"tcp",
"spt dpt seq ack xxflwin sum urp",
IPPROTO_TCP,
@@ -1404,7 +1415,7 @@ udp_prep(struct outdata *outdata)
outudp->uh_ulen = htons((u_short)protlen);
outudp->uh_sum = 0;
if (doipcksum) {
- u_short sum = p_cksum(outip, (u_short*)outudp, protlen);
+ u_short sum = p_cksum(outip, (u_short*)outudp, protlen, protlen);
outudp->uh_sum = (sum) ? sum : 0xffff;
}
@@ -1421,6 +1432,32 @@ udp_check(const u_char *data, int seq)
}
void
+udplite_prep(struct outdata *outdata)
+{
+ struct udphdr *const outudp = (struct udphdr *) outp;
+
+ outudp->uh_sport = htons(ident + (fixedPort ? outdata->seq : 0));
+ outudp->uh_dport = htons(port + (fixedPort ? 0 : outdata->seq));
+ outudp->uh_ulen = htons(8);
+ outudp->uh_sum = 0;
+ if (doipcksum) {
+ u_short sum = p_cksum(outip, (u_short*)outudp, protlen, 8);
+ outudp->uh_sum = (sum) ? sum : 0xffff;
+ }
+
+ return;
+}
+
+int
+udplite_check(const u_char *data, int seq)
+{
+ struct udphdr *const udp = (struct udphdr *) data;
+
+ return (ntohs(udp->uh_sport) == ident + (fixedPort ? seq : 0) &&
+ ntohs(udp->uh_dport) == port + (fixedPort ? 0 : seq));
+}
+
+void
tcp_prep(struct outdata *outdata)
{
struct tcphdr *const tcp = (struct tcphdr *) outp;
@@ -1434,7 +1471,7 @@ tcp_prep(struct outdata *outdata)
tcp->th_sum = 0;
if (doipcksum) {
- u_short sum = p_cksum(outip, (u_short*)tcp, protlen);
+ u_short sum = p_cksum(outip, (u_short*)tcp, protlen, protlen);
tcp->th_sum = (sum) ? sum : 0xffff;
}
}
@@ -1557,7 +1594,7 @@ print(register u_char *buf, register int
* Checksum routine for UDP and TCP headers.
*/
u_short
-p_cksum(struct ip *ip, u_short *data, int len)
+p_cksum(struct ip *ip, u_short *data, int len, int cov)
{
static struct ipovly ipo;
u_short sum[2];
@@ -1568,7 +1605,7 @@ p_cksum(struct ip *ip, u_short *data, in
ipo.ih_dst = ip->ip_dst;
sum[1] = in_cksum((u_short*)&ipo, sizeof(ipo)); /* pseudo ip hdr cksum */
- sum[0] = in_cksum(data, len); /* payload data cksum */
+ sum[0] = in_cksum(data, cov); /* payload data cksum */
return ~in_cksum(sum, sizeof(sum));
}
More information about the svn-src-all
mailing list