question related to /sbin/ipfw/ipfw2.c

Ganbold ganbold at micom.mng.net
Tue Sep 23 12:14:08 UTC 2008


Roman Kurakin wrote:
> Ganbold wrote:
>> Hi,
>>
>> What does following part of src/sbin/ipfw/ipfw2.c code?
>> ...
>> static void
>> fill_ip(ipfw_insn_ip *cmd, char *av)
>> {
>>    int len = 0;
>>    uint32_t *d = ((ipfw_insn_u32 *)cmd)->d;
>>
>>    cmd->o.len &= ~F_LEN_MASK;    /* zero len */
>> -----------------------------------
>>    if (strncmp(av, "table(", 6) == 0) {
> match the beginning of the "table(entry,value)"
>>        char *p = strchr(av + 6, ',');
> find the ',' if any
>>
>>        if (p)
>>            *p++ = '\0';
> and replace it with '\0' eq "table(entry\0value)" so as a string it is 
> now "table(entry"
> and make p point to 'value', eq p = 'value' now
>>        cmd->o.opcode = O_IP_DST_LOOKUP;
>>        cmd->o.arg1 = strtoul(av + 6, NULL, 0);
> av+6 is the "entry" string
> arg1=(unsigned long)entry
>>
>>        if (p) {
> if we have a 'value ' part
>>            cmd->o.len |= F_INSN_SIZE(ipfw_insn_u32);
>>            d[0] = strtoul(p, NULL, 0);
> d[0] = (unsigned long)value

Ok, now how do we know or choose the index of d[]?
Basically I would like to store some value in d[].
How can I do that?

thanks,

Ganbold

>>        } else
>>            cmd->o.len |= F_INSN_SIZE(ipfw_insn);
>>        return;
>>    }
> Is that what you need?
>
> rik
>> -----------------------------------
>>
>> Specially, what does following code?
>> ...
>>        cmd->o.opcode = O_IP_DST_LOOKUP;
>>        cmd->o.arg1 = strtoul(av + 6, NULL, 0);
>>        if (p) {
>>            cmd->o.len |= F_INSN_SIZE(ipfw_insn_u32);
>>            d[0] = strtoul(p, NULL, 0);
>>        } else
>>            cmd->o.len |= F_INSN_SIZE(ipfw_insn);
>> ...
>>
>> thanks,
>>
>> Ganbold
>>
>
> _______________________________________________
> freebsd-ipfw at freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-ipfw
> To unsubscribe, send any mail to "freebsd-ipfw-unsubscribe at freebsd.org"
>
>
>


-- 
A little inaccuracy saves a world of explanation. -- C. E. Ayres


More information about the freebsd-ipfw mailing list