aboutsummaryrefslogtreecommitdiffstats
path: root/src/scvpp/src/nat.c
blob: 1ff59f3b9e6b8bdd6b518125c06f821b72c0f600 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
/*
 * Copyright (c) 2018 PANTHEON.tech.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at:
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <scvpp/comm.h>
#include <scvpp/nat.h>

#include <assert.h>
#include <stdbool.h>


DEFINE_VAPI_MSG_IDS_NAT_API_JSON

static vapi_error_e
nat44_interface_dump_cb(struct vapi_ctx_s *ctx, void *callback_ctx,
                        vapi_error_e rv, bool is_last,
                        vapi_payload_nat44_interface_details *reply)
{
    UNUSED(ctx); UNUSED(rv);
    vapi_payload_nat44_interface_details *dctx = callback_ctx;
    assert(dctx);

    if (is_last)
    {
        assert(NULL == reply);
    }
    else
    {
        //TODO: Use LOG message for scvpp
//         SC_LOG_DBG("NAT Interface dump entry: [%u]: %u\n", reply->sw_if_index,
//                     reply->is_inside);
        *dctx = *reply;
    }

    return VAPI_OK;
}

static vapi_error_e
bin_api_nat44_interface_dump(vapi_payload_nat44_interface_details *reply)
{
    vapi_error_e rv;
    vapi_msg_nat44_interface_dump *mp;

    ARG_CHECK(VAPI_EINVAL, reply);

    mp = vapi_alloc_nat44_interface_dump(g_vapi_ctx);
    assert(NULL != mp);

    VAPI_CALL(vapi_nat44_interface_dump(g_vapi_ctx, mp,
                                        nat44_interface_dump_cb, reply));

    return rv;
}

VAPI_REQUEST_CB(nat44_add_del_interface_addr);

static vapi_error_e
bin_api_nat44_add_del_interface_addr(
    const vapi_payload_nat44_add_del_interface_addr *msg)
{
    vapi_error_e rv;
    vapi_msg_nat44_add_del_interface_addr *mp;

    ARG_CHECK(VAPI_EINVAL, msg);

    mp = vapi_alloc_nat44_add_del_interface_addr(g_vapi_ctx);
    assert(NULL != mp);

    mp->payload = *msg;

    VAPI_CALL(vapi_nat44_add_del_interface_addr(g_vapi_ctx, mp,
                                                nat44_add_del_interface_addr_cb,
                                                NULL));

    return rv;
}

VAPI_REQUEST_CB(nat44_add_del_address_range);

static vapi_error_e
bin_api_nat44_add_del_addr_range(
    const vapi_payload_nat44_add_del_address_range *range)
{
    vapi_error_e rv;
    vapi_msg_nat44_add_del_address_range *mp;

    ARG_CHECK(VAPI_EINVAL, range);

    mp = vapi_alloc_nat44_add_del_address_range(g_vapi_ctx);

    assert(NULL != mp);

    mp->payload = *range;

    VAPI_CALL(vapi_nat44_add_del_address_range(g_vapi_ctx, mp,
                                               nat44_add_del_address_range_cb,
                                               NULL));

    return rv;
}

VAPI_REQUEST_CB(nat44_add_del_static_mapping);

static vapi_error_e
bin_api_nat44_add_del_static_mapping(
    const vapi_payload_nat44_add_del_static_mapping *msg)
{
    vapi_error_e rv;
    vapi_msg_nat44_add_del_static_mapping *mp;

    ARG_CHECK(VAPI_EINVAL, msg);

    mp = vapi_alloc_nat44_add_del_static_mapping(g_vapi_ctx);
    assert(NULL != mp);

    mp->payload = *msg;

    VAPI_CALL(vapi_nat44_add_del_static_mapping(g_vapi_ctx, mp,
                                                nat44_add_del_static_mapping_cb,
                                                NULL));

    return rv;
}

static vapi_error_e nat44_static_mapping_dump_cb(
    struct vapi_ctx_s *ctx, void *callback_ctx, vapi_error_e rv,
    bool is_last,vapi_payload_nat44_static_mapping_details *reply)
{
    UNUSED(rv); UNUSED(ctx);
    vapi_payload_nat44_static_mapping_details *dctx = callback_ctx;
    assert(dctx);

    if (is_last)
    {
        assert(NULL == reply);
    }
    else
    {
        *dctx = *reply;
    }

    return VAPI_OK;
}

static vapi_error_e
bin_api_nat44_static_mapping_dump(
    vapi_payload_nat44_static_mapping_details *reply)
{
    vapi_error_e rv;
    vapi_msg_nat44_static_mapping_dump *msg;

    ARG_CHECK(VAPI_EINVAL, reply);

    msg = vapi_alloc_nat44_static_mapping_dump(g_vapi_ctx);
    assert(NULL != msg);

    VAPI_CALL(vapi_nat44_static_mapping_dump(g_vapi_ctx, msg,
                                             nat44_static_mapping_dump_cb,
                                             reply));

    return rv;
}

VAPI_REQUEST_CB(nat44_forwarding_enable_disable);

static vapi_error_e bin_api_nat44_forwarding_enable_disable(
    const vapi_payload_nat44_forwarding_enable_disable *msg)
{
    vapi_error_e rv;
    vapi_msg_nat44_forwarding_enable_disable *mp;

    ARG_CHECK(VAPI_EINVAL, msg);

    mp = vapi_alloc_nat44_forwarding_enable_disable(g_vapi_ctx);
    assert(NULL != mp);

    mp->payload = *msg;

    VAPI_CALL(vapi_nat44_forwarding_enable_disable(
        g_vapi_ctx, mp, nat44_forwarding_enable_disable_cb, NULL));

    return rv;
}

VAPI_REQUEST_CB(nat_set_workers);

static vapi_error_e
bin_api_nat_set_workers(const vapi_payload_nat_set_workers *msg)
{
    vapi_error_e rv;
    vapi_msg_nat_set_workers *mp;

    ARG_CHECK(VAPI_EINVAL, msg);

    mp = vapi_alloc_nat_set_workers(g_vapi_ctx);
    assert(NULL != mp);

    mp->payload = *msg;

    VAPI_CALL(vapi_nat_set_workers(g_vapi_ctx, mp, nat_set_workers_cb, NULL));

    return rv;
}

int nat44_interface_dump(nat44_interface_details_t *reply)
{
    vapi_error_e rv;

    rv = bin_api_nat44_interface_dump(reply);
    if (VAPI_OK != rv)
        return -SCVPP_EINVAL;

    return SCVPP_OK;
}

int nat44_add_del_interface_addr(const nat44_add_del_interface_addr_t *msg)
{
    vapi_error_e rv;

    rv = bin_api_nat44_add_del_interface_addr(msg);
    if (VAPI_OK != rv)
        return -SCVPP_EINVAL;

    return SCVPP_OK;
}

int nat44_add_del_addr_range(const nat44_add_del_address_range_t *range)
{
    vapi_error_e rv;

    rv = bin_api_nat44_add_del_addr_range(range);
    if (VAPI_OK != rv)
        return -SCVPP_EINVAL;

    return SCVPP_OK;
}

int nat44_add_del_static_mapping(const nat44_add_del_static_mapping_t *msg)
{
    vapi_error_e rv;

    rv = bin_api_nat44_add_del_static_mapping(msg);
    if (VAPI_OK != rv)
        return -SCVPP_EINVAL;

    return SCVPP_OK;
}

int nat44_static_mapping_dump(nat44_static_mapping_details_t *reply)
{
    vapi_error_e rv;

    rv = bin_api_nat44_static_mapping_dump(reply);
    if (VAPI_OK != rv)
        return -SCVPP_EINVAL;

    return SCVPP_OK;
}

int
nat44_forwarding_enable_disable(const nat44_forwarding_enable_disable_t *msg)
{
    vapi_error_e rv;

    rv = bin_api_nat44_forwarding_enable_disable(msg);
    if (VAPI_OK != rv)
        return -SCVPP_EINVAL;

    return 0;
}

int nat_set_workers(const nat_set_workers_t *msg)
{
    vapi_error_e rv;

    rv = bin_api_nat_set_workers(msg);
    if (VAPI_OK != rv)
        return -SCVPP_EINVAL;

    return SCVPP_OK;
}