static void routing_less(struct pkt_buff *pkt)
{
	uint16_t hdr_ext_len;
	ssize_t data_len;
	struct routinghdr *routing;

	routing = (struct routinghdr *) pkt_pull(pkt, sizeof(*routing));
	if (routing == NULL)
		return;

	/* Total Header Length in Bytes */
	hdr_ext_len = (routing->h_hdr_ext_len + 1) * 8;
	/* Data length in Bytes */
	data_len = hdr_ext_len - sizeof(*routing);
	if (data_len > pkt_len(pkt) || data_len < 0)
		return;

	tprintf(" Routing ");
	
	switch (routing->h_routing_type) {
	case ROUTING_HEADER_TYPE_0:
		dissect_routinghdr_type_0_less(pkt, &data_len);
		break;
	default:
		tprintf("Type %u is unknown", routing->h_routing_type);
	}

	if (data_len > pkt_len(pkt) || data_len < 0)
		return;

	pkt_pull(pkt, data_len);
	pkt_set_proto(pkt, &eth_lay3, routing->h_next_header);
}
Beispiel #2
0
static int
vr_do_flow_action(struct vrouter *router, struct vr_flow_entry *fe,
        unsigned int index, struct vr_packet *pkt,
        unsigned short proto, struct vr_forwarding_md *fmd)
{
    uint32_t new_stats;

    new_stats = __sync_add_and_fetch(&fe->fe_stats.flow_bytes, pkt_len(pkt));
    if (new_stats < pkt_len(pkt))
        fe->fe_stats.flow_bytes_oflow++;

    new_stats = __sync_add_and_fetch(&fe->fe_stats.flow_packets, 1);
    if (!new_stats) 
        fe->fe_stats.flow_packets_oflow++;

    if (fe->fe_action == VR_FLOW_ACTION_HOLD) {
        if (vr_flow_queue_is_empty(router, fe)) {
            vr_trap_flow(router, fe, pkt, index);
            return vr_enqueue_flow(fe, pkt, proto, fmd);
        } else {
            vr_pfree(pkt, VP_DROP_FLOW_UNUSABLE);
            return 0;
        }
    }

    return vr_flow_action(router, fe, index, pkt, proto, fmd);
}
static void dissect_routinghdr_type_0(struct pkt_buff *pkt,
				      ssize_t *data_len, int less)
{
	uint8_t num_addr;
	char address[INET6_ADDRSTRLEN];
	struct in6_addr *addr;
	struct routinghdr_0 *routing_0;

  	routing_0 = (struct routinghdr_0 *) pkt_pull(pkt, sizeof(*routing_0));
	*data_len -= sizeof(*routing_0);
	if (routing_0 == NULL || *data_len > pkt_len(pkt) || *data_len < 0)
		return;

	if (less) {
		tprintf("Addresses (%lu)", *data_len / sizeof(struct in6_addr));
		return;
	}

	tprintf("Res (0x%x)", routing_0->reserved);

	num_addr = *data_len / sizeof(*addr);

	while (num_addr--) {
		addr = (struct in6_addr *) pkt_pull(pkt, sizeof(*addr));
		*data_len -= sizeof(*addr);
		if (addr == NULL || *data_len > pkt_len(pkt) || *data_len < 0)
			return;

		tprintf("\n\t   Address: %s",
			inet_ntop(AF_INET6, addr, address,
				  sizeof(address)));
	}
}
Beispiel #4
0
static void ipv4_less(struct pkt_buff *pkt)
{
	char src_ip[INET_ADDRSTRLEN];
	char dst_ip[INET_ADDRSTRLEN];
	struct ipv4hdr *ip = (struct ipv4hdr *) pkt_pull(pkt, sizeof(*ip));

	if (!ip)
		return;

	inet_ntop(AF_INET, &ip->h_saddr, src_ip, sizeof(src_ip));
	inet_ntop(AF_INET, &ip->h_daddr, dst_ip, sizeof(dst_ip));

	tprintf(" %s/%s Len %u", src_ip, dst_ip,
		ntohs(ip->h_tot_len));

	/* cut off IP options and everything that is not part of IPv4 payload */
	pkt_pull(pkt, max((uint8_t) ip->h_ihl, sizeof(*ip) / sizeof(uint32_t))
		* sizeof(uint32_t) - sizeof(*ip));
	/* XXX there coul still be an Ethernet trailer included or others */
#if 0
	pkt_trim(pkt, pkt_len(pkt) - min(pkt_len(pkt),
		 (ntohs(ip->h_tot_len) - ip->h_ihl * sizeof(uint32_t))));
#endif
	pkt_set_proto(pkt, &eth_lay3, ip->h_protocol);
}
static void hop_by_hop(struct pkt_buff *pkt)
{
	uint16_t hdr_ext_len;
	ssize_t opt_len;
	struct hop_by_hophdr *hop_ops;

	hop_ops = (struct hop_by_hophdr *) pkt_pull(pkt, sizeof(*hop_ops));
	if (hop_ops == NULL)
		return;

	/* Total Header Length in Bytes */
	hdr_ext_len = (hop_ops->hdr_len + 1) * 8;
	/* Options length in Bytes */
	opt_len = hdr_ext_len - sizeof(*hop_ops);

	tprintf("\t [ Hop-by-Hop Options ");
	tprintf("NextHdr (%u), ", hop_ops->h_next_header);
	if (opt_len > pkt_len(pkt) || opt_len < 0){
		tprintf("HdrExtLen (%u, %u Bytes, %s)", hop_ops->hdr_len,
		      hdr_ext_len, colorize_start_full(black, red)
		      "invalid" colorize_end());
		      return;
	}
	tprintf("HdrExtLen (%u, %u Bytes)", hop_ops->hdr_len,
		hdr_ext_len);

	dissect_opt_hop(pkt, &opt_len);

	tprintf(" ]\n");

	pkt_pull(pkt, opt_len);
	pkt_set_proto(pkt, &eth_lay3, hop_ops->h_next_header);
}
static int
linux_if_rx(struct vr_interface *vif, struct vr_packet *pkt)
{
    int rc;
    struct net_device *dev = (struct net_device *)vif->vif_os;
    struct sk_buff *skb = vp_os_packet(pkt);
    struct vr_ip *ip;
    unsigned short network_off, transport_off, cksum_off = 0;

    skb->data = pkt->vp_head + pkt->vp_data;
    skb->len = pkt_len(pkt);
    skb_set_tail_pointer(skb, pkt_head_len(pkt));

    if (!dev) {
        kfree_skb(skb);
        goto exit_rx;
    }

    (void)__sync_fetch_and_add(&dev->stats.rx_bytes, skb->len);
    (void)__sync_fetch_and_add(&dev->stats.rx_packets, 1);

    /* this is only needed for mirroring */
    if ((pkt->vp_flags & VP_FLAG_FROM_DP) &&
            (pkt->vp_flags & VP_FLAG_CSUM_PARTIAL)) {
    	network_off = pkt_get_network_header_off(pkt);
    	ip = (struct vr_ip *)(pkt_data_at_offset(pkt, network_off));
    	transport_off = network_off + (ip->ip_hl * 4);

        if (ip->ip_proto == VR_IP_PROTO_TCP)
            cksum_off = offsetof(struct vr_tcp, tcp_csum);
        else if (ip->ip_proto == VR_IP_PROTO_UDP)
Beispiel #7
0
static void nlmsg(struct pkt_buff *pkt)
{
	struct nlmsghdr *hdr = (struct nlmsghdr *) pkt_pull(pkt, NLMSG_HDRLEN);
	unsigned int trim_len = pkt_len(pkt);

	while (hdr) {
		trim_len -= hdr->nlmsg_len;
		nlmsg_print(ntohs(pkt->sll->sll_protocol), hdr);

		if (!pkt_pull(pkt, NLMSG_ALIGN(hdr->nlmsg_len) - NLMSG_HDRLEN))
			break;

		hdr = (struct nlmsghdr *) pkt_pull(pkt, NLMSG_HDRLEN);
		if (hdr == NULL)
			break;
		if (hdr->nlmsg_len == 0)
			break;

		if (hdr->nlmsg_type != NLMSG_DONE &&
		    (hdr->nlmsg_flags & NLM_F_MULTI))
			tprintf("\n");
	}

	/* mmaped packet? */
	if (hdr && hdr->nlmsg_len == 0)
		pkt_trim(pkt, trim_len);
}
Beispiel #8
0
static int
eth_tx(struct vr_interface *vif, struct vr_packet *pkt)
{
    int ret;
    struct vr_forwarding_md fmd;
    struct vr_interface_stats *stats = vif_get_stats(vif, pkt->vp_cpu);

    /*
     * GRO packets come here twice - once with VP_FLAG_GRO set and
     * once without the flag set. Don't count them twice.
     */
    if (((pkt->vp_flags & VP_FLAG_GRO) == 0) ||
             (vif->vif_type != VIF_TYPE_VIRTUAL)) {
        stats->vis_obytes += pkt_len(pkt);
        stats->vis_opackets++;
    }
    if (vif->vif_flags & VIF_FLAG_MIRROR_TX) {
        vr_init_forwarding_md(&fmd);
        fmd.fmd_dvrf = vif->vif_vrf;
        vr_mirror(vif->vif_router, vif->vif_mirror_id, pkt, &fmd);
    }
        
    ret = hif_ops->hif_tx(vif, pkt);
    if (ret != 0) {
        ret = 0;
        stats->vis_oerrors++;
    }

    return ret;
}
Beispiel #9
0
static struct pkt0_packet *
alloc_pkt0_packet(struct vr_packet *vrp)
{
    struct pkt0_packet *packet;
    unsigned int pkt_size = pkt_len(vrp);
    int ret;

    packet = ExAllocatePoolWithTag(NonPagedPoolNx, sizeof(struct pkt0_packet), pkt0_allocation_tag);
    if (packet == NULL)
        return NULL;
    RtlZeroMemory(packet, sizeof(*packet));

    packet->buffer = ExAllocatePoolWithTag(NonPagedPoolNx, pkt_size, pkt0_allocation_tag);
    if (packet->buffer == NULL)
        goto failure;
    RtlZeroMemory(packet->buffer, pkt_size);

    ret = vr_pcopy(packet->buffer, vrp, vrp->vp_data, pkt_size);
    if (ret != pkt_size) {
        goto failure;
    }
    packet->length = ret;

    return packet;

failure:
    if (packet)
        free_pkt0_packet(packet);

    return NULL;
}
static void dissect_igmp_v2(struct pkt_buff *pkt)
{
	char     addr[INET_ADDRSTRLEN];
	uint16_t csum;

	struct igmp_v2_msg *msg =
		(struct igmp_v2_msg *) pkt_pull(pkt, sizeof(*msg));

	if (msg == NULL)
		return;

	switch (msg->type) {
	case RGMP_HELLO:
	case RGMP_BYE:
	case RGMP_JOIN_GROUP:
	case RGMP_LEAVE_GROUP:
		tprintf(" [ IGMPv2 (RGMP)");
		break;
	default:
		tprintf(" [ IGMPv2");
		break;
	}

	PRINT_FRIENDLY_NAMED_MSG_TYPE(msg->type);
	tprintf(", Max Resp Time (%u)", msg->max_resp_time);
	csum = calc_csum(msg, sizeof(*msg) + pkt_len(pkt), 0);
	tprintf(", CSum (0x%.4x) is %s", ntohs(msg->checksum), csum ?
		colorize_start_full(black, red) "bogus (!)" colorize_end() : "ok");
	if (csum)
		tprintf(" - %s should be %x%s", colorize_start_full(black, red),
			csum_expected(msg->checksum, csum), colorize_end());
	inet_ntop(AF_INET, &msg->group_address, addr, sizeof(addr));
	tprintf(", Group Addr (%s)", addr);
	tprintf(" ]\n");
}
static void auth_hdr(struct pkt_buff *pkt)
{
	ssize_t hdr_len;
	struct auth_hdr *auth_ops;

	auth_ops = (struct auth_hdr *) pkt_pull(pkt, sizeof(*auth_ops));
	if (auth_ops == NULL)
		return;
	
	hdr_len = (auth_ops->h_payload_len * 4) + 8;

	tprintf(" [ Authentication Header ");
	tprintf("NextHdr (%u), ", auth_ops->h_next_header);
	if (hdr_len > pkt_len(pkt) || hdr_len < 0){
		tprintf("HdrLen (%u, %zd Bytes %s), ",
		      auth_ops->h_payload_len, hdr_len,
		      colorize_start_full(black, red)
		      "invalid" colorize_end());
		      return;
	}
	tprintf("HdrLen (%u, %zd Bytes), ",auth_ops->h_payload_len, hdr_len);
	tprintf("Reserved (0x%x), ", ntohs(auth_ops->h_reserved));
	/* TODO
	 * Upgrade for Extended (64-bit) Sequence Number
	 * http://tools.ietf.org/html/rfc4302#section-2.5.1
	 */
	tprintf("SPI (0x%x), ", ntohl(auth_ops->h_spi));
	tprintf("SNF (0x%x), ", ntohl(auth_ops->h_snf));
	tprintf("ICV 0x");
	for (size_t i = sizeof(struct auth_hdr); i < hdr_len; i++)
		tprintf("%02x", *pkt_pull(pkt, 1));
	tprintf(" ]\n");

	pkt_set_proto(pkt, &eth_lay3, auth_ops->h_next_header);
}
Beispiel #12
0
static int whine_if_too_big(struct packet *in, struct packet *out)
{
	unsigned int len;
	unsigned int mtu;

	if (pkt_l3_proto(in) == L3PROTO_IPV4 && !is_dont_fragment_set(pkt_ip4_hdr(in)))
		return 0;

	len = pkt_len(out);
	mtu = get_nexthop_mtu(out);
	if (len > mtu) {
		/*
		 * We don't have to worry about ICMP errors causing this because the translate code already
		 * truncates them.
		 */
		log_debug("Packet is too big (len: %u, mtu: %u).", len, mtu);

		switch (pkt_l3_proto(out)) {
		case L3PROTO_IPV6:
			mtu -= 20;
			break;
		case L3PROTO_IPV4:
			mtu += 20;
			break;
		}
		icmp64_send(out, ICMPERR_FRAG_NEEDED, mtu);

		return -EINVAL;
	}

	return 0;
}
static void igmp_less(struct pkt_buff *pkt)
{
	int version = -1;

	switch (*pkt_peek(pkt)) {
	case IGMP_V0_CREATE_GROUP_REQUEST:
	case IGMP_V0_CREATE_GROUP_REPLY:
	case IGMP_V0_JOIN_GROUP_REQUEST:
	case IGMP_V0_JOIN_GROUP_REPLY:
	case IGMP_V0_LEAVE_GROUP_REQUEST:
	case IGMP_V0_LEAVE_GROUP_REPLY:
	case IGMP_V0_CONFIRM_GROUP_REQUEST:
	case IGMP_V0_CONFIRM_GROUP_REPLY:
		if (pkt_len(pkt) == sizeof(struct igmp_v0_msg))
			version = 0;
		break;
	case IGMP_MEMBERSHIP_QUERY: /* v1/v2/v3 */
		if (pkt_len(pkt) >= sizeof(struct igmp_v3_membership_query))
			version = 3;
		else if (pkt_len(pkt) == sizeof(struct igmp_v2_msg)
			&& *(pkt_peek(pkt) + 1))
			version = 2;
		else if (pkt_len(pkt) == sizeof(struct igmp_v1_msg))
			version = 1;
		break;
	case IGMP_V1_MEMBERSHIP_REPORT:
		if (pkt_len(pkt) == sizeof(struct igmp_v1_msg))
			version = 1;
		break;
	case RGMP_HELLO:
	case RGMP_BYE:
	case RGMP_JOIN_GROUP:
	case RGMP_LEAVE_GROUP:
	case IGMP_V2_MEMBERSHIP_REPORT:
	case IGMP_V2_LEAVE_GROUP:
		if (pkt_len(pkt) == sizeof(struct igmp_v2_msg))
			version = 2;
		break;
	case IGMP_V3_MEMBERSHIP_REPORT:
		if (pkt_len(pkt) >= sizeof(struct igmp_v3_membership_report))
			version = 3;
		break;
	}

	if (version < 0 || version > 3)
		return;

	switch (*pkt_peek(pkt)) {
	case RGMP_HELLO:
	case RGMP_BYE:
	case RGMP_JOIN_GROUP:
	case RGMP_LEAVE_GROUP:
		tprintf(" IGMPv2 (RGMP)");
		break;
	default:
		tprintf(" IGMPv%u", version);
		break;
	}
	PRINT_FRIENDLY_NAMED_MSG_TYPE(*pkt_peek(pkt));
}
static void routing(struct pkt_buff *pkt)
{
	uint16_t hdr_ext_len;
	ssize_t data_len;
	struct routinghdr *routing;

	routing = (struct routinghdr *) pkt_pull(pkt, sizeof(*routing));
	if (routing == NULL)
		return;

	/* Total Header Length in Bytes */
	hdr_ext_len = (routing->h_hdr_ext_len + 1) * 8;
	/* Data length in Bytes */
	data_len = hdr_ext_len - sizeof(*routing);

	tprintf("\t [ Routing ");
	tprintf("NextHdr (%u), ", routing->h_next_header);
	if (data_len > pkt_len(pkt) || data_len < 0){
		tprintf("HdrExtLen (%u, %u Bytes %s), ", routing->h_hdr_ext_len,
		      hdr_ext_len, colorize_start_full(black, red)
		      "invalid" colorize_end());
		      return;
	}
	tprintf("HdrExtLen (%u, %u Bytes), ", routing->h_hdr_ext_len,
		hdr_ext_len);
	tprintf("Type (%u), ", routing->h_routing_type);
	tprintf("Left (%u), ", routing->h_segments_left);

	switch (routing->h_routing_type) {
	case ROUTING_HEADER_TYPE_0:
		dissect_routinghdr_type_0_norm(pkt, &data_len);
		break;
	default:
		tprintf("Type %u is unknown", routing->h_routing_type);
	}

	tprintf(" ]\n");

	if (data_len > pkt_len(pkt) || data_len < 0)
		return;

	pkt_pull(pkt, data_len);
	pkt_set_proto(pkt, &eth_lay3, routing->h_next_header);
}
Beispiel #15
0
void ascii(struct pkt_buff *pkt)
{
	size_t len = pkt_len(pkt);

	if (!len)
		return;

	_ascii(pkt_pull(pkt, len), len);
	tprintf("\n");
}
static int
agent_rx(struct vr_interface *vif, struct vr_packet *pkt,
        unsigned short vlan_id __attribute__((unused)))
{
    struct agent_hdr *hdr;
    struct vr_interface *agent_vif;
    struct vr_interface_stats *stats = vif_get_stats(vif, pkt->vp_cpu);

    stats->vis_ibytes += pkt_len(pkt);
    stats->vis_ipackets++;

    hdr = (struct agent_hdr *)pkt_pull(pkt, sizeof(struct vr_eth));
    if (!hdr || !pkt_pull(pkt, sizeof(*hdr))) {
        stats->vis_ierrors++;
        vr_pfree(pkt, VP_DROP_PULL);
        return 0;
    }

    /*
     * Update the original (OS visible) packet to point to the
     * l2 header of the injected packet
     */
    vr_pset_data(pkt, pkt->vp_data);
    if (ntohs(hdr->hdr_cmd) & AGENT_CMD_ROUTE) {
        /*
         * XXX 
         * Packet with command "route" from agent may 
         * result in flow setup, this breaks the 
         * assumption that all packets for a flow will
         * reach same CPU. Need a better way to handle this
         */
        agent_vif = __vrouter_get_interface(vrouter_get(0), 
                                            ntohs(hdr->hdr_ifindex));
        if (!agent_vif) {
            agent_vif = vif;
        }
        pkt->vp_if = agent_vif;
        vr_interface_input(ntohs(hdr->hdr_vrf), agent_vif, pkt, VLAN_ID_INVALID);
    } else {
        vif = __vrouter_get_interface(vrouter_get(0), ntohs(hdr->hdr_ifindex));
        if (!vif) {
            stats->vis_ierrors++;
            vr_pfree(pkt, VP_DROP_INVALID_IF);
            return 0;
        }

        pkt->vp_type = VP_TYPE_AGENT;
        pkt_set_network_header(pkt, pkt->vp_data + sizeof(struct vr_eth));
        pkt_set_inner_network_header(pkt, 
                                     pkt->vp_data + sizeof(struct vr_eth));
        return vif->vif_tx(vif, pkt);
    }

    return 0;
}
Beispiel #17
0
void hex_ascii(struct pkt_buff *pkt)
{
	size_t   len = pkt_len(pkt);
	uint8_t *ptr = pkt_pull(pkt, len);

	if (len) {
		_ascii(ptr, len);
		_hex(ptr, len);
	}

	tprintf("\n");
}
static void dissect_igmp_v3_membership_query(struct pkt_buff *pkt)
{
	char      addr[INET_ADDRSTRLEN];
	size_t    n;
	uint16_t  csum;
	uint32_t *src_addr;

	struct igmp_v3_membership_query *msg =
		(struct igmp_v3_membership_query *) pkt_pull(pkt, sizeof(*msg));

	if (msg == NULL)
		return;

	tprintf(" [ IGMPv3");
	PRINT_FRIENDLY_NAMED_MSG_TYPE(msg->type);
	tprintf(", Max Resp Code (0x%.2x => %u)", msg->max_resp_code,
		DECODE_MAX_RESP_CODE(msg->max_resp_code));
	csum = calc_csum(msg, sizeof(*msg) + pkt_len(pkt), 0);
	tprintf(", CSum (0x%.4x) is %s", ntohs(msg->checksum), csum ?
		colorize_start_full(black, red) "bogus (!)" colorize_end() : "ok");
	if (csum)
		tprintf(" - %s should be %x%s", colorize_start_full(black, red),
			csum_expected(msg->checksum, csum), colorize_end());
	inet_ntop(AF_INET, &msg->group_address, addr, sizeof(addr));
	/* S Flag (Suppress Router-Side Processing) */
	tprintf(", Suppress (%u)", msg->s_flag ? 1 : 0);
	/* QRV (Querier's Robustness Variable) */
	tprintf(", QRV (%u)", msg->qrv);
	/* QQIC (Querier's Query Interval Code) */
	tprintf(", QQIC (0x%.2x => %u)", msg->qqic, DECODE_QQIC(msg->qqic));
	tprintf(", Group Addr (%s)", addr);
	n = ntohs(msg->number_of_sources);
	tprintf(", Num Src (%zu)", n);

	if (n--) {
		src_addr = (uint32_t *) pkt_pull(pkt, sizeof(*src_addr));
		if (src_addr != NULL) {
			inet_ntop(AF_INET, src_addr, addr, sizeof(addr));
			tprintf(", Src Addr (%s", addr);
			while (n--) {
				src_addr = (uint32_t *)
					pkt_pull(pkt, sizeof(*src_addr));
				if (src_addr == NULL)
					break;
				inet_ntop(AF_INET, src_addr, addr, sizeof(addr));
				tprintf(", %s", addr);
			}
			tprintf(")");
		}
	}
	tprintf(" ]\n");
}
static void dissect_mobilityhdr_type_0(struct pkt_buff *pkt,
				       ssize_t *message_data_len)
{
	struct bin_refr_req_msg *type_0;
	
	type_0 = (struct bin_refr_req_msg *) pkt_pull(pkt, sizeof(*type_0));
	*message_data_len -= sizeof(*type_0);
	if (type_0 == NULL || *message_data_len > pkt_len(pkt) ||
							*message_data_len < 0)
		return;

	dissect_mobility_options(pkt, message_data_len);
}
Beispiel #20
0
static flow_result_t
vr_do_flow_action(struct vrouter *router, struct vr_flow_entry *fe,
        unsigned int index, struct vr_packet *pkt,
        struct vr_forwarding_md *fmd)
{
    uint32_t new_stats;

    new_stats = __sync_add_and_fetch(&fe->fe_stats.flow_bytes, pkt_len(pkt));
    if (new_stats < pkt_len(pkt))
        fe->fe_stats.flow_bytes_oflow++;

    new_stats = __sync_add_and_fetch(&fe->fe_stats.flow_packets, 1);
    if (!new_stats)
        fe->fe_stats.flow_packets_oflow++;

    if (fe->fe_action == VR_FLOW_ACTION_HOLD) {
        vr_enqueue_flow(router, fe, pkt, index, fmd);
        return FLOW_HELD;
    }

    return vr_flow_action(router, fe, index, pkt, fmd);
}
static void mobility(struct pkt_buff *pkt)
{
	uint16_t hdr_ext_len;
	ssize_t message_data_len;
	struct mobilityhdr *mobility;

	mobility = (struct mobilityhdr *) pkt_pull(pkt, sizeof(*mobility));
	if (mobility == NULL)
		return;

	/* Total Header Length in Bytes */
	hdr_ext_len = (mobility->hdr_len + 1) * 8;
	/* Total Message Data length in Bytes*/
	message_data_len = (hdr_ext_len - sizeof(*mobility));

	tprintf("\t [ Mobility ");
	tprintf("NextHdr (%u), ", mobility->payload_proto);
	if (message_data_len > pkt_len(pkt) || message_data_len < 0){
		tprintf("HdrExtLen (%u, %u Bytes %s), ", mobility->hdr_len,
				hdr_ext_len, colorize_start_full(black, red)
				"invalid" colorize_end());
		return;
	}
	tprintf("HdrExtLen (%u, %u Bytes), ", mobility->hdr_len,
		hdr_ext_len);
	tprintf("MH Type (%u), ", mobility->MH_type);
	tprintf("Res (0x%x), ", mobility->reserved);
	tprintf("Chks (0x%x), ", ntohs(mobility->chksum));
	tprintf("MH Data ");

	get_mh_type(pkt, &message_data_len, &mobility->MH_type);

	tprintf(" ]\n");

	if (message_data_len > pkt_len(pkt) || message_data_len < 0)
		return;
	pkt_pull(pkt, message_data_len);
	pkt_set_proto(pkt, &eth_lay3, mobility->payload_proto);
}
Beispiel #22
0
/* vhost driver */
static int
vhost_rx(struct vr_interface *vif, struct vr_packet *pkt,
        unsigned short vlan_id __attribute__((unused)))
{
    struct vr_interface_stats *stats = vif_get_stats(vif, pkt->vp_cpu);

    stats->vis_ibytes += pkt_len(pkt);
    stats->vis_ipackets++;

    /* please see the text on xconnect mode */
    if (vif_mode_xconnect(vif))
        return vif_xconnect(vif, pkt);

    return vr_input(vif->vif_vrf, vif, pkt);
}
static void dissect_mobilityhdr_type_1_2(struct pkt_buff *pkt,
					 ssize_t *message_data_len)
{
	struct tst_init_msg *type_1_2;

	type_1_2 = (struct tst_init_msg *) pkt_pull(pkt, sizeof(*type_1_2));
	*message_data_len -= sizeof(*type_1_2);
	if (type_1_2 == NULL || *message_data_len > pkt_len(pkt) ||
							*message_data_len < 0)
		return;

	tprintf("Init Cookie (0x%x)", ntohll(type_1_2->init_cookie));

	dissect_mobility_options(pkt, message_data_len);
}
static void dissect_mobilityhdr_type_5(struct pkt_buff *pkt,
				       ssize_t *message_data_len)
{
	struct bind_upd_msg *type_5;

	type_5 = (struct bind_upd_msg *) pkt_pull(pkt, sizeof(*type_5));
	*message_data_len -= sizeof(*type_5);
	if (type_5 == NULL || *message_data_len > pkt_len(pkt) ||
							*message_data_len < 0)
		return;

	tprintf("Sequence (0x%x) ", ntohs(type_5->sequence));
	tprintf("A|H|L|K (0x%x) ", ntohs(type_5->ahlk_res) >> 12);
	tprintf("Lifetime (%us)", ntohs(type_5->lifetime) * 4);

	dissect_mobility_options(pkt, message_data_len);
}
Beispiel #25
0
/* eth driver */
static int
eth_srx(struct vr_interface *vif, struct vr_packet *pkt,
        unsigned short vlan_id)
{
    unsigned short vrf;
    struct vr_interface_stats *stats = vif_get_stats(vif, pkt->vp_cpu);

    stats->vis_ibytes += pkt_len(pkt);
    stats->vis_ipackets++;

    if (vlan_id >= VIF_VRF_TABLE_ENTRIES)
        vrf = vif->vif_vrf;
    else
        vrf = vif->vif_vrf_table[vlan_id];

    return vr_input(vrf, vif, pkt);
}
Beispiel #26
0
static int
agent_tx(struct vr_interface *vif, struct vr_packet *pkt)
{
    int ret;
    struct vr_interface_stats *stats = vif_get_stats(vif, pkt->vp_cpu);

    stats->vis_obytes += pkt_len(pkt);
    stats->vis_opackets++;

    ret = hif_ops->hif_tx(vif, pkt);
    if (ret != 0) {
        ret = 0;
        stats->vis_oerrors++;
    }

    return ret;
}
static void dissect_mobilityhdr_type_3_4(struct pkt_buff *pkt,
					 ssize_t *message_data_len)
{
	struct tst_msg *type_3_4;

	type_3_4 = (struct tst_msg *) pkt_pull(pkt, sizeof(*type_3_4));
	*message_data_len -= sizeof(*type_3_4);
	if (type_3_4 == NULL || *message_data_len > pkt_len(pkt) ||
							*message_data_len < 0)
		return;

	tprintf("HN Index (%u) ", ntohs(type_3_4->nonce_index));
	tprintf("Init Cookie (0x%x) ", ntohll(type_3_4->init_cookie));
	tprintf("Keygen Token (0x%x)", ntohll(type_3_4->keygen_token));

	dissect_mobility_options(pkt, message_data_len);
}
static void dissect_mobilityhdr_type_6(struct pkt_buff *pkt,
				       ssize_t *message_data_len)
{
	struct bind_ack_msg *type_6;

	type_6 = (struct bind_ack_msg *) pkt_pull(pkt, sizeof(*type_6));
	*message_data_len -= sizeof(*type_6);
	if (type_6 == NULL || *message_data_len > pkt_len(pkt) ||
							*message_data_len < 0)
		return;

	tprintf("Status (0x%x) ", type_6->status);
	tprintf("K (%u) ", type_6->k_res >> 7);
	tprintf("Sequence (0x%x)", ntohs(type_6->sequence));
	tprintf("Lifetime (%us)", ntohs(type_6->lifetime) * 4);

	dissect_mobility_options(pkt, message_data_len);
}
static void auth_hdr_less(struct pkt_buff *pkt)
{
  	ssize_t hdr_len;
	struct auth_hdr *auth_ops;

	auth_ops = (struct auth_hdr *) pkt_pull(pkt, sizeof(*auth_ops));
	if (auth_ops == NULL)
		return;

	hdr_len = (auth_ops->h_payload_len * 4) + 8;
	if (hdr_len > pkt_len(pkt) || hdr_len < 0)
		return;

	tprintf(" AH");

	pkt_pull(pkt, hdr_len - sizeof(*auth_ops));
	pkt_set_dissector(pkt, &eth_lay3, auth_ops->h_next_header);
}
Beispiel #30
0
static int
vhost_tx(struct vr_interface *vif, struct vr_packet *pkt)
{
    int ret;
    struct vr_interface_stats *stats = vif_get_stats(vif, pkt->vp_cpu);

    stats->vis_obytes += pkt_len(pkt);
    stats->vis_opackets++;

    if (vif->vif_type == VIF_TYPE_XEN_LL_HOST)
        memcpy(pkt_data(pkt), vif->vif_mac, sizeof(vif->vif_mac));

    ret = hif_ops->hif_rx(vif, pkt);
    if (ret < 0) {
        ret = 0;
        stats->vis_oerrors++;
    }

    return ret;
}