Debian Codegraph @

src/batch.c

raw symbols SCIP
1 /* SPDX-License-Identifier: GPL-2.0-or-later */cxx . . $ `<file>/src/batch.c`/
2 /*
3 * Copyright (c) 2013-2015 Pablo Neira Ayuso <[email protected]>
4 */
5
6 #include "internal.h"cxx . . $ `<file>/include/internal.h`/
7 #include <errno.h>
8 #include <libmnl/libmnl.h>
9 #include <libnftnl/batch.h>cxx . . $ `<file>/include/libnftnl/batch.h`/
10
11 struct nftnl_batchcxx . . $ nftnl_batch# {
12 uint32_tcxx . . $ uint32_t# num_pagescxx . . $ nftnl_batch#num_pages.;
13 struct nftnl_batch_pagecxx . . $ nftnl_batch_page# *current_pagecxx . . $ nftnl_batch#current_page.;
14 uint32_tcxx . . $ uint32_t# page_sizecxx . . $ nftnl_batch#page_size.;
15 uint32_tcxx . . $ uint32_t# page_overrun_sizecxx . . $ nftnl_batch#page_overrun_size.;
16 struct list_headcxx . . $ list_head# page_listcxx . . $ nftnl_batch#page_list.;
17 };
18
19 struct nftnl_batch_pagecxx . . $ nftnl_batch_page# {
20 struct list_headcxx . . $ list_head# headcxx . . $ nftnl_batch_page#head.;
21 struct mnl_nlmsg_batchcxx . . $ mnl_nlmsg_batch# *batchcxx . . $ nftnl_batch_page#batch.;
22 };
23
24 static struct nftnl_batch_pagecxx . . $ nftnl_batch_page# *nftnl_batch_page_alloccxx . . $ nftnl_batch_page_alloc(821410927bd4be3f).(struct nftnl_batchcxx . . $ nftnl_batch# *batch)
25 {
26 struct nftnl_batch_pagecxx . . $ nftnl_batch_page# *page;
27 char *buf;
28
29 page = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(sizeof(struct nftnl_batch_pagecxx . . $ nftnl_batch_page#));
30 if (page == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!)
31 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
32
33 buf = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(batch->page_sizecxx . . $ nftnl_batch#page_size. + batch->page_overrun_sizecxx . . $ nftnl_batch#page_overrun_size.);
34 if (buf == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!)
35 goto err1;
36
37 page->batchcxx . . $ nftnl_batch_page#batch. = mnl_nlmsg_batch_startcxx . . $ mnl_nlmsg_batch_start(92148d5219220a56).(buf, batch->page_sizecxx . . $ nftnl_batch#page_size.);
38 if (page->batchcxx . . $ nftnl_batch_page#batch. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!)
39 goto err2;
40
41 return page;
42 err2:
43 freecxx . . $ free(5d22bdacc48458e8).(buf);
44 err1:
45 freecxx . . $ free(5d22bdacc48458e8).(page);
46 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
47 }
48
49 static void nftnl_batch_add_pagecxx . . $ nftnl_batch_add_page(8c90ff8612844ada).(struct nftnl_batch_pagecxx . . $ nftnl_batch_page# *page,
50 struct nftnl_batchcxx . . $ nftnl_batch# *batch)
51 {
52 batch->current_pagecxx . . $ nftnl_batch#current_page. = page;
53 batch->num_pagescxx . . $ nftnl_batch#num_pages.++;
54 list_add_tailcxx . . $ list_add_tail(6c3f7387ec573de3).(&page->headcxx . . $ nftnl_batch_page#head., &batch->page_listcxx . . $ nftnl_batch#page_list.);
55 }
56
57 EXPORT_SYMBOLcxx . . $ `include/utils.h:14:10`!(nftnl_batch_alloc);
58 struct nftnl_batchcxx . . $ nftnl_batch# *nftnl_batch_alloccxx . . $ nftnl_batch_alloc(2ed5552633381357).(uint32_tcxx . . $ uint32_t# pg_size, uint32_tcxx . . $ uint32_t# pg_overrun_size)
59 {
60 struct nftnl_batchcxx . . $ nftnl_batch# *batch;
61 struct nftnl_batch_pagecxx . . $ nftnl_batch_page# *page;
62
63 batch = calloccxx . . $ calloc(63a7bf2941bfcd7a).(1, sizeof(struct nftnl_batchcxx . . $ nftnl_batch#));
64 if (batch == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!)
65 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
66
67 batch->page_sizecxx . . $ nftnl_batch#page_size. = pg_size;
68 batch->page_overrun_sizecxx . . $ nftnl_batch#page_overrun_size. = pg_overrun_size;
69 INIT_LIST_HEADcxx . . $ `include/linux_list.h:66:9`!(&batch->page_list);
70
71 page = nftnl_batch_page_alloccxx . . $ nftnl_batch_page_alloc(821410927bd4be3f).(batch);
72 if (page == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!)
73 goto err1;
74
75 nftnl_batch_add_pagecxx . . $ nftnl_batch_add_page(8c90ff8612844ada).(page, batch);
76 return batch;
77 err1:
78 freecxx . . $ free(5d22bdacc48458e8).(batch);
79 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
80 }
81
82 EXPORT_SYMBOLcxx . . $ `include/utils.h:14:10`!(nftnl_batch_free);
83 void nftnl_batch_freecxx . . $ nftnl_batch_free(b545ef6d17d57827).(struct nftnl_batchcxx . . $ nftnl_batch# *batch)
84 {
85 struct nftnl_batch_pagecxx . . $ nftnl_batch_page# *page, *next;
86
87 list_for_each_entry_safecxx . . $ `include/linux_list.h:435:9`!(page, next, &batch->page_list, head) {
88 freecxx . . $ free(5d22bdacc48458e8).(mnl_nlmsg_batch_headcxx . . $ mnl_nlmsg_batch_head(e6dcd6b3a8cfcc6e).(page->batchcxx . . $ nftnl_batch_page#batch.));
89 mnl_nlmsg_batch_stopcxx . . $ mnl_nlmsg_batch_stop(9ec449ff7bd2d2ec).(page->batchcxx . . $ nftnl_batch_page#batch.);
90 freecxx . . $ free(5d22bdacc48458e8).(page);
91 }
92
93 freecxx . . $ free(5d22bdacc48458e8).(batch);
94 }
95
96 EXPORT_SYMBOLcxx . . $ `include/utils.h:14:10`!(nftnl_batch_update);
97 int nftnl_batch_updatecxx . . $ nftnl_batch_update(ed1849ac2d1e2e5).(struct nftnl_batchcxx . . $ nftnl_batch# *batch)
98 {
99 struct nftnl_batch_pagecxx . . $ nftnl_batch_page# *page;
100 struct nlmsghdrcxx . . $ nlmsghdr# *last_nlh;
101
102 if (mnl_nlmsg_batch_nextcxx . . $ mnl_nlmsg_batch_next(5cafdd85047999f6).(batch->current_pagecxx . . $ nftnl_batch#current_page.->batchcxx . . $ nftnl_batch_page#batch.))
103 return 0;
104
105 last_nlh = nftnl_batch_buffercxx . . $ nftnl_batch_buffer(edaff7d62bd7d9f6).(batch);
106
107 page = nftnl_batch_page_alloccxx . . $ nftnl_batch_page_alloc(821410927bd4be3f).(batch);
108 if (page == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!)
109 goto err1;
110
111 nftnl_batch_add_pagecxx . . $ nftnl_batch_add_page(8c90ff8612844ada).(page, batch);
112
113 memcpycxx . . $ memcpy(cc817cb175f282d).(nftnl_batch_buffercxx . . $ nftnl_batch_buffer(edaff7d62bd7d9f6).(batch), last_nlh, last_nlh->nlmsg_lencxx . . $ nlmsghdr#nlmsg_len.);
114 mnl_nlmsg_batch_nextcxx . . $ mnl_nlmsg_batch_next(5cafdd85047999f6).(batch->current_pagecxx . . $ nftnl_batch#current_page.->batchcxx . . $ nftnl_batch_page#batch.);
115
116 return 0;
117 err1:
118 return -1;
119 }
120
121 EXPORT_SYMBOLcxx . . $ `include/utils.h:14:10`!(nftnl_batch_buffer);
122 void *nftnl_batch_buffercxx . . $ nftnl_batch_buffer(edaff7d62bd7d9f6).(struct nftnl_batchcxx . . $ nftnl_batch# *batch)
123 {
124 return mnl_nlmsg_batch_currentcxx . . $ mnl_nlmsg_batch_current(e6dcd6b3a8cfcc6e).(batch->current_pagecxx . . $ nftnl_batch#current_page.->batchcxx . . $ nftnl_batch_page#batch.);
125 }
126
127 EXPORT_SYMBOLcxx . . $ `include/utils.h:14:10`!(nftnl_batch_buffer_len);
128 uint32_tcxx . . $ uint32_t# nftnl_batch_buffer_lencxx . . $ nftnl_batch_buffer_len(9637eaf30b27120e).(struct nftnl_batchcxx . . $ nftnl_batch# *batch)
129 {
130 return mnl_nlmsg_batch_sizecxx . . $ mnl_nlmsg_batch_size(70b831e9aabf33b5).(batch->current_pagecxx . . $ nftnl_batch#current_page.->batchcxx . . $ nftnl_batch_page#batch.);
131 }
132
133 EXPORT_SYMBOLcxx . . $ `include/utils.h:14:10`!(nftnl_batch_iovec_len);
134 int nftnl_batch_iovec_lencxx . . $ nftnl_batch_iovec_len(ed1849ac2d1e2e5).(struct nftnl_batchcxx . . $ nftnl_batch# *batch)
135 {
136 int num_pages = batch->num_pagescxx . . $ nftnl_batch#num_pages.;
137
138 /* Skip last page if it's empty */
139 if (mnl_nlmsg_batch_is_emptycxx . . $ mnl_nlmsg_batch_is_empty(5cafdd85047999f6).(batch->current_pagecxx . . $ nftnl_batch#current_page.->batchcxx . . $ nftnl_batch_page#batch.))
140 num_pages--;
141
142 return num_pages;
143 }
144
145 EXPORT_SYMBOLcxx . . $ `include/utils.h:14:10`!(nftnl_batch_iovec);
146 void nftnl_batch_ioveccxx . . $ nftnl_batch_iovec(a9cf4080a08f1b05).(struct nftnl_batchcxx . . $ nftnl_batch# *batch, struct ioveccxx . . $ iovec# *iov,
147 uint32_tcxx . . $ uint32_t# iovlen)
148 {
149 struct nftnl_batch_pagecxx . . $ nftnl_batch_page# *page;
150 int i = 0;
151
152 list_for_each_entrycxx . . $ `include/linux_list.h:384:9`!(page, &batch->page_list, head) {
153 if (i >= iovlen)
154 break;
155
156 iov[i].iov_basecxx . . $ iovec#iov_base. = mnl_nlmsg_batch_headcxx . . $ mnl_nlmsg_batch_head(e6dcd6b3a8cfcc6e).(page->batchcxx . . $ nftnl_batch_page#batch.);
157 iov[i].iov_lencxx . . $ iovec#iov_len. = mnl_nlmsg_batch_sizecxx . . $ mnl_nlmsg_batch_size(70b831e9aabf33b5).(page->batchcxx . . $ nftnl_batch_page#batch.);
158 i++;
159 }
160 }