From 0d8490e5f08a9e9edd32f56a0ffe38c1dc460e56 Mon Sep 17 00:00:00 2001 From: Bjørn Mork Date: Wed, 9 Nov 2011 16:08:30 +0100 Subject: remove dead code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Bjørn Mork --- ldra.c | 273 ----------------------------------------------------------------- 1 file changed, 273 deletions(-) diff --git a/ldra.c b/ldra.c index 21dc274..a4cf69b 100644 --- a/ldra.c +++ b/ldra.c @@ -617,259 +617,6 @@ Steven McCanne and Van Jacobson of Lawrence Berkeley Laboratory. return(0); } -#if 0 - - if (vlan && (vlan != 602) && (ll.sll_ifindex == idx_down)) { - /* insert RELAY-MSG + INTERFACE-ID + OPTION_RELAY_MSG header */ - int extra; - struct dhcpv6_option *opt; - int *val; - int new, j; - u_int16_t *csum; - char *p; - int hopcount = 0; - int trusted = 1; /* FIMXE: allow setting this per interface */ - int mtu = 1500; /* FIMXE: get this from the upstream interface? */ - - fprintf(stderr, "down => up\n"); - - fprintf(stderr, "received %d bytes from %s on ifid=%d:\n", len, macstr((char *)ll.sll_addr), ll.sll_ifindex); - print_hex(buf, len); - - /* verify that incoming packet is supposed to be relayed */ - dhcpv6 = (struct dhcpv6_relay_msg *)(buf + PKTHDRZ); /* NOTE: Not necessarily a relay message */ - switch (dhcpv6->msg_type) { - case DHCPV6_ADVERTISE: - case DHCPV6_REPLY: - case DHCPV6_RECONFIGURE: - case DHCPV6_RELAY_REPL: - fprintf(stderr, "ignoring message type %hhu on downstream interface\n", dhcpv6->msg_type); - continue; - case DHCPV6_RELAY_FORW: - if (trusted) - hopcount = dhcpv6->hop_count + 1; /* propagate */ - else { - fprintf(stderr, "ignoring message type DHCPV6_RELAY_FORW on untrusted downstream interface\n"); - continue; - } - } - - /* create outgoing frame */ - /* 1. copy ethernet + IPv6 + udp header */ - eth = memcpy(txbuf, buf, PKTHDRZ); - - /* set up structure for easy data manipulation */ - ip6 = (struct ip6_hdr *)(txbuf + sizeof(struct ethhdr)); - udp = (struct udphdr *)(txbuf + sizeof(struct ethhdr) + sizeof(struct ip6_hdr)); - - fprintf(stderr, "sending from %s", ip6str(&ip6->ip6_src)); - fprintf(stderr, " to %s\n", ip6str(&ip6->ip6_dst)); - - /* 2. fill inn DHCP relay header */ - dhcpv6 = (struct dhcpv6_relay_msg *)(txbuf + PKTHDRZ); - dhcpv6->msg_type = DHCPV6_RELAY_FORW; - dhcpv6->hop_count = hopcount; - memset(&dhcpv6->link_addr, 0, sizeof(dhcpv6->link_addr)); - memcpy(&dhcpv6->peer_addr, &ip6->ip6_src, sizeof(dhcpv6->peer_addr)); - - fprintf(stderr, "sizeof dhcpv6_relay_msg = %d, sizeof(dhcpv6->link_addr)=%d, extra=%d\n", - sizeof(struct dhcpv6_relay_msg), sizeof(dhcpv6->link_addr), extra); - - /* fill in INTERFACE-ID */ - opt = (struct dhcpv6_option *)&dhcpv6->options; - opt->code = htons(OPTION_INTERFACE_ID); - opt->len = htons(sizeof(int)); - val = (int *)&opt->data; - *val = htonl(vlan); - - /* fill in OPTION_RELAY_MSG */ - opt = nextopt(opt); - opt->code = htons(OPTION_RELAY_MSG); - opt->len = htons(ntohs(udp->len) - sizeof(struct udphdr)); - - /* get the totals size of the added DHCP relay message with options */ - extra = (char *)&opt->data - (char *)dhcpv6; - - /* verify that we have enough space lefte for the original DHCP packet */ - if ((extra + len) > mtu) { - fprintf(stderr, "ERROR: relay packet exceeds MTU (%d > %d)\n", (extra + len), mtu); - continue; - } - - - /* copy the original DHCP packet into the OPTION_RELAY_MSG */ - memcpy(&opt->data, (buf + PKTHDRZ), ntohs(opt->len)); - - fprintf(stderr, "verify that extra=%d is equal to %d\n", extra, - sizeof(struct dhcpv6_relay_msg) + 2 * sizeof(struct dhcpv6_option) + sizeof(int)); - - fprintf(stderr, "length of INTERFACE-ID attr is %d\n", (char *)opt - (char *)(&dhcpv6->options)); - - /* update UDP and IPv6 header lengths */ - new = htons(ntohs(udp->len) + extra); - udp->len = new; - ip6->ip6_plen = new; - - /* maybe correct UDP source port? NOTE: may already by 547 if we received the packet from another relay */ - if (ntohs(udp->source) == 546) - udp->source = htons(547); - - /* update UDP checksum - we could have based this on the old sum, but... */ - udp->check = htons(udp6chksum(ip6)); - - /* finally: transmit the packet on the upstream interface */ - - /* packet(7): When you send packets it is enough to specify - sll_family, sll_addr, sll_halen, sll_ifindex. The other - fields should be 0. */ - ll.sll_ifindex = idx_up; - memcpy(&ll.sll_addr, ð->h_dest, ll.sll_halen); - ll.sll_protocol = 0; - ll.sll_hatype = 0; - ll.sll_pkttype = 0; - - fprintf(stderr, "sending %d bytes to %s on ifid=%d:\n", len + extra, macstr((char *)ll.sll_addr), ll.sll_ifindex); - print_hex(txbuf, len + extra); - - if (sendto(s, txbuf, len + extra, 0, (struct sockaddr *)&ll, sizeof(ll)) == -1) - fprintf(stderr, "sendto() failed: %m\n"); - - - - } else if (ll.sll_ifindex == idx_up) { - int j; - struct dhcpv6_option *opt; - int interfaceid = 0; - int datalen = 0; - int packetlen; - struct vlan_tag *vtag; - - fprintf(stderr, "up => down\n"); - - fprintf(stderr, "received %d bytes from %s on ifid=%d:\n", len, macstr((char *)ll.sll_addr), ll.sll_ifindex); - print_hex(buf, len); - - /* verify that incoming packet is supposed to be relayed */ - dhcpv6 = (struct dhcpv6_relay_msg *)(buf + PKTHDRZ); /* NOTE: Not necessarily a relay message */ - switch (dhcpv6->msg_type) { - case DHCPV6_RELAY_REPL: - break; - default: - fprintf(stderr, "ignoring msg_type=%d on upstream interface\n", dhcpv6->msg_type); - continue; - } - - /* FIXME: parse options here, to allow us to decide - * whether or not to add a VLAN tag based on the - * interfaceid - */ - - - /* create outgoing frame */ - - /* 1. copy ethernet header */ - eth = memcpy(txbuf, buf, sizeof(struct ethhdr)); - - /* 2. insert VLAN tag */ - vtag = (struct vlan_tag *)ð->h_proto; - vtag->h_proto = eth->h_proto; /* copy original protocol */ - vtag->v_tpid = htons(ETH_P_8021Q); - - /* 3. copy IPv6 and UDP headers and set up structure pointers */ - ip6 = memcpy(txbuf + sizeof(struct ethhdr) + VLANTAGZ, buf + sizeof(struct ethhdr), sizeof(struct ip6_hdr) + sizeof(struct udphdr)); - udp = (struct udphdr *)(txbuf + sizeof(struct ethhdr) + VLANTAGZ + sizeof(struct ip6_hdr)); - - - /* 4. parse RELAY options */ - opt = (struct dhcpv6_option *)&dhcpv6->options; - do { - fprintf(stderr, "opt=%p, opt->code=%#06hx, opt->len=%hd\n", opt, ntohs(opt->code), ntohs(opt->len)); - - switch (ntohs(opt->code)) { - case OPTION_INTERFACE_ID: - /* sanity: never accept more than one of these! */ - if (interfaceid > 0) { - fprintf(stderr, "multiple OPTION_INTERFACE_ID is not allowed!\n"); - } else { - interfaceid = ntohl(*(int *)&opt->data); - vtag->v_tci = htons(interfaceid & 0xfff); /* use directly as VLAN */ - } - break; - case OPTION_RELAY_MSG: - /* sanity: never accept more than one of these! */ - if (datalen > 0) { - fprintf(stderr, "multiple OPTION_RELAY_MSG is not allowed!\n"); - } else { - /* save the lengh for later header fixups */ - datalen = ntohs(opt->len); - - /* copy the option data to our outgoing packet */ - memcpy(txbuf + PKTHDRZ + VLANTAGZ, &opt->data, datalen); - } - break; - default: - fprintf(stderr, "ignoring unknown relay option\n"); - } - opt = nextopt(opt); - } while ((char *)opt < (buf + len)); - - /* verify that we found an OPTION_RELAY_MSG */ - if (datalen == 0) { - fprintf(stderr, "couldn't find mandatory option OPTION_RELAY_MSG in packet - ignoring\n"); - continue; - } - /* verify that we found an OPTION_INTERFACE_ID */ - if (interfaceid == 0) { - fprintf(stderr, "couldn't find mandatory option OPTION_INTERFACE_ID in packet - ignoring\n"); - continue; - } - - /* fixup lengths and destination port */ - ip6->ip6_plen = htons(datalen + sizeof(struct udphdr)); - udp->len = ip6->ip6_plen; - udp->dest = htons(546); - - /* update UDP checksum */ - udp->check = htons(udp6chksum(ip6)); - - packetlen = sizeof(struct ethhdr) + VLANTAGZ + sizeof(struct ip6_hdr) + ntohs(udp->len); - fprintf(stderr, "packetlen=%d bytes\n", packetlen); - - /* finally: transmit the packet on the correct downstream interface */ - - /* packet(7): When you send packets it is enough to specify - sll_family, sll_addr, sll_halen, sll_ifindex. The other - fields should be 0. */ - - ll.sll_ifindex = idx_down; - - memcpy(&ll.sll_addr, ð->h_dest, ll.sll_halen); - ll.sll_protocol = 0; - ll.sll_hatype = 0; - ll.sll_pkttype = 0; - - fprintf(stderr, "sending %d bytes to %s on ifid=%d:\n", packetlen, macstr((char *)ll.sll_addr), ll.sll_ifindex); - print_hex(txbuf, packetlen); - - if (sendto(s, txbuf, packetlen, 0, (struct sockaddr *)&ll, sizeof(ll)) == -1) - fprintf(stderr, "sendto() failed: %m\n"); - - - - } else { - fprintf(stderr, "ignoring unknown interface=%d\n", ll.sll_ifindex); - continue; - } - - -/* - fprintf(stderr, "%s(): received %d bytes from address with len=%d on ifid=%d\n", - __FUNCTION__, len, ll.sll_halen, ll.sll_ifindex ); - print_mac((char *)ll.sll_addr); - fprintf(stderr,"\n"); - - print_hex(buf, len); -*/ /* TODO: verify that packet arrived on one of the interfaces we're wathcing, @@ -907,23 +654,3 @@ Steven McCanne and Van Jacobson of Lawrence Berkeley Laboratory. */ - -/* - eth = (struct ethhdr *)buf; - ip6 = (struct ip6_hdr *)(buf + sizeof(struct ethhdr)); - udp = (struct udphdr *)(buf + sizeof(struct ethhdr) + sizeof(struct ip6_hdr)); - dhcpv6 = (struct dhcpv6_relay_msg *)(buf + sizeof(struct ethhdr) + sizeof(struct ip6_hdr) + sizeof(struct udphdr)); - - fprintf(stderr,"eth.h_proto=%#06x, ll.sll_protocol=%#06x, ip6.ip6_plen=%hd, udp.len=%hd, dhcpv6.msg_type=%hhd\n", - ntohs(eth->h_proto), ntohs(ll.sll_protocol), ntohs(ip6->ip6_plen), ntohs(udp->len), dhcpv6->msg_type); - -*/ - - -} - - close(s); - return(0); -} - -#endif -- cgit v1.2.3