diff options
author | 2011-11-09 16:08:43 +0100 | |
---|---|---|
committer | 2011-11-09 16:20:38 +0100 | |
commit | 6801b5f1358c3d60e9125755cc8e4c517bd5e63d (patch) | |
tree | 64a2c26a16592ee56e69ad7c06d89bc4427820f1 | |
parent | 5e7f6e5f7263f8b248c16a93c050de35d904711c (diff) |
retrieve the upstream MTU
Signed-off-by: Bjørn Mork <bjorn@mork.no>
-rw-r--r-- | ldra.c | 25 |
1 files changed, 21 insertions, 4 deletions
@@ -42,6 +42,18 @@ code sample: http://aschauf.landshut.org/fh/linux/udp_vs_raw/ch01s03.html + + +TODO: + + = collect input: + + - upstream interface + - enterprisenumber for remote ID + - client interface mappings (if, vlan, remoteid, subscriberid, trusted) + + = use mmap packet interface + */ #include <arpa/inet.h> @@ -134,11 +146,11 @@ u_int32_t chksum(char *buf, size_t n) return sum; } -/* calculate IPv6 udp chksum, blindly assuming that there are no other headers in the packet */ +/* calculate IPv6 udp chksum, blindly assuming that the UDP header follows immediately after the IP header */ u_int16_t udp6chksum(struct ip6_hdr *ip6) { - int len = ntohs(ip6->ip6_plen); struct udphdr *udp = (struct udphdr *)((char *)ip6 + sizeof(struct ip6_hdr)); + int len = ntohs(udp->len); u_int32_t sum = chksum((char *)udp, len); /* udp header + packet data */ /* add the pseudo header: src + dst + nxtheader + length */ @@ -302,6 +314,7 @@ int main(int argc, char *argv[]) { int idx_up, idx_down; struct in6_addr all_dhcp_servers_and_relays; + int mtu; /* get this from the upstream interface? */ /* prepare for comparing later on */ @@ -323,13 +336,18 @@ int main(int argc, char *argv[]) { idx_up = ifr.ifr_ifindex; + /* it's the upstream MTU that will be a problem */ + if (ioctl(s, SIOCGIFMTU, &ifr, sizeof(ifr))) + fprintf(stderr, "%s(): SIOCGIFMTU failed: %m\n", __FUNCTION__); + mtu = ifr.ifr_mtu; + strncpy((char *)&ifr.ifr_name, downstream, IFNAMSIZ); if (ioctl(s, SIOCGIFINDEX, &ifr, sizeof(ifr))) fprintf(stderr, "%s(): SIOCGIFINDEX failed: %m\n", __FUNCTION__); idx_down = ifr.ifr_ifindex; - fprintf(stderr,"idx_down=%d, idx_up=%d\n", idx_down, idx_up); + fprintf(stderr,"idx_down=%d, idx_up=%d, mtu=%d\n", idx_down, idx_up, mtu); /* Maybe bind to exactly two interfaces - one upstream and one downstream, using a specifically crated filter for each socket? */ @@ -539,7 +557,6 @@ Steven McCanne and Van Jacobson of Lawrence Berkeley Laboratory. int *val; int hopcount = 0; int trusted = 1; /* FIMXE: allow setting this per interface */ - int mtu = 1500; /* FIMXE: get this from the upstream interface? */ /* FIMXE: We receive three(!) copies of the same frame in the common case: |