MCPcopy Create free account
hub / github.com/F-Stack/f-stack / table_do_modify_record

Function table_do_modify_record

tools/ipfw/tables.c:889–939  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

887}
888
889static int
890table_do_modify_record(int cmd, ipfw_obj_header *oh,
891 ipfw_obj_tentry *tent, int count, int atomic)
892{
893 ipfw_obj_ctlv *ctlv;
894 ipfw_obj_tentry *tent_base;
895 caddr_t pbuf;
896 char xbuf[sizeof(*oh) + sizeof(ipfw_obj_ctlv) + sizeof(*tent)];
897 int error, i;
898 size_t sz;
899
900 sz = sizeof(*ctlv) + sizeof(*tent) * count;
901 if (count == 1) {
902 memset(xbuf, 0, sizeof(xbuf));
903 pbuf = xbuf;
904 } else {
905 if ((pbuf = calloc(1, sizeof(*oh) + sz)) == NULL)
906 return (ENOMEM);
907 }
908
909 memcpy(pbuf, oh, sizeof(*oh));
910 oh = (ipfw_obj_header *)pbuf;
911 oh->opheader.version = 1;
912
913 ctlv = (ipfw_obj_ctlv *)(oh + 1);
914 ctlv->count = count;
915 ctlv->head.length = sz;
916 if (atomic != 0)
917 ctlv->flags |= IPFW_CTF_ATOMIC;
918
919 tent_base = tent;
920 memcpy(ctlv + 1, tent, sizeof(*tent) * count);
921 tent = (ipfw_obj_tentry *)(ctlv + 1);
922 for (i = 0; i < count; i++, tent++) {
923 tent->head.length = sizeof(ipfw_obj_tentry);
924 tent->idx = oh->idx;
925 }
926
927 sz += sizeof(*oh);
928 error = do_get3(cmd, &oh->opheader, &sz);
929 if (error != 0)
930 error = errno;
931 tent = (ipfw_obj_tentry *)(ctlv + 1);
932 /* Copy result back to provided buffer */
933 memcpy(tent_base, ctlv + 1, sizeof(*tent) * count);
934
935 if (pbuf != xbuf)
936 free(pbuf);
937
938 return (error);
939}
940
941static void
942table_modify_record(ipfw_obj_header *oh, int ac, char *av[], int add,

Callers 1

table_modify_recordFunction · 0.85

Calls 5

memsetFunction · 0.85
callocFunction · 0.85
do_get3Function · 0.85
memcpyFunction · 0.50
freeFunction · 0.50

Tested by

no test coverage detected