| 3034 | } |
| 3035 | |
| 3036 | static uint16_t |
| 3037 | pack_object(struct tidx *tstate, const char *name, int otype) |
| 3038 | { |
| 3039 | ipfw_obj_ntlv *ntlv; |
| 3040 | uint32_t i; |
| 3041 | |
| 3042 | for (i = 0; i < tstate->count; i++) { |
| 3043 | if (strcmp(tstate->idx[i].name, name) != 0) |
| 3044 | continue; |
| 3045 | if (tstate->idx[i].set != tstate->set) |
| 3046 | continue; |
| 3047 | if (tstate->idx[i].head.type != otype) |
| 3048 | continue; |
| 3049 | |
| 3050 | return (tstate->idx[i].idx); |
| 3051 | } |
| 3052 | |
| 3053 | if (tstate->count + 1 > tstate->size) { |
| 3054 | tstate->size += 4; |
| 3055 | tstate->idx = realloc(tstate->idx, tstate->size * |
| 3056 | sizeof(ipfw_obj_ntlv)); |
| 3057 | if (tstate->idx == NULL) |
| 3058 | return (0); |
| 3059 | } |
| 3060 | |
| 3061 | ntlv = &tstate->idx[i]; |
| 3062 | memset(ntlv, 0, sizeof(ipfw_obj_ntlv)); |
| 3063 | strlcpy(ntlv->name, name, sizeof(ntlv->name)); |
| 3064 | ntlv->head.type = otype; |
| 3065 | ntlv->head.length = sizeof(ipfw_obj_ntlv); |
| 3066 | ntlv->set = tstate->set; |
| 3067 | ntlv->idx = ++tstate->counter; |
| 3068 | tstate->count++; |
| 3069 | |
| 3070 | return (ntlv->idx); |
| 3071 | } |
| 3072 | |
| 3073 | static uint16_t |
| 3074 | pack_table(struct tidx *tstate, const char *name) |
no test coverage detected