| 939 | } |
| 940 | |
| 941 | static void |
| 942 | table_modify_record(ipfw_obj_header *oh, int ac, char *av[], int add, |
| 943 | int quiet, int update, int atomic) |
| 944 | { |
| 945 | ipfw_obj_tentry *ptent, tent, *tent_buf; |
| 946 | ipfw_xtable_info xi; |
| 947 | const char *etxt, *px, *texterr; |
| 948 | uint8_t type; |
| 949 | uint32_t vmask; |
| 950 | int cmd, count, error, i, ignored; |
| 951 | |
| 952 | if (ac == 0) |
| 953 | errx(EX_USAGE, "address required"); |
| 954 | |
| 955 | if (add != 0) { |
| 956 | cmd = IP_FW_TABLE_XADD; |
| 957 | texterr = "Adding record failed"; |
| 958 | } else { |
| 959 | cmd = IP_FW_TABLE_XDEL; |
| 960 | texterr = "Deleting record failed"; |
| 961 | } |
| 962 | |
| 963 | /* |
| 964 | * Calculate number of entries: |
| 965 | * Assume [key val] x N for add |
| 966 | * and |
| 967 | * key x N for delete |
| 968 | */ |
| 969 | count = (add != 0) ? ac / 2 + 1 : ac; |
| 970 | |
| 971 | if (count <= 1) { |
| 972 | /* Adding single entry with/without value */ |
| 973 | memset(&tent, 0, sizeof(tent)); |
| 974 | tent_buf = &tent; |
| 975 | } else { |
| 976 | |
| 977 | if ((tent_buf = calloc(count, sizeof(tent))) == NULL) |
| 978 | errx(EX_OSERR, |
| 979 | "Unable to allocate memory for all entries"); |
| 980 | } |
| 981 | ptent = tent_buf; |
| 982 | |
| 983 | memset(&xi, 0, sizeof(xi)); |
| 984 | count = 0; |
| 985 | while (ac > 0) { |
| 986 | tentry_fill_key(oh, ptent, *av, add, &type, &vmask, &xi); |
| 987 | |
| 988 | /* |
| 989 | * Compatibility layer: auto-create table if not exists. |
| 990 | */ |
| 991 | if (xi.tablename[0] == '\0') { |
| 992 | xi.type = type; |
| 993 | xi.vmask = vmask; |
| 994 | strlcpy(xi.tablename, oh->ntlv.name, |
| 995 | sizeof(xi.tablename)); |
| 996 | if (quiet == 0) |
| 997 | warnx("DEPRECATED: inserting data into " |
| 998 | "non-existent table %s. (auto-created)", |
no test coverage detected