summaryrefslogtreecommitdiffstats
path: root/contrib/traceroute
diff options
context:
space:
mode:
authortuexen <tuexen@FreeBSD.org>2015-05-31 12:03:38 +0000
committertuexen <tuexen@FreeBSD.org>2015-05-31 12:03:38 +0000
commitb8a0027b6d0313b154e2023a4931d830c4005841 (patch)
tree57c9fb181342bce66b6dabafbdeeed6240400a7d /contrib/traceroute
parent5da06ca262db2a05a1c6624c6da9f50d75faebc8 (diff)
downloadFreeBSD-src-b8a0027b6d0313b154e2023a4931d830c4005841.zip
FreeBSD-src-b8a0027b6d0313b154e2023a4931d830c4005841.tar.gz
Don't send illegal packets when using UDP-Lite.
MFC after: 3 days
Diffstat (limited to 'contrib/traceroute')
-rw-r--r--contrib/traceroute/traceroute.813
-rw-r--r--contrib/traceroute/traceroute.c47
2 files changed, 50 insertions, 10 deletions
diff --git a/contrib/traceroute/traceroute.8 b/contrib/traceroute/traceroute.8
index e7e9456..952da41 100644
--- a/contrib/traceroute/traceroute.8
+++ b/contrib/traceroute/traceroute.8
@@ -65,7 +65,7 @@ Turn on AS# lookups and use the given server instead of the
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 than symbolically and numerically
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
diff --git a/contrib/traceroute/traceroute.c b/contrib/traceroute/traceroute.c
index 7572c8e..9ec655f 100644
--- a/contrib/traceroute/traceroute.c
+++ b/contrib/traceroute/traceroute.c
@@ -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 cc, register struct sockaddr_in *from)
* 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, int len)
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));
}
OpenPOWER on IntegriCloud