Make room for multi-type values in struct tentry.

This commit is contained in:
Alexander V. Chernikov 2014-08-15 12:58:32 +00:00
parent c21034b744
commit 4bbd15771b
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/projects/ipfw/; revision=270021
4 changed files with 21 additions and 19 deletions

View File

@ -1387,15 +1387,15 @@ tentry_fill_value(ipfw_obj_header *oh, ipfw_obj_tentry *tent, char *arg,
char *p;
/* Try to interpret as number first */
tent->value = strtoul(arg, &p, 0);
tent->v.value = strtoul(arg, &p, 0);
if (*p == '\0')
return;
if (inet_pton(AF_INET, arg, &val) == 1) {
tent->value = ntohl(val);
tent->v.value = ntohl(val);
return;
}
/* Try hostname */
if (lookup_host(arg, (struct in_addr *)&tent->value) == 0)
if (lookup_host(arg, (struct in_addr *)&tent->v.value) == 0)
return;
errx(EX_OSERR, "Unable to parse value %s", arg);
#if 0
@ -1565,7 +1565,7 @@ table_show_entry(ipfw_xtable_info *i, ipfw_obj_tentry *tent)
uint32_t tval;
struct tflow_entry *tfe;
tval = tent->value;
tval = tent->v.value;
if (co.do_value_as_ip || i->vftype == IPFW_VFTYPE_IP) {
tval = htonl(tval);

View File

@ -756,12 +756,10 @@ typedef struct _ipfw_obj_tentry {
ipfw_obj_tlv head; /* TLV header */
uint8_t subtype; /* subtype (IPv4,IPv6) */
uint8_t masklen; /* mask length */
uint16_t idx; /* Table name index */
uint32_t value; /* value */
uint8_t result; /* request result */
uint8_t spare0;
uint16_t idx; /* Table name index */
uint16_t spare1;
uint32_t spare2;
union {
/* Longest field needs to be aligned by 8-byte boundary */
struct in_addr addr; /* IPv4 address */
@ -770,6 +768,10 @@ typedef struct _ipfw_obj_tentry {
char iface[IF_NAMESIZE]; /* interface name */
struct tflow_entry flow;
} k;
union {
uint32_t value; /* 32-bit value */
char storage[64]; /* Future needs */
} v;
} ipfw_obj_tentry;
#define IPFW_TF_UPDATE 0x01 /* Update record if exists */
/* Container TLV */

View File

@ -888,7 +888,7 @@ ipfw_manage_table_ent_v1(struct ip_fw_chain *ch, ip_fw3_opheader *op3,
ptei->masklen = ptent->masklen;
if (ptent->head.flags & IPFW_TF_UPDATE)
ptei->flags |= TEI_FLAGS_UPDATE;
ptei->value = ptent->value;
ptei->value = ptent->v.value;
}
error = (oh->opheader.opcode == IP_FW_TABLE_XADD) ?
@ -2244,7 +2244,7 @@ dump_table_entry(void *e, void *arg)
ent->addr = da->tent.k.addr.s_addr;
ent->masklen = da->tent.masklen;
ent->value = da->tent.value;
ent->value = da->tent.v.value;
return (0);
}
@ -2345,7 +2345,7 @@ dump_table_xentry(void *e, void *arg)
/* Convert current format to previous one */
xent->masklen = tent->masklen;
xent->value = tent->value;
xent->value = tent->v.value;
/* Apply some hacks */
if (tc->no.type == IPFW_TABLE_ADDR && tent->subtype == AF_INET) {
xent->k.addr6.s6_addr32[3] = tent->k.addr.s_addr;

View File

@ -482,14 +482,14 @@ ta_dump_radix_tentry(void *ta_state, struct table_info *ti, void *e,
tent->k.addr.s_addr = n->addr.sin_addr.s_addr;
tent->masklen = n->masklen;
tent->subtype = AF_INET;
tent->value = n->value;
tent->v.value = n->value;
#ifdef INET6
} else {
xn = (struct radix_addr_xentry *)e;
memcpy(&tent->k, &xn->addr6.sin6_addr, sizeof(struct in6_addr));
tent->masklen = xn->masklen;
tent->subtype = AF_INET6;
tent->value = xn->value;
tent->v.value = xn->value;
#endif
}
@ -1257,13 +1257,13 @@ ta_dump_chash_tentry(void *ta_state, struct table_info *ti, void *e,
tent->k.addr.s_addr = htonl(ent->a.a4 << (32 - cfg->mask4));
tent->masklen = cfg->mask4;
tent->subtype = AF_INET;
tent->value = ent->value;
tent->v.value = ent->value;
#ifdef INET6
} else {
memcpy(&tent->k, &ent->a.a6, sizeof(struct in6_addr));
tent->masklen = cfg->mask6;
tent->subtype = AF_INET6;
tent->value = ent->value;
tent->v.value = ent->value;
#endif
}
@ -2354,7 +2354,7 @@ ta_dump_ifidx_tentry(void *ta_state, struct table_info *ti, void *e,
tent->masklen = 8 * IF_NAMESIZE;
memcpy(&tent->k, ife->no.name, IF_NAMESIZE);
tent->value = ife->value;
tent->v.value = ife->value;
return (0);
}
@ -2778,7 +2778,7 @@ ta_dump_numarray_tentry(void *ta_state, struct table_info *ti, void *e,
na = (struct numarray *)e;
tent->k.key = na->number;
tent->value = na->value;
tent->v.value = na->value;
return (0);
}
@ -3124,7 +3124,7 @@ ta_dump_fhash_tentry(void *ta_state, struct table_info *ti, void *e,
tfe->proto = ent->proto;
tfe->dport = htons(ent->dport);
tfe->sport = htons(ent->sport);
tent->value = ent->value;
tent->v.value = ent->value;
tent->subtype = ent->af;
if (ent->af == AF_INET) {
@ -3693,7 +3693,7 @@ ta_dump_kfib_tentry(void *ta_state, struct table_info *ti, void *e,
len = 0;
tent->masklen = len;
tent->subtype = AF_INET;
tent->value = 0; /* Do we need to put GW here? */
tent->v.value = 0; /* Do we need to put GW here? */
#ifdef INET6
} else if (addr->sin_family == AF_INET6) {
addr6 = (struct sockaddr_in6 *)addr;
@ -3706,7 +3706,7 @@ ta_dump_kfib_tentry(void *ta_state, struct table_info *ti, void *e,
len = 0;
tent->masklen = len;
tent->subtype = AF_INET6;
tent->value = 0;
tent->v.value = 0;
#endif
}