Example #1
0
static void print(const struct ebt_u_entry *entry,
                  const struct ebt_entry_match *match)
{
    struct ebt_vlan_info *vlaninfo = (struct ebt_vlan_info *) match->data;

    if (vlaninfo->bitmask & EBT_VLAN_ID) {
#if 1  /*Rodney_20090724*/
        printf("--vlan-id ");
        if (vlaninfo->invflags & EBT_VLAN_ID)
            printf("! ");
        print_id_range(vlaninfo->id);
#else
        printf("--vlan-id %s%d ", (vlaninfo->invflags & EBT_VLAN_ID) ? "! " : "", vlaninfo->id);
#endif
    }
    if (vlaninfo->bitmask & EBT_VLAN_PRIO) {
#if 1  /*Rodney_20090724*/
        printf("--vlan-prio ");
        if (vlaninfo->invflags & EBT_VLAN_PRIO)
            printf("! ");
        print_prio_range(vlaninfo->prio);
#else
        printf("--vlan-prio %s%d ", (vlaninfo->invflags & EBT_VLAN_PRIO) ? "! " : "", vlaninfo->prio);
#endif
    }
    if (vlaninfo->bitmask & EBT_VLAN_ENCAP) {
        printf("--vlan-encap %s", (vlaninfo->invflags & EBT_VLAN_ENCAP) ? "! " : "");
        ethent = getethertypebynumber(ntohs(vlaninfo->encap));
        if (ethent != NULL) {
            printf("%s ", ethent->e_name);
        } else {
            printf("%4.4X ", ntohs(vlaninfo->encap));
        }
    }
}
struct ethertypeent *parseethertypebynumber(int type)
{
	if (type < 1536)
		ebt_print_error("Ethernet protocols have values >= 0x0600");
	if (type > 0xffff)
		ebt_print_error("Ethernet protocols have values <= 0xffff");
	return getethertypebynumber(type);
}
Example #3
0
static void print(const struct ebt_u_entry *entry,
   const struct ebt_entry_match *match)
{
	struct ebt_arp_info *arpinfo = (struct ebt_arp_info *)match->data;
	int i;

	if (arpinfo->bitmask & EBT_ARP_OPCODE) {
		int opcode = ntohs(arpinfo->opcode);
		printf("--arp-op ");
		if (arpinfo->invflags & EBT_ARP_OPCODE)
			printf("! ");
		if (opcode > 0 && opcode <= NUMOPCODES)
			printf("%s ", opcodes[opcode - 1]);
		else
			printf("%d ", opcode);
	}
	if (arpinfo->bitmask & EBT_ARP_HTYPE) {
		printf("--arp-htype ");
		if (arpinfo->invflags & EBT_ARP_HTYPE)
			printf("! ");
		printf("%d ", ntohs(arpinfo->htype));
	}
	if (arpinfo->bitmask & EBT_ARP_PTYPE) {
		struct ethertypeent *ent;

		printf("--arp-ptype ");
		if (arpinfo->invflags & EBT_ARP_PTYPE)
			printf("! ");
		ent = getethertypebynumber(ntohs(arpinfo->ptype));
		if (!ent)
			printf("0x%x ", ntohs(arpinfo->ptype));
		else
			printf("%s ", ent->e_name);
	}
	if (arpinfo->bitmask & EBT_ARP_SRC_IP) {
		printf("--arp-ip-src ");
		if (arpinfo->invflags & EBT_ARP_SRC_IP)
			printf("! ");
		for (i = 0; i < 4; i++)
			printf("%d%s", ((unsigned char *)&arpinfo->saddr)[i],
			   (i == 3) ? "" : ".");
		printf("%s ", ebt_mask_to_dotted(arpinfo->smsk));
	}
	if (arpinfo->bitmask & EBT_ARP_DST_IP) {
		printf("--arp-ip-dst ");
		if (arpinfo->invflags & EBT_ARP_DST_IP)
			printf("! ");
		for (i = 0; i < 4; i++)
			printf("%d%s", ((unsigned char *)&arpinfo->daddr)[i],
			   (i == 3) ? "" : ".");
		printf("%s ", ebt_mask_to_dotted(arpinfo->dmsk));
	}
	if (arpinfo->bitmask & EBT_ARP_SRC_MAC) {
		printf("--arp-mac-src ");
		if (arpinfo->invflags & EBT_ARP_SRC_MAC)
			printf("! ");
		ebt_print_mac_and_mask(arpinfo->smaddr, arpinfo->smmsk);
		printf(" ");
	}
	if (arpinfo->bitmask & EBT_ARP_DST_MAC) {
		printf("--arp-mac-dst ");
		if (arpinfo->invflags & EBT_ARP_DST_MAC)
			printf("! ");
		ebt_print_mac_and_mask(arpinfo->dmaddr, arpinfo->dmmsk);
		printf(" ");
	}
	if (arpinfo->bitmask & EBT_ARP_GRAT) {
		if (arpinfo->invflags & EBT_ARP_GRAT)
			printf("! ");
		printf("--arp-gratuitous ");
	}
}
Example #4
0
/* Helper function for list_rules() */
static void list_em(struct ebt_u_entries *entries)
{
	int i;
	struct ebt_u_entry *hlp;
	struct ebt_u_match_list *m_l;
	struct ebt_u_match *m;
	struct ebt_u_target *t;

	hlp = entries->entries->next;
	printf("\nBridge chain: %s, entries: %d, policy: %s\n",
	   entries->name, entries->nentries,
	   ebt_standard_targets[-entries->policy - 1]);

	for (i = 0; i < entries->nentries; i++) {
		/* The standard target's print() uses this to find out
		 * the name of a udc */
		hlp->replace = replace;

		/* Don't print anything about the protocol if no protocol was
		 * specified, obviously this means any protocol will do. */
		if (!(hlp->bitmask & EBT_NOPROTO)) {
			printf("-p ");
			if (hlp->invflags & EBT_IPROTO)
				printf("! ");
			if (hlp->bitmask & EBT_802_3)
				printf("Length ");
			else {
				const struct ethertypeent *ent;

				ent = getethertypebynumber(ntohs(hlp->ethproto));
				if (!ent)
					printf("0x%x ", ntohs(hlp->ethproto));
				else
					printf("%s ", ent->e_name);
			}
		}
		if (hlp->bitmask & EBT_SOURCEMAC) {
			printf("-s ");
			if (hlp->invflags & EBT_ISOURCE)
				printf("! ");
			ebt_print_mac_and_mask(hlp->sourcemac, hlp->sourcemsk);
			printf(" ");
		}
		if (hlp->bitmask & EBT_DESTMAC) {
			printf("-d ");
			if (hlp->invflags & EBT_IDEST)
				printf("! ");
			ebt_print_mac_and_mask(hlp->destmac, hlp->destmsk);
			printf(" ");
		}
		if (hlp->in[0] != '\0') {
			printf("-i ");
			if (hlp->invflags & EBT_IIN)
				printf("! ");
			print_iface(hlp->in);
		}
		if (hlp->logical_in[0] != '\0') {
			printf("--logical-in ");
			if (hlp->invflags & EBT_ILOGICALIN)
				printf("! ");
			print_iface(hlp->logical_in);
		}
		if (hlp->logical_out[0] != '\0') {
			printf("--logical-out ");
			if (hlp->invflags & EBT_ILOGICALOUT)
				printf("! ");
			print_iface(hlp->logical_out);
		}
		if (hlp->out[0] != '\0') {
			printf("-o ");
			if (hlp->invflags & EBT_IOUT)
				printf("! ");
			print_iface(hlp->out);
		}

		m_l = hlp->m_list;
		while (m_l) {
			m = ebt_find_match(m_l->m->u.name);
			if (!m)
				ebt_print_bug("Match not found");
			m->print(hlp, m_l->m);
			m_l = m_l->next;
		}

		printf("-j ");
		if (strcmp(hlp->t->u.name, EBT_STANDARD_TARGET))
			printf("%s ", hlp->t->u.name);
		t = ebt_find_target(hlp->t->u.name);
		if (!t)
			ebt_print_bug("Target '%s' not found", hlp->t->u.name);
		t->print(hlp, hlp->t);
		printf("\n");
		hlp = hlp->next;
	}
}
/* Helper function for list_rules() */
static void list_em(struct ebt_u_entries *entries)
{
	int i, j, space = 0, digits;
	struct ebt_u_entry *hlp;
	struct ebt_u_match_list *m_l;
	struct ebt_u_watcher_list *w_l;
	struct ebt_u_match *m;
	struct ebt_u_watcher *w;
	struct ebt_u_target *t;

	if (replace->flags & LIST_MAC2)
		ebt_printstyle_mac = 2;
	else
		ebt_printstyle_mac = 0;
	hlp = entries->entries->next;
	if (replace->flags & LIST_X && entries->policy != EBT_ACCEPT) {
		printf("ebtables -t %s -P %s %s\n", replace->name,
		   entries->name, ebt_standard_targets[-entries->policy - 1]);
	} else if (!(replace->flags & LIST_X)) {
		printf("\nBridge chain: %s, entries: %d, policy: %s\n",
		   entries->name, entries->nentries,
		   ebt_standard_targets[-entries->policy - 1]);
	}

	if (replace->flags & LIST_N) {
		i = entries->nentries;
		while (i > 9) {
			space++;
			i /= 10;
		}
	}

	for (i = 0; i < entries->nentries; i++) {
		if (replace->flags & LIST_N) {
			digits = 0;
			/* A little work to get nice rule numbers. */
			j = i + 1;
			while (j > 9) {
				digits++;
				j /= 10;
			}
			for (j = 0; j < space - digits; j++)
				printf(" ");
			printf("%d. ", i + 1);
		}
		if (replace->flags & LIST_X)
			printf("ebtables -t %s -A %s ",
			   replace->name, entries->name);

		/* The standard target's print() uses this to find out
		 * the name of a udc */
		hlp->replace = replace;

		/* Don't print anything about the protocol if no protocol was
		 * specified, obviously this means any protocol will do. */
		if (!(hlp->bitmask & EBT_NOPROTO)) {
			printf("-p ");
			if (hlp->invflags & EBT_IPROTO)
				printf("! ");
			if (hlp->bitmask & EBT_802_3)
				printf("Length ");
			else {
				struct ethertypeent *ent;

				ent = getethertypebynumber(ntohs(hlp->ethproto));
				if (!ent)
					printf("0x%x ", ntohs(hlp->ethproto));
				else
					printf("%s ", ent->e_name);
			}
		}
		if (hlp->bitmask & EBT_SOURCEMAC) {
			printf("-s ");
			if (hlp->invflags & EBT_ISOURCE)
				printf("! ");
			ebt_print_mac_and_mask(hlp->sourcemac, hlp->sourcemsk);
			printf(" ");
		}
		if (hlp->bitmask & EBT_DESTMAC) {
			printf("-d ");
			if (hlp->invflags & EBT_IDEST)
				printf("! ");
			ebt_print_mac_and_mask(hlp->destmac, hlp->destmsk);
			printf(" ");
		}
		if (hlp->in[0] != '\0') {
			printf("-i ");
			if (hlp->invflags & EBT_IIN)
				printf("! ");
			print_iface(hlp->in);
		}
		if (hlp->logical_in[0] != '\0') {
			printf("--logical-in ");
			if (hlp->invflags & EBT_ILOGICALIN)
				printf("! ");
			print_iface(hlp->logical_in);
		}
		if (hlp->logical_out[0] != '\0') {
			printf("--logical-out ");
			if (hlp->invflags & EBT_ILOGICALOUT)
				printf("! ");
			print_iface(hlp->logical_out);
		}
		if (hlp->out[0] != '\0') {
			printf("-o ");
			if (hlp->invflags & EBT_IOUT)
				printf("! ");
			print_iface(hlp->out);
		}

		m_l = hlp->m_list;
		while (m_l) {
			m = ebt_find_match(m_l->m->u.name);
			if (!m)
				ebt_print_bug("Match not found");
			m->print(hlp, m_l->m);
			m_l = m_l->next;
		}
		w_l = hlp->w_list;
		while (w_l) {
			w = ebt_find_watcher(w_l->w->u.name);
			if (!w)
				ebt_print_bug("Watcher not found");
			w->print(hlp, w_l->w);
			w_l = w_l->next;
		}

		printf("-j ");
		if (strcmp(hlp->t->u.name, EBT_STANDARD_TARGET))
			printf("%s ", hlp->t->u.name);
		t = ebt_find_target(hlp->t->u.name);
		if (!t)
			ebt_print_bug("Target '%s' not found", hlp->t->u.name);
		t->print(hlp, hlp->t);
		if (replace->flags & LIST_C) {
			uint64_t pcnt = hlp->cnt.pcnt;
			uint64_t bcnt = hlp->cnt.bcnt;

			if (replace->flags & LIST_X)
				printf("-c %"PRIu64" %"PRIu64, pcnt, bcnt);
			else
				printf(", pcnt = %"PRIu64" -- bcnt = %"PRIu64, pcnt, bcnt);
		}
		printf("\n");
		hlp = hlp->next;
	}
}