From 6801b5f1358c3d60e9125755cc8e4c517bd5e63d Mon Sep 17 00:00:00 2001 From: Bjørn Mork Date: Wed, 9 Nov 2011 16:08:43 +0100 Subject: retrieve the upstream MTU MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Bjørn Mork --- ldra.c | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/ldra.c b/ldra.c index 30954e2..723d189 100644 --- a/ldra.c +++ b/ldra.c @@ -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 @@ -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: -- cgit v1.2.3