-
Notifications
You must be signed in to change notification settings - Fork 257
/
Copy pathgnb_pf.c
663 lines (434 loc) · 19.5 KB
/
gnb_pf.c
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
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
/*
Copyright (C) gnbdev
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdlib.h>
#include "gnb.h"
#include "gnb_node.h"
#include "gnb_hash32.h"
#include "gnb_pf.h"
#include "gnb_payload16.h"
#include "gnb_unified_forwarding.h"
void gnb_send_ur0_frame(gnb_core_t *gnb_core, gnb_node_t *dst_node, gnb_payload16_t *payload);
gnb_node_t* gnb_query_route4(gnb_core_t *gnb_core, uint32_t dst_ip_int){
char ip_string[INET_ADDRSTRLEN];
inet_ntop(AF_INET, &dst_ip_int, ip_string, INET_ADDRSTRLEN);
gnb_node_t *node=NULL;
uint32_t dsp_ip_key = dst_ip_int;
node = GNB_HASH32_UINT32_GET_PTR(gnb_core->ipv4_node_map, dsp_ip_key);
if ( node ) {
goto finish;
}
dsp_ip_key = dst_ip_int & htonl(IN_CLASSC_NET);
node = GNB_HASH32_UINT32_GET_PTR(gnb_core->subnetc_node_map, dsp_ip_key);
if ( node ) {
goto finish;
}
dsp_ip_key = dst_ip_int & htonl(IN_CLASSB_NET);
node = GNB_HASH32_UINT32_GET_PTR(gnb_core->subnetb_node_map, dsp_ip_key);
if ( node ) {
goto finish;
}
dsp_ip_key = dst_ip_int & htonl(IN_CLASSA_NET);
node = GNB_HASH32_UINT32_GET_PTR(gnb_core->subneta_node_map, dsp_ip_key);
if ( node ) {
goto finish;
}
finish:
return node;
}
#define GNB_PF_TUN_FRAME_INIT 0
#define GNB_PF_TUN_FRAME_ERROR 1
#define GNB_PF_TUN_FRAME_DROP 2
#define GNB_PF_TUN_FRAME_NEXT 3
#define GNB_PF_TUN_FRAME_FINISH 4
#define GNB_PF_TUN_ROUTE_INIT 5
#define GNB_PF_TUN_ROUTE_ERROR 6
#define GNB_PF_TUN_ROUTE_DROP 7
#define GNB_PF_TUN_ROUTE_NOROUTE 8
#define GNB_PF_TUN_ROUTE_NEXT 9
#define GNB_PF_TUN_ROUTE_FINISH 10
#define GNB_PF_TUN_FORWARD_INIT 11
#define GNB_PF_TUN_FORWARD_ERROR 12
#define GNB_PF_TUN_FORWARD_NEXT 13
#define GNB_PF_TUN_FORWARD_FINISH 14
#define GNB_PF_INET_FRAME_INIT 15
#define GNB_PF_INET_FRAME_ERROR 16
#define GNB_PF_INET_FRAME_DROP 17
#define GNB_PF_INET_FRAME_NEXT 18
#define GNB_PF_INET_FRAME_FINISH 19
#define GNB_PF_INET_ROUTE_INIT 20
#define GNB_PF_INET_ROUTE_ERROR 21
#define GNB_PF_INET_ROUTE_DROP 22
#define GNB_PF_INET_ROUTE_NEXT 23
#define GNB_PF_INET_ROUTE_FINISH 24
#define GNB_PF_INET_FORWARD_INIT 25
#define GNB_PF_INET_FORWARD_ERROR 26
#define GNB_PF_INET_FORWARD_DROP 27
#define GNB_PF_INET_FORWARD_NEXT 28
#define GNB_PF_INET_FORWARD_FINISH 29
#define GNB_PF_INET_FORWARD_TO_TUN 30
#define GNB_PF_INET_FORWARD_TO_INET 31
static char* gnb_pf_status_strings[32];
void gnb_pf_status_strings_init() {
gnb_pf_status_strings[GNB_PF_TUN_FRAME_INIT] = "TUN_FRAME_INIT";
gnb_pf_status_strings[GNB_PF_TUN_FRAME_ERROR] = "TUN_FRAME_ERROR";
gnb_pf_status_strings[GNB_PF_TUN_FRAME_DROP] = "TUN_FRAME_DROP";
gnb_pf_status_strings[GNB_PF_TUN_FRAME_NEXT] = "TUN_FRAME_NEXT";
gnb_pf_status_strings[GNB_PF_TUN_FRAME_FINISH] = "TUN_FRAME_FINISH";
gnb_pf_status_strings[GNB_PF_TUN_ROUTE_INIT] = "TUN_ROUTE_INIT";
gnb_pf_status_strings[GNB_PF_TUN_ROUTE_ERROR] = "TUN_ROUTE_ERROR";
gnb_pf_status_strings[GNB_PF_TUN_ROUTE_DROP] = "TUN_ROUTE_DROP";
gnb_pf_status_strings[GNB_PF_TUN_ROUTE_NOROUTE] = "TUN_ROUTE_NOROUTE";
gnb_pf_status_strings[GNB_PF_TUN_ROUTE_NEXT] = "TUN_ROUTE_NEXT";
gnb_pf_status_strings[GNB_PF_TUN_ROUTE_FINISH] = "TUN_ROUTE_FINISH";
gnb_pf_status_strings[GNB_PF_TUN_FORWARD_INIT] = "TUN_FORWARD_INIT";
gnb_pf_status_strings[GNB_PF_TUN_FORWARD_ERROR] = "TUN_FORWARD_ERROR";
gnb_pf_status_strings[GNB_PF_TUN_FORWARD_NEXT] = "TUN_FORWARD_NEXT";
gnb_pf_status_strings[GNB_PF_TUN_FORWARD_FINISH] = "TUN_FORWARD_FINISH";
gnb_pf_status_strings[GNB_PF_INET_FRAME_INIT] = "INET_FRAME_INIT";
gnb_pf_status_strings[GNB_PF_INET_FRAME_ERROR] = "INET_FRAME_ERROR";
gnb_pf_status_strings[GNB_PF_INET_FRAME_DROP] = "INET_FRAME_DROP";
gnb_pf_status_strings[GNB_PF_INET_FRAME_NEXT] = "INET_FRAME_NEXT";
gnb_pf_status_strings[GNB_PF_INET_FRAME_FINISH] = "INET_FRAME_FINISH";
gnb_pf_status_strings[GNB_PF_INET_ROUTE_INIT] = "INET_ROUTE_INIT";
gnb_pf_status_strings[GNB_PF_INET_ROUTE_ERROR] = "INET_ROUTE_ERROR";
gnb_pf_status_strings[GNB_PF_INET_ROUTE_DROP] = "INET_ROUTE_DROP";
gnb_pf_status_strings[GNB_PF_INET_ROUTE_NEXT] = "INET_ROUTE_NEXT";
gnb_pf_status_strings[GNB_PF_INET_ROUTE_FINISH] = "INET_ROUTE_FINISH";
gnb_pf_status_strings[GNB_PF_INET_FORWARD_INIT] = "INET_FORWARD_INIT";
gnb_pf_status_strings[GNB_PF_INET_FORWARD_ERROR] = "INET_FORWARD_ERROR";
gnb_pf_status_strings[GNB_PF_INET_FORWARD_DROP] = "INET_FORWARD_DROP";
gnb_pf_status_strings[GNB_PF_INET_FORWARD_NEXT] = "INET_FORWARD_NEXT";
gnb_pf_status_strings[GNB_PF_INET_FORWARD_TO_TUN] = "INET_FORWARD_TO_TUN";
gnb_pf_status_strings[GNB_PF_INET_FORWARD_TO_INET] = "INET_FORWARD_TO_INET";
}
gnb_pf_array_t * gnb_pf_array_init(gnb_heap_t *heap, int size){
gnb_pf_array_t *pf_array;
pf_array = (gnb_pf_array_t *)gnb_heap_alloc(heap, sizeof(gnb_pf_array_t) + sizeof(gnb_pf_t)*size);
pf_array->size = size;
pf_array->num = 0;
return pf_array;
}
int gnb_pf_install(gnb_pf_array_t *pf_array, gnb_pf_t *pf){
if ( pf_array->num >= pf_array->size ) {
return -1;
}
pf_array->pf[pf_array->num] = pf;
pf_array->num++;
return 0;
}
void gnb_pf_init(gnb_core_t *gnb_core, gnb_pf_array_t *pf_array){
int i;
for ( i=0; i<pf_array->num; i++ ) {
if ( NULL==pf_array->pf[i]->pf_init ) {
continue;
}
pf_array->pf[i]->pf_init(gnb_core,pf_array->pf[i]);
}
}
void gnb_pf_conf(gnb_core_t *gnb_core, gnb_pf_array_t *pf_array){
int i;
for ( i=0; i<pf_array->num; i++ ) {
if ( NULL==pf_array->pf[i]->pf_conf ) {
continue;
}
pf_array->pf[i]->pf_conf(gnb_core,pf_array->pf[i]);
}
}
/*
把输入的 payload 加上offset,这样pf模块处理的时候,就可以在offset之前填充pf的头部,减少一次通过 memcpy 重组payload
*/
void gnb_pf_tun(gnb_core_t *gnb_core, gnb_pf_array_t *pf_array, gnb_payload16_t *payload){
int i;
int ret;
gnb_pf_ctx_t pf_ctx_st;
memset(&pf_ctx_st,0,sizeof(gnb_pf_ctx_t));
pf_ctx_st.pf_fwd = GNB_PF_FWD_INIT;
pf_ctx_st.fwd_payload = payload;
pf_ctx_st.fwd_payload->type = GNB_PAYLOAD_TYPE_IPFRAME;
pf_ctx_st.fwd_payload->sub_type = GNB_PAYLOAD_SUB_TYPE_IPFRAME_INIT;
int pf_tun_frame_status = GNB_PF_TUN_FRAME_INIT;
int pf_tun_route_status = GNB_PF_TUN_ROUTE_INIT;
int pf_tun_forward_status = GNB_PF_TUN_FORWARD_INIT;
gnb_uuid_t fwd_uuid64 = 0;
gnb_core->select_fwd_node = gnb_select_forward_node(gnb_core);
pf_ctx_st.pf_status = GNB_PF_TUN_FRAME_INIT;
if ( 1 == gnb_core->conf->if_dump ) {
GNB_LOG3(gnb_core->log, GNB_LOG_ID_PF, "----- GNB PF TUN BEGIN -----\n");
}
for ( i=0; i<pf_array->num; i++ ) {
if ( NULL==pf_array->pf[i]->pf_tun_frame ) {
continue;
}
pf_ctx_st.pf_status = pf_array->pf[i]->pf_tun_frame(gnb_core, pf_array->pf[i], &pf_ctx_st);
if ( GNB_PF_ERROR == pf_ctx_st.pf_status ) {
pf_tun_frame_status = GNB_PF_TUN_FRAME_ERROR;
goto pf_tun_finish;
}
if ( GNB_PF_DROP == pf_ctx_st.pf_status ) {
pf_tun_frame_status = GNB_PF_TUN_FRAME_DROP;
goto pf_tun_finish;
}
if ( GNB_PF_NEXT == pf_ctx_st.pf_status ) {
pf_tun_frame_status = GNB_PF_TUN_FRAME_NEXT;
}
if ( GNB_PF_FINISH == pf_ctx_st.pf_status ) {
pf_tun_frame_status = GNB_PF_TUN_FRAME_FINISH;
break;
}
}
pf_ctx_st.pf_status = GNB_PF_TUN_ROUTE_INIT;
for ( i=0; i<pf_array->num; i++ ) {
if ( NULL == pf_array->pf[i]->pf_tun_route ) {
continue;
}
pf_ctx_st.pf_status = pf_array->pf[i]->pf_tun_route(gnb_core, pf_array->pf[i], &pf_ctx_st);
if ( GNB_PF_ERROR == pf_ctx_st.pf_status ) {
pf_tun_route_status = GNB_PF_TUN_ROUTE_ERROR;
goto pf_tun_finish;
}
if ( GNB_PF_NOROUTE == pf_ctx_st.pf_status ) {
pf_tun_route_status = GNB_PF_TUN_ROUTE_NOROUTE;
}
if ( GNB_PF_DROP == pf_ctx_st.pf_status ) {
pf_tun_route_status = GNB_PF_TUN_ROUTE_DROP;
}
if ( GNB_PF_NEXT == pf_ctx_st.pf_status ) {
pf_tun_route_status = GNB_PF_TUN_ROUTE_NEXT;
}
}
/*
* 一般的,forwarding 的优先级是 relay_forwarding > unified_forwarding > direct_forwarding > std_forwarding
* 以下条件跳转是确保 relay_forwarding > unified_forwarding
* */
if ( NULL != pf_ctx_st.fwd_node && 1 == pf_ctx_st.relay_forwarding ) {
goto pf_tun_fwd;
}
if ( GNB_UNIFIED_FORWARDING_OFF == gnb_core->conf->unified_forwarding ) {
goto skip_unified_forwarding;
}
if ( GNB_UNIFIED_FORWARDING_FORCE == gnb_core->conf->unified_forwarding ) {
GNB_LOG3(gnb_core->log, GNB_LOG_ID_PF, "Unified Forwarding Force src=%llu dst=%llu\n", pf_ctx_st.src_uuid64, pf_ctx_st.dst_uuid64);
ret = gnb_unified_forwarding_tun(gnb_core, &pf_ctx_st);
if ( ret > 0 ) {
pf_ctx_st.unified_forwarding = 1;
} else {
pf_ctx_st.unified_forwarding = 0;
}
goto pf_tun_finish;
}
if ( NULL == pf_ctx_st.fwd_node && GNB_UNIFIED_FORWARDING_AUTO == gnb_core->conf->unified_forwarding ) {
GNB_LOG3(gnb_core->log, GNB_LOG_ID_PF, "Unified Forwarding Auto src=%llu dst=%llu\n", pf_ctx_st.src_uuid64, pf_ctx_st.dst_uuid64);
ret = gnb_unified_forwarding_tun(gnb_core, &pf_ctx_st);
if ( ret > 0 ) {
pf_ctx_st.unified_forwarding = 1;
} else {
pf_ctx_st.unified_forwarding = 0;
}
goto pf_tun_finish;
}
if ( GNB_UNIFIED_FORWARDING_SUPER == gnb_core->conf->unified_forwarding || GNB_UNIFIED_FORWARDING_HYPER == gnb_core->conf->unified_forwarding ) {
GNB_LOG3(gnb_core->log, GNB_LOG_ID_PF, "Unified Forwarding Multi-Path src=%llu dst=%llu\n", pf_ctx_st.src_uuid64, pf_ctx_st.dst_uuid64);
ret = gnb_unified_forwarding_with_multi_path_tun(gnb_core, &pf_ctx_st);
if ( 0 == ret ) {
pf_ctx_st.unified_forwarding = 1;
} else {
pf_ctx_st.unified_forwarding = 0;
}
goto pf_tun_finish;
}
skip_unified_forwarding:
if ( NULL == pf_ctx_st.fwd_node ) {
goto pf_tun_finish;
}
pf_tun_fwd:
pf_ctx_st.pf_status = GNB_PF_TUN_FORWARD_INIT;
for ( i=pf_array->num-1; i>=0; i-- ) {
if ( NULL==pf_array->pf[i]->pf_tun_fwd ) {
continue;
}
pf_ctx_st.pf_status = pf_array->pf[i]->pf_tun_fwd(gnb_core, pf_array->pf[i], &pf_ctx_st);
if ( GNB_PF_ERROR == pf_ctx_st.pf_status ) {
pf_tun_forward_status = GNB_PF_TUN_FORWARD_ERROR;
goto pf_tun_finish;
}
if ( GNB_PF_NEXT == pf_ctx_st.pf_status ) {
pf_tun_forward_status = GNB_PF_TUN_FORWARD_NEXT;
}
if ( GNB_PF_FINISH == pf_ctx_st.pf_status ) {
pf_tun_forward_status = GNB_PF_TUN_FORWARD_FINISH;
break;
}
}
gnb_forward_payload_to_node(gnb_core, pf_ctx_st.fwd_node, pf_ctx_st.fwd_payload);
pf_ctx_st.fwd_node->in_bytes += pf_ctx_st.ip_frame_size;
gnb_core->local_node->out_bytes += pf_ctx_st.ip_frame_size;
if ( pf_ctx_st.dst_uuid64 == pf_ctx_st.fwd_node->uuid64 ) {
GNB_LOG3(gnb_core->log, GNB_LOG_ID_PF, ">>> tun payload forward to inet src=%llu dst=%llu >>>\n", pf_ctx_st.src_uuid64, pf_ctx_st.fwd_node->uuid64);
} else {
GNB_LOG3(gnb_core->log, GNB_LOG_ID_PF, "*>> tun payload forward to inet src=%llu dst=%llu fwd=%llu *>>\n", pf_ctx_st.src_uuid64, pf_ctx_st.dst_uuid64, pf_ctx_st.fwd_node->uuid64);
}
pf_tun_finish:
if ( 0 == pf_ctx_st.unified_forwarding && NULL != pf_ctx_st.dst_node && NULL == pf_ctx_st.fwd_node && 1 == pf_ctx_st.universal_udp4_relay ) {
gnb_send_ur0_frame(gnb_core, pf_ctx_st.dst_node, pf_ctx_st.fwd_payload);
GNB_LOG3(gnb_core->log, GNB_LOG_ID_PF, "tun try to universal relay src=%llu dst=%llu\n", pf_ctx_st.src_uuid64, pf_ctx_st.dst_uuid64);
}
if_dump:
if ( 1 == gnb_core->conf->if_dump ) {
fwd_uuid64 = NULL != pf_ctx_st.fwd_node ? pf_ctx_st.fwd_node->uuid64:0;
GNB_LOG3(gnb_core->log, GNB_LOG_ID_PF, "tun src=%llu dst=%llu fwd=%llu [%s] [%s] relay=%d,unified=%d,direct=%d,forward=%d ip_frame_size=%u\n",
pf_ctx_st.src_uuid64, pf_ctx_st.dst_uuid64, fwd_uuid64,
gnb_pf_status_strings[pf_tun_frame_status], gnb_pf_status_strings[pf_tun_route_status],
pf_ctx_st.relay_forwarding, pf_ctx_st.unified_forwarding, pf_ctx_st.direct_forwarding, pf_ctx_st.std_forwarding,
pf_ctx_st.ip_frame_size);
}
if ( 1 == gnb_core->conf->if_dump ) {
GNB_LOG3(gnb_core->log, GNB_LOG_ID_PF, "----- GNB PF TUN END -----\n");
}
finish:
return;
}
void gnb_pf_inet(gnb_core_t *gnb_core, gnb_pf_array_t *pf_array, gnb_payload16_t *payload, gnb_sockaddress_t *source_node_addr){
gnb_pf_ctx_t pf_ctx_st;
memset(&pf_ctx_st,0,sizeof(gnb_pf_ctx_t));
pf_ctx_st.pf_fwd = GNB_PF_FWD_INIT;
pf_ctx_st.fwd_payload = payload;
pf_ctx_st.source_node_addr = source_node_addr;
int i;
int pf_inet_frame_status = GNB_PF_INET_FRAME_INIT;
int pf_inet_route_status = GNB_PF_INET_ROUTE_INIT;
int pf_inet_forwad_status = GNB_PF_INET_FORWARD_INIT;
int ret;
gnb_uuid_t fwd_uuid64 = 0;
gnb_core->select_fwd_node = gnb_select_forward_node(gnb_core);
if ( 1 == gnb_core->conf->if_dump ) {
GNB_LOG3(gnb_core->log, GNB_LOG_ID_PF, "----- GNB PF INET BEGIN -----\n");
}
if ( GNB_PAYLOAD_SUB_TYPE_IPFRAME_UNIFIED == payload->sub_type ) {
//如果 ip分组 不是转发到本节点,就转发到目的节点
ret = gnb_unified_forwarding_inet(gnb_core, payload);
if ( UNIFIED_FORWARDING_TO_TUN != ret ) {
goto pf_inet_finish;
}
}
if ( GNB_PAYLOAD_SUB_TYPE_IPFRAME_UNIFIED_MULTI_PATH == payload->sub_type ) {
//如果 ip分组 不是转发到本节点,就转发到目的节点
ret = gnb_unified_forwarding_multi_path_inet(gnb_core, payload);
if ( UNIFIED_FORWARDING_TO_TUN != ret ) {
goto pf_inet_finish;
}
}
for ( i=pf_array->num-1; i>=0; i-- ) {
if ( NULL == pf_array->pf[i]->pf_inet_frame ) {
continue;
}
pf_ctx_st.pf_status = pf_array->pf[i]->pf_inet_frame(gnb_core, pf_array->pf[i], &pf_ctx_st);
if ( GNB_PF_ERROR == pf_ctx_st.pf_status ) {
pf_inet_frame_status = GNB_PF_INET_FRAME_ERROR;
goto pf_inet_finish;
}
if ( GNB_PF_DROP == pf_ctx_st.pf_status ) {
pf_inet_frame_status = GNB_PF_INET_FRAME_DROP;
goto pf_inet_finish;
}
if ( GNB_PF_NEXT == pf_ctx_st.pf_status ) {
pf_inet_frame_status = GNB_PF_INET_FRAME_NEXT;
}
if ( GNB_PF_FINISH == pf_ctx_st.pf_status ) {
pf_inet_frame_status = GNB_PF_INET_FRAME_FINISH;
break;
}
}
for ( i=0; i<pf_array->num; i++ ) {
if ( NULL == pf_array->pf[i]->pf_inet_route ) {
continue;
}
pf_ctx_st.pf_status = pf_array->pf[i]->pf_inet_route(gnb_core, pf_array->pf[i], &pf_ctx_st);
if ( GNB_PF_ERROR == pf_ctx_st.pf_status ) {
pf_inet_route_status = GNB_PF_INET_ROUTE_ERROR;
goto pf_inet_finish;
}
if ( GNB_PF_DROP == pf_ctx_st.pf_status ) {
pf_inet_route_status = GNB_PF_INET_ROUTE_DROP;
goto pf_inet_finish;
}
if ( GNB_PF_NEXT == pf_ctx_st.pf_status ) {
pf_inet_route_status = GNB_PF_INET_ROUTE_NEXT;
}
if ( GNB_PF_FINISH == pf_ctx_st.pf_status ) {
pf_inet_route_status = GNB_PF_INET_ROUTE_FINISH;
break;
}
}
for ( i=0; i<pf_array->num; i++ ) {
if ( NULL == pf_array->pf[i]->pf_inet_fwd ) {
continue;
}
pf_ctx_st.pf_status = pf_array->pf[i]->pf_inet_fwd(gnb_core, pf_array->pf[i], &pf_ctx_st);
if ( GNB_PF_ERROR == pf_ctx_st.pf_status ) {
pf_inet_forwad_status = GNB_PF_INET_FORWARD_ERROR;
goto pf_inet_finish;
}
if ( GNB_PF_DROP == pf_ctx_st.pf_status ) {
pf_inet_forwad_status = GNB_PF_INET_FORWARD_DROP;
goto pf_inet_finish;
}
if ( GNB_PF_NEXT == pf_ctx_st.pf_status ) {
pf_inet_forwad_status = GNB_PF_INET_FORWARD_NEXT;
}
if ( GNB_PF_FINISH == pf_ctx_st.pf_status ) {
pf_inet_forwad_status = GNB_PF_INET_FORWARD_FINISH;
break;
}
}
fwd_uuid64 = NULL!=pf_ctx_st.fwd_node ? pf_ctx_st.fwd_node->uuid64:0;
if ( NULL == pf_ctx_st.src_node ) {
goto pf_inet_finish;
}
if ( gnb_core->conf->activate_tun && GNB_PF_FWD_TUN == pf_ctx_st.pf_fwd ) {
gnb_core->drv->write_tun(gnb_core, pf_ctx_st.ip_frame, pf_ctx_st.ip_frame_size);
fwd_uuid64 = pf_ctx_st.dst_uuid64;
pf_inet_forwad_status = GNB_PF_INET_FORWARD_TO_TUN;
gnb_core->local_node->in_bytes += pf_ctx_st.ip_frame_size;
pf_ctx_st.src_node->out_bytes += pf_ctx_st.ip_frame_size;
GNB_LOG3(gnb_core->log, GNB_LOG_ID_PF, "<<< inet payload forward to tun src=%llu dst=%llu <<<\n", pf_ctx_st.src_uuid64, pf_ctx_st.dst_uuid64);
goto pf_inet_finish;
}
if ( GNB_PF_FWD_INET == pf_ctx_st.pf_fwd && NULL != pf_ctx_st.fwd_node && NULL != pf_ctx_st.fwd_payload ) {
gnb_forward_payload_to_node(gnb_core, pf_ctx_st.fwd_node, pf_ctx_st.fwd_payload);
pf_inet_forwad_status = GNB_PF_INET_FORWARD_TO_INET;
gnb_core->local_node->out_bytes += pf_ctx_st.ip_frame_size;
pf_ctx_st.fwd_node->in_bytes += pf_ctx_st.ip_frame_size;
GNB_LOG3(gnb_core->log, GNB_LOG_ID_PF, "<*< inet payload forward to inet src=%llu dst=%llu fwd=%llu >*>\n", pf_ctx_st.src_uuid64, pf_ctx_st.dst_uuid64, fwd_uuid64);
}
pf_inet_finish:
if ( 1 == gnb_core->conf->if_dump ) {
GNB_LOG3(gnb_core->log, GNB_LOG_ID_PF, "inet src=%llu dst=%llu fwd=%llu [%s] [%s] [%s] ip_frame_size=%u\n",
pf_ctx_st.src_uuid64, pf_ctx_st.dst_uuid64, fwd_uuid64,
gnb_pf_status_strings[pf_inet_frame_status], gnb_pf_status_strings[pf_inet_route_status], gnb_pf_status_strings[pf_inet_forwad_status],
pf_ctx_st.ip_frame_size);
}
if ( 1 == gnb_core->conf->if_dump ) {
GNB_LOG3(gnb_core->log, GNB_LOG_ID_PF,"----- GNB PF INET END -----\n");
}
return;
}
void gnb_pf_release(gnb_core_t *gnb_core, gnb_pf_array_t *pf_array){
int i;
for ( i=0; i<pf_array->num; i++ ) {
if ( NULL==pf_array->pf[i]->pf_release ) {
continue;
}
pf_array->pf[i]->pf_release(gnb_core, pf_array->pf[i]);
}
}