-
Notifications
You must be signed in to change notification settings - Fork 2
/
ip_rte_support.ex.c
12223 lines (10201 loc) · 438 KB
/
ip_rte_support.ex.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
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* ip_rte_support.ex.c */
/* Support routines for ip_dispatch and its associated child processes */
/****************************************/
/* Copyright (c) 1987-2005 */
/* by OPNET Technologies, Inc. */
/* (A Delaware Corporation) */
/* 7255 Woodmont Av., Suite 250 */
/* Bethesda, MD 20814, U.S.A. */
/* All Rights Reserved. */
/****************************************/
/* ---- (SECTION_INC) Include Directives ---- */
#include <string.h>
#include <opnet.h>
#include <ip_rte_support.h>
#include <mpls_support.h>
#include <ip_addr_v4.h>
#include <oms_bgutil.h>
#include <ip_vrf_table.h>
#include <ip_te_support.h>
#include <ip_rte_v4.h>
#include <ip_rte_slot.h>
#include <oms_slot.h>
#include <ip_cmn_rte_table.h>
#include <ip_rte_table_v4.h>
#include <dsr_pkt_support.h>
#include <ip_mcast_support.h>
#include <ip_sim_attr_cache.h>
#include <ip_ot_support.h>
#include <manet_tora_imep.h>
#include <mobile_ip_support.h>
#include <ip_notif_log_support.h>
#include <oms_rr.h>
#include <umts_gtp_support.h>
#include <ip_firewall.h>
#include <aodv.h>
#include <aodv_ptypes.h>
#include <aodv_pkt_support.h>
#include <mpls_path_support.h>
#include <ip_grouping.h>
#include <mipv6_signaling_sup.h>
#include <mipv6_support.h>
#include <oms_dl.h>
#define IPC_TRACER_RATIO_INVALID -1.0
/* ---- Internal Data types ---- */
typedef enum IpT_Support_Intf_Type
{
IpC_Support_Intf_Type_Physical = 0,
IpC_Support_Intf_Type_Loopback = 1,
IpC_Support_Intf_Type_Tunnel = 2,
IpC_Support_Intf_Type_Virtual = 3,
IpC_Support_Intf_Type_Aggregate = 4,
IpC_Support_Intf_Type_Number
} IpT_Support_Intf_Type;
#define NUM_INTERFACE_TYPES IpC_Support_Intf_Type_Number
static const char* local_intf_name = "Local";
typedef struct IpT_Rte_Datagram_Dest_Get_Args
{
IpT_Rte_Module_Data* iprmd_ptr;
Packet* pkptr;
Ici* rsvp_ici_ptr;
InetT_Address dest_addr;
int input_intf_tbl_index;
Boolean packet_from_lower_layer;
int protocol_type;
InetT_Address* next_addr_ptr;
char** lsp_name_pstr;
Boolean* broadcast_ptr;
Boolean* higher_layer_ptr;
Boolean* destroy_pkt_ptr;
IpT_Port_Info* output_port_info_ptr;
IpT_Interface_Info** interface_ptr;
int* num_tracer_info_ptr;
IpT_Tracer_Info ** tracer_info_array_pptr;
char** drop_reason_pstr;
IpT_Rte_Proc_Id* src_proto_ptr;
} IpT_Rte_Datagram_Dest_Get_Args;
const char* intf_types_str_array [NUM_INTERFACE_TYPES] = {"Interface Information", "Loopback Interfaces", "Tunnel Interfaces", "VLAN Interfaces", "Aggregate Interfaces"};
static Pmohandle objid_pmh;
static Boolean objid_pmh_initialized = OPC_FALSE;
static char intf_name_unknown_str[] = "Unknown";
static Boolean ip_rte_pkt_is_routing_pkt (IpT_Dgram_Fields* pk_fd_ptr);
static Boolean ip_rte_pkt_is_routing_pkt_ext (IpT_Dgram_Fields* pk_fd_ptr);
/* The following two addresses are used by MANET models. InetI_Imep_Mcast_Addr is used in this file also. */
/* Since ip_rte_support.ex.c is included in all layer-2 models, it is a good idea to define these variables */
/* in this file. That way, manet files need not be declared in all layer-2 process models. */
InetT_Address InetI_Imep_Mcast_Addr;
IpT_Address IpI_Imep_Mcast_Addr;
static const IpT_Rte_Proc_Id direct_routes_proto_id = IP_CMN_RTE_TABLE_UNIQUE_ROUTE_PROTO_ID (IPC_DYN_RTE_DIRECTLY_CONNECTED, IPC_NO_MULTIPLE_PROC);
static const IpT_Rte_Proc_Id local_routes_proto_id = IP_CMN_RTE_TABLE_UNIQUE_ROUTE_PROTO_ID (IPC_DYN_RTE_LOCAL, IPC_NO_MULTIPLE_PROC);
/* ---- (SECTION_LP) Local Prototypes ---- */
static void
ip_rte_total_packets_received_stat_update (IpT_Rte_Module_Data * iprmd_ptr, int pkt_dest_type,
Packet * pk_ptr, InetT_Addr_Family addr_family);
static void
ip_rte_dgram_options_process (IpT_Rte_Module_Data * iprmd_ptr, Packet* ip_pkptr, int output_table_index);
static Compcode
ip_rte_datagram_dest_get (IpT_Rte_Module_Data * iprmd_ptr, Packet* pkptr, Ici* rsvp_ici_ptr, Boolean force_fwd,
InetT_Address dest_addr, int input_intf_tbl_index, Boolean packet_from_lower_layer, IpT_Dgram_Fields* pk_fd_ptr,
IpT_Rte_Ind_Ici_Fields* ici_fdstruct_ptr, InetT_Address *next_addr_ptr,char** lsp_name_pstr, Boolean *broadcast_ptr,
Boolean *higher_layer_ptr, Boolean *destroy_pkt_ptr, IpT_Port_Info* output_port_info_ptr,
IpT_Interface_Info **interface_ptr, int * num_tracer_info_ptr,
IpT_Tracer_Info ** tracer_info_array_pptr, char** drop_reason_pstr, IpT_Rte_Proc_Id* src_proto_ptr,
IpT_Cmn_Rte_Table_Entry** route_entry_pptr);
static Compcode
ip_rte_gateway_datagram_dest_get (IpT_Rte_Module_Data* iprmd_ptr, Boolean force_fwd, Packet* pkptr,
InetT_Address dest_addr, Boolean packet_from_lower_layer, IpT_Dgram_Fields* pk_fd_ptr,
IpT_Rte_Ind_Ici_Fields* ici_fdstruct_ptr, InetT_Address *next_addr_ptr, char** lsp_name_pstr,
Boolean *broadcast_ptr, Boolean *higher_layer_ptr, Boolean *destroy_pkt_ptr,
IpT_Port_Info* output_port_info_ptr, IpT_Interface_Info **interface_pptr, int *num_tracer_info_ptr,
IpT_Tracer_Info** tracer_info_array_pptr, char** drop_reason_pstr, IpT_Rte_Proc_Id* src_proto_ptr,
IpT_Cmn_Rte_Table_Entry** route_entry_pptr);
static Compcode
ip_rte_datagram_to_direct_connected_dest_handle (IpT_Rte_Module_Data* iprmd_ptr, Boolean force_fwd,
InetT_Address dest_addr, Boolean packet_from_lower_layer, InetT_Address *next_addr_ptr, Boolean *broadcast_ptr,
Boolean *higher_layer_ptr, Boolean *destroy_pkt_ptr, IpT_Port_Info* output_port_info_ptr,
IpT_Interface_Info **interface_pptr, char** drop_reason_pstr);
static Compcode
ip_rte_bgutil_packet_split (IpT_Rte_Module_Data* iprmd_ptr, InetT_Address* next_addr_ptr, IpT_Cmn_Rte_Table_Entry* route_entry_ptr,
Boolean* destroy_pkt_ptr, IpT_Port_Info* output_port_info_ptr, IpT_Interface_Info** interface_pptr, int* num_tracer_info_ptr,
IpT_Tracer_Info** tracer_info_array_pptr, char** drop_reason_pstr, IpT_Rte_Proc_Id* src_proto_ptr);
static Compcode
ip_rte_host_higher_layer_datagram_dest_get (IpT_Rte_Module_Data* iprmd_ptr, Boolean force_fwd,
InetT_Address dest_addr, int protocol_type, InetT_Address* next_addr_ptr, Boolean* broadcast_ptr,
Boolean* higher_layer_ptr, Boolean* destroy_pkt_ptr, IpT_Port_Info* output_port_info_ptr,
IpT_Interface_Info** interface_pptr, char** drop_reason_pstr, IpT_Rte_Proc_Id* src_proto_ptr);
static Compcode
ip_rte_host_lower_layer_datagram_dest_get (IpT_Rte_Module_Data* iprmd_ptr,
InetT_Address dest_addr, int protocol_type, InetT_Address* next_addr_ptr, Boolean* broadcast_ptr,
Boolean* higher_layer_ptr, Boolean* destroy_pkt_ptr, IpT_Port_Info* output_port_info_ptr,
IpT_Interface_Info** interface_pptr, char** drop_reason_pstr, IpT_Rte_Proc_Id* src_proto_ptr);
static Compcode
ip_rte_mcast_datagram_dest_get (IpT_Rte_Module_Data * iprmd_ptr, Packet* pkptr, Ici* rsvp_ici_ptr,
IpT_Rte_Ind_Ici_Fields* intf_ici_fdstruct_ptr, InetT_Address dest_addr,
InetT_Address* next_addr_ptr, Boolean* higher_layer_ptr, Boolean* destroy_pkt_ptr,
int protocol_type, int* output_table_index_ptr, IpT_Interface_Info** interface_pptr);
static double
ip_rte_decomp_delay_compute (Packet* pkptr, IpT_Dgram_Fields* pk_fd_ptr);
#if 0
static void
ip_unnumbered_intf_router_id_assign (IpT_Rte_Module_Data * iprmd_ptr);
#endif
static IpT_Address
ip_obtain_neighbor_router_id (IpT_Rte_Module_Data * iprmd_ptr, Objid link_objid);
static void
ip_rte_pk_fragment (IpT_Rte_Module_Data * iprmd_ptr, Packet *pk_ptr, int conn_class,
IpT_Rte_Ind_Ici_Fields* intf_ici_ptr);
static void
ip_rte_frag_send (IpT_Rte_Module_Data* iprmd_ptr, Packet* pk_ptr, InetT_Addr_Family addr_family,
int conn_class, IpT_Interface_Info* iface_info_ptr, IpT_Rte_Ind_Ici_Fields* intf_ici_ptr);
static void
ip_rte_pk_sent_stats_update (IpT_Rte_Module_Data* iprmd_ptr, Packet* pk_ptr,
int ip_queuing_scheme, int pk_tx_type, InetT_Addr_Family addr_family);
static void
ip_src_address_determine (InetT_Address *src_addr_ptr, IpT_Rte_Module_Data* iprmd_ptr, int intf_tbl_index,
InetT_Addr_Family addr_family);
static void
ip_inface_statistic_update (IpT_Rte_Module_Data * iprmd_ptr, IpT_Interface_Info* out_intf_info_ptr, double pkt_bitsize, Packet * pkptr);
static void
ip_forward_packet_to_output_queues (IpT_Rte_Module_Data * iprmd_ptr, Packet* pk_ptr, int outstrm,
Ici* iciptr, int pkt_txtype, IpT_Rte_Ind_Ici_Fields* intf_ici_fdstruct_ptr);
static void
ip_rte_ip_vpn_tunnel_packet (IpT_Rte_Module_Data * iprmd_ptr,
Packet** pkptr, double* tunnel_delay);
static void
ip_rte_packet_tunnel_proc (IpT_Rte_Module_Data* iprmd_ptr, Packet* inner_pkptr,
int instrm, InetT_Address next_addr, IpT_Interface_Info* tunnel_intf_ptr);
static void
ip_packet_tunnel (IpT_Rte_Module_Data* iprmd_ptr, Packet* inner_pkptr,
int instrm, InetT_Address next_addr, InetT_Address phys_addr, IpT_Interface_Info* tunnel_intf_ptr);
static Compcode
ip_rte_ipv6_manual_tunnel_pkt_fields_set (IpT_Dgram_Fields* pkt_fields_ptr, IpT_Interface_Info* tunnel_intf_ptr);
static Compcode
ip_rte_ipv6_auto_tunnel_pkt_fields_set (IpT_Dgram_Fields* pkt_fields_ptr, InetT_Address dest_addr,
IpT_Interface_Info* tunnel_intf_ptr);
static Compcode
ip_rte_ipv6_6to4_tunnel_pkt_fields_set (IpT_Dgram_Fields* pkt_fields_ptr, InetT_Address dest_addr,
IpT_Interface_Info* tunnel_intf_ptr);
static Packet*
ip_rte_tunnel_gre_pkt_create (Packet* tunneled_pkptr);
static void
ip_rte_load_balancer_handle_packet (IpT_Rte_Module_Data* module_data, Packet** pkptr);
static Boolean
ip_rte_load_balancer_packet_mine (const InetT_Address dest_address,
IpT_Rte_Module_Data *iprmd_ptr, int* table_index_ptr);
static void
ip_rte_load_balancer_log ();
static char*
ip_mpls_packet_classify (IpT_Rte_Module_Data* iprmd_ptr, Packet* pkt_ptr, int in_iface, Boolean higher_layer_pkt);
static Boolean
ip_rte_support_is_mpls_tracer (Packet* pkptr, char** fec_name_ptr);
int
ip_cmn_rte_table_entry_cost_get (IpT_Cmn_Rte_Table_Entry *rte_entry_ptr,int hop_index);
static void
ip_rte_flow_id_swap (OmsT_Bgutil_Tracer_Packet_Info* trc_pkt_info_ptr,
IpT_Interface_Info* interface_ptr, InetT_Address next_hop_addr);
static int
ip_rte_minor_port_from_next_hop_get (IpT_Rte_Module_Data* iprmd_ptr, int phys_intf_index, InetT_Address next_hop);
static Boolean
ip_mpls_lsp_status_get (IpT_Rte_Module_Data* iprmd_ptr, char* lsp_name_str, int in_iface);
static InetT_Address
ip_rte_support_next_hop_set (IpT_Rte_Module_Data* iprmd_ptr, InetT_Addr_Family addr_family,
const InetT_Address* addr_ptr, int* out_iface_ptr);
InetT_Address
ip_rte_next_hop_address_valid (IpT_Rte_Module_Data* iprmd_ptr, int intf_index);
static void
ip_rte_isis_pdu_send (IpT_Rte_Module_Data *iprmd_ptr, Packet *pk_ptr);
static void
ip_rte_isis_pdu_recv (IpT_Rte_Module_Data *iprmd_ptr, Packet *pk_ptr, IpT_Interface_Info* rcvd_intf_info_ptr,
int instrm, int input_intf_tbl_index, int minor_port_in);
static Compcode
ip_rte_pk_rcvd_intf_tbl_indx_get (IpT_Rte_Module_Data *iprmd_ptr, int instrm, IpT_Dgram_Fields* pk_fd_ptr,
Boolean tunnel_pkt_at_src, int *minor_port_ptr, int *input_intf_tbl_index_ptr);
void
ip_policy_action_into_list_insert (List* ip_policy_action_lptr, char* node_name, char* rte_map_filter_name,
const char* iface_name_str, IpT_Policy_Action policy_action);
static IpT_Policy_Action_Info*
ip_policy_action_info_mem_alloc (void);
static int
ip_rte_input_slot_index_determine (IpT_Rte_Module_Data *iprmd_ptr, IpT_Interface_Info* in_iface_ptr, int instrm);
static void
ip_rte_support_intf_objid_add (PrgT_String_Hash_Table* intf_name_htable_ptr, Objid intf_name_objid);
static Boolean
inet_rte_v6intf_addr_range_check (InetT_Address next_hop, IpT_Interface_Info* intf_ptr,
InetT_Address_Range** addr_range_pptr);
static Boolean
ipv6_rte_is_local_address(const InetT_Address intf_addr, IpT_Rte_Module_Data* iprmd_ptr,
int* intf_index_ptr);
static Boolean
ip_rte_subintf_layer2_mapping_found (const char* mapping_name, IpT_Layer2_Mapping mapping_type, IpT_Layer2_Mappings layer2_map);
static Boolean
ip_rte_support_number_range_match (IpT_Rte_Map_Match_Info* match_info_ptr, int number);
static IpT_Rte_Ind_Ici_Fields*
ip_rte_intf_ici_fdstruct_ptr_get (Packet* ip_dgram_ptr);
static void
ip_rte_lacp_pdu_handle (IpT_Rte_Module_Data* iprmd_ptr, Packet* pkptr);
static void
ip_rte_support_metric_string_get (int metric, char* metric_string);
static DciT_Protocol
ip_rte_support_protocol_type_get (int proto);
static IpT_Cmn_Rte_Table*
ip_rte_table_determine (IpT_Rte_Module_Data* iprmd_ptr, Packet* pkptr, IpT_Dgram_Fields* pk_fds_ptr, Boolean from_lower_layer);
/* ---- (SECTION_ECP) Externally Callable Procedures ---- */
void
ip_rte_set_procs (IpT_Rte_Module_Data * iprmd_ptr,
IpT_Rte_Error_Proc error_p, IpT_Rte_Warning_Proc warning_p)
{
/** Until a more comprehensive revisit of this code to **/
/** better repackage, we mimick what used to be a set **/
/** of process model state variables with a similar **/
/** structure that must be set by each model before **/
/** invoking any other function in this file. **/
FIN (ip_rte_set_procs (iprmd_ptr, error_p, warning_p));
iprmd_ptr->error_proc = error_p;
iprmd_ptr->warning_proc = warning_p;
FOUT;
}
Boolean
ip_interface_routing_protocols_contains (List* routing_protocols_lptr, int routing_protocol)
{
Boolean protocol_is_in_this_list;
int* i_th_protocol_ptr;
int i_th_protocol, num_rte_protocols;
/** Checks if the passed in routing protocol is not in the supplied list. **/
FIN (ip_interface_routing_protocols_contains (routing_protocols_lptr, routing_protocol));
/* Check for NIL list */
if (routing_protocols_lptr == OPC_NIL)
FRET (OPC_FALSE);
/* Assume that the passed in routing protocol is not in the supplied list. */
protocol_is_in_this_list = OPC_FALSE;
/* Loop though the different number of routing protocols */
/* running on this interface. */
num_rte_protocols = op_prg_list_size (routing_protocols_lptr);
for (i_th_protocol = 0; i_th_protocol < num_rte_protocols; i_th_protocol++)
{
/* Access the first specification -- this element will */
/* be a pointer to the routing protocol ID. */
i_th_protocol_ptr = (int *) op_prg_list_access (routing_protocols_lptr, i_th_protocol);
/* Check if the supplied protocol is same as this. There is */
/* a special case when a custom routing protocol is used. */
if (routing_protocol == IpC_Rte_Custom &&
*i_th_protocol_ptr >= IPC_INITIAL_CUSTOM_RTE_PROTOCOL_ID)
{
protocol_is_in_this_list = OPC_TRUE;
break;
}
else
{
/* this must be standard routing protocol (e.g., OSPF). */
if (*i_th_protocol_ptr == routing_protocol)
{
protocol_is_in_this_list = OPC_TRUE;
break;
}
}
}
FRET (protocol_is_in_this_list);
}
IpT_Intf_Name_Objid_Table_Handle
ip_rte_proto_intf_attr_objid_table_build (Objid proto_params_objid)
{
PrgT_String_Hash_Table* intf_name_htable_ptr;
Objid intf_info_objid;
Objid subintf_info_objid;
int intf_info_cattr_size;
int subintf_info_cattr_size;
Objid intf_attr_objid;
int intf_type, j, k;
int num_entries = 0;
/** This function creates a lookup table for mapping between **/
/** an Interface name and the objid of the corresponding **/
/** interface under the protocol Parameters of a particular **/
/** protocol e.g. RIP Parameters. The attributes must be in the **/
/** standard form. i.e the given object must have a compound **/
/** attribute named "Interface Information". Each row of this **/
/** attriubte must have an attribute name "Name" whose value **/
/** would be the name of an interface on this node. **/
/** Subinterfaces (if any) must be specified under an attribute **/
/** named "Subinterface Information". But it is not required. **/
/** This funciton also handles Loopback and Tunnel interfaces. **/
/** But it is not required that the given object have attributes**/
/** named "Loopback Interfaces" or "Tunnel Interfaces". **/
/** The function named ip_rte_proto_intf_attr_objid_table_lookup**/
/** can be used to look up the objid of a particular interface **/
/** in the table returned by this function. **/
/** The table thus created must be destroyed by calling **/
/** ip_rte_proto_intf_attr_objid_table_destroy to avoid a **/
/** memory leak. **/
FIN (ip_rte_proto_intf_attr_objid_table_build (proto_params_objid));
/* Initialize the Pool memory object handle if it is not already */
/* initialized. */
if (OPC_FALSE == objid_pmh_initialized)
{
objid_pmh = op_prg_pmo_define ("Interface Objid", sizeof (Objid), 50);
objid_pmh_initialized = OPC_TRUE;
}
/* Create a hash table to store the objid corresponding to */
/* each interface name. */
intf_name_htable_ptr = prg_string_hash_table_create (50, 25);
/* Get the objids of the "Interface Information", */
/* "Loopback Interfaces", "Tunnel Interfaces" and "VLAN */
/* Interfaces" attributes. */
for (intf_type = 0; intf_type < NUM_INTERFACE_TYPES; intf_type++)
{
/* Make sure there is an attribute corresponing to this */
/* interface type under this protocol's parameters. */
if (op_ima_obj_attr_exists (proto_params_objid, intf_types_str_array [intf_type]))
{
op_ima_obj_attr_get (proto_params_objid, intf_types_str_array [intf_type], &(intf_info_objid));
/* Find out the number of rows under this attribute. */
intf_info_cattr_size = op_topo_child_count (intf_info_objid, OPC_OBJTYPE_GENERIC);
/* Loop through all the rows and read in their names */
for (j = 0; j < intf_info_cattr_size; j++)
{
/* Get the object ID of the jth row. */
intf_attr_objid = op_topo_child (intf_info_objid, OPC_OBJTYPE_GENERIC, j);
/* Add this row to the hash table. */
ip_rte_support_intf_objid_add (intf_name_htable_ptr, intf_attr_objid);
++num_entries;
/* For physical interfaces we need to go through */
/* the list of Subinterfaces also. */
if ((IpC_Support_Intf_Type_Physical == intf_type) &&
(op_ima_obj_attr_exists (intf_attr_objid, "Subinterface Information")))
{
/* Get the object Id of the subinterface */
/* information attribute. */
op_ima_obj_attr_get (intf_attr_objid, "Subinterface Information", &subintf_info_objid);
/* Get the number of subinterfaces. */
subintf_info_cattr_size = op_topo_child_count (subintf_info_objid, OPC_OBJTYPE_GENERIC);
/* Loop through the subinterfaces and add them */
/* also to the hash table. */
for (k = 0; k < subintf_info_cattr_size; k++)
{
/* Get the object ID of the ith row. */
intf_attr_objid = op_topo_child (subintf_info_objid, OPC_OBJTYPE_GENERIC, k);
/* Add this row to the hash table. */
ip_rte_support_intf_objid_add (intf_name_htable_ptr, intf_attr_objid);
++num_entries;
}
}
}
}
}
/* If the hash table is empty, delete it. */
if (0 == num_entries)
{
prg_string_hash_table_free (intf_name_htable_ptr);
intf_name_htable_ptr = IpC_Intf_Name_Objid_Table_Invalid;
}
/* Return the hash table. */
FRET (intf_name_htable_ptr);
}
int
ip_rte_proto_intf_attr_objid_table_size (IpT_Intf_Name_Objid_Table_Handle table_handle)
{
PrgT_List* key_lptr;
int table_size;
/** Return the number of entries in the table. **/
FIN (ip_rte_proto_intf_attr_objid_table_size (table_handle));
/* Currently there is no function that will directly give the */
/* the number of entries in the hash table. So we have to */
/* create the list of keys and get its size. */
/* Get the list of keys. */
key_lptr = prg_string_hash_table_keys_get (table_handle);
/* The size of the table is the number of keys. */
table_size = prg_list_size (key_lptr);
/* Free the memory allocated to the list. */
prg_list_free (key_lptr);
prg_mem_free (key_lptr);
/* Return the number of entries in the table. */
FRET (table_size);
}
Objid
ip_rte_proto_intf_attr_objid_table_lookup_by_name (IpT_Intf_Name_Objid_Table_Handle intf_name_htable_ptr,
const char* interface_name)
{
Objid* intf_objid_ptr;
Objid intf_attr_objid;
/** This function is used to obtain the objid of a row from the **/
/** table created using the **/
/** ip_rte_proto_intf_attr_objid_table_build function. If a **/
/** matching element is not found, OPC_OBJID_INVALID will be **/
/** returned. **/
FIN (ip_rte_proto_intf_attr_objid_table_lookup_by_name (intf_name_htable_ptr, ip_iface_elem_ptr));
/* We do not need to handle the case where the hash table is */
/* NIL, because that case is handled by the */
/* prg_string_hash_table_item_get function. */
/* Look for a matching entry in the hash table. */
intf_objid_ptr = (Objid*) prg_string_hash_table_item_get (intf_name_htable_ptr, interface_name);
/* If no matching entry was found, return OPC_OBJID_INVALID */
if (OPC_NIL == intf_objid_ptr)
{
intf_attr_objid = OPC_OBJID_INVALID;
}
else
{
/* We found a match return the stored value. */
intf_attr_objid = *intf_objid_ptr;
}
FRET (intf_attr_objid);
}
void
ip_rte_proto_intf_attr_objid_table_destroy (IpT_Intf_Name_Objid_Table_Handle intf_name_htable_ptr)
{
/** Frees the memory allocated to a table created using **/
/** ip_rte_proto_intf_attr_objid_table_build. **/
FIN (ip_rte_proto_intf_attr_objid_table_destroy (intf_name_htable_ptr));
prg_string_hash_table_free_proc (intf_name_htable_ptr, op_prg_mem_free);
FOUT;
}
static void
ip_rte_support_intf_objid_add (PrgT_String_Hash_Table* intf_name_htable_ptr, Objid intf_attr_objid)
{
void* old_objid_ptr;
char intf_name [128];
Objid* intf_objid_ptr;
/** This function adds the given interface name to the hash table. **/
FIN (ip_rte_support_intf_objid_add (intf_name_htable_ptr, intf_name_objid));
/* Allocate enough memory to hod the object ID. */
intf_objid_ptr = (Objid*) op_prg_pmo_alloc (objid_pmh);
*intf_objid_ptr = intf_attr_objid;
/* Get the name of this interface. */
op_ima_obj_attr_get (intf_attr_objid, "Name", intf_name);
/* Create a hash table entry corresponding to this interface */
prg_string_hash_table_item_insert (intf_name_htable_ptr, intf_name, intf_objid_ptr, &old_objid_ptr);
if (old_objid_ptr != OPC_NIL)
{
ipnl_dupl_intf_name_error (intf_attr_objid, intf_name);
}
FOUT;
}
IpT_Packet_Format
ip_rte_packet_format_valid (IpT_Rte_Module_Data * iprmd_ptr,Packet * pkptr)
{
static Boolean ip_error_message_printed = OPC_FALSE;
char ip_packet_format [256];
/** Check if the given packet is of a format that can be **/
/** handled by the IP module. **/
FIN (ip_rte_packet_format_valid (pkptr));
/* Obtain the format of the packet. */
op_pk_format (pkptr, ip_packet_format);
/* Check if the packet is an IP datagram. */
if (strcmp (ip_packet_format, "ip_dgram_v4") == 0)
{
/* The packet is an IP datagram. */
FRET (IpC_Packet_Format_Ip_Dgram);
}
/* Check if the packet is an LACP PDU. */
else if (strcmp (ip_packet_format, "lac_pdu") == 0)
{
/* This is an LACP PDU. */
FRET (IpC_Packet_Format_Lacp_Pdu);
}
else
{
/* Invalid packet format. */
/* Print this error message only once. */
if (ip_error_message_printed == OPC_FALSE)
{
/* Print a warning message in the simulation log. */
ipnl_protwarn_pkformat (op_pk_id (pkptr), op_pk_tree_id (pkptr),
ip_packet_format);
ip_error_message_printed = OPC_TRUE;
}
/* Destroy the packet and update statistics. */
ip_rte_dgram_discard (iprmd_ptr, pkptr, OPC_NIL,
"Non IP packet received" /* Reason for drop */);
FRET (IpC_Packet_Format_Invalid);
}
}
Boolean
ip_rte_packet_arrival (IpT_Rte_Module_Data * iprmd_ptr,
Packet ** pkpptr, int instrm,
IpT_Rte_Ind_Ici_Fields ** intf_ici_fdstruct_pptr,
IpT_Interface_Info **rcvd_iface_info_pptr)
{
Boolean ip_rte_trace;
IpT_Dgram_Fields* pk_fd_ptr;
/* IP datagrams maintain an ICI to record information */
/* required for proper routing (e.g., slot on which the */
/* datagram arrived, output interface on which it */
/* should be forwarded, etc.) -- all that information */
/* is stored in a single structure field of the */
/* ip_rte_ind_v4 ICI. */
IpT_Rte_Ind_Ici_Fields *intf_ici_fdstruct_ptr;
Boolean packet_from_lower_layer;
double proxy_delay = 0.0;
Ici* rsvp_ici_ptr = OPC_NIL;
Ici* mcast_ici_ptr;
int mcast_major_port;
int mcast_minor_port;
IpT_Interface_Info* iface_info_ptr = OPC_NIL;
int slot_index = -1;
Ici* intf_ici_ptr = OPC_NIL;
int minor_port_in;
char trace_msg [128];
char intf_addr_str [INETC_ADDR_STR_LEN];
InetT_Address dest_addr;
InetT_Addr_Family addr_family;
InetT_Address next_addr = INETC_ADDRESS_INVALID;
Boolean broadcast = OPC_FALSE;
Boolean higher_layer = OPC_FALSE;
Boolean destroy_pkt = OPC_FALSE;
Boolean multicast_dest_addr;
char dest_addr_str [INETC_ADDR_STR_LEN];
int pkt_dest_type;
Boolean force_fwd;
IpT_Interface_Info* interface_ptr = OPC_NIL;
Compcode got_datagram_info;
double decomp_delay;
double comp_delay = 0.0;
OpT_Packet_Size packet_size;
Boolean car_packet_drop;
char str0 [512];
double vpn_delay = 0.0;
IpT_Address lb_addr;
Boolean packet_is_labeled;
Boolean packet_from_manet = OPC_FALSE;
char* fec_name = OPC_NIL;
int num_tracer_info = 0;
IpT_Tracer_Info * tracer_info_array = OPC_NIL;
int input_intf_tbl_index = IPC_INTF_INDEX_INVALID;
int output_table_index = IPC_INTF_INDEX_INVALID;
char* vrf_name = OPC_NIL;
char* lsp_name_str = OPC_NIL;
char* drop_reason_str = OPC_NIL;
InetT_Address rte_map_next_addr = INETC_ADDRESS_INVALID;
int rte_map_output_table_index = IPC_INTF_INDEX_INVALID;
IpT_Rte_Table_Lookup route_table_lookup = IpC_Rte_Table_Lookup;
IpT_Rte_Proc_Id src_proto = 0;
char* policy_name;
Packet * bgutil_pkptr;
IpT_Port_Info output_port_info;
char msg0 [512];
Compcode status;
Boolean permitted;
Boolean filter_present = OPC_FALSE;
IpT_Acl_List* matched_acl_ptr = OPC_NIL;
const char* input_intf_name;
Compcode src_nat_status = OPC_COMPCODE_FAILURE;
Compcode dest_nat_status = OPC_COMPCODE_FAILURE;
const char* protocol_name;
Boolean src_xlate_match = OPC_FALSE;
Boolean dest_xlate_match = OPC_FALSE;
int vmac_addr = -1;
Boolean tunnel_pkt_at_src;
IpT_Cmn_Rte_Table_Entry* route_entry_ptr = OPC_NIL;
int member_intf_index;
IpT_Group_Intf_Info* intf_group_info_ptr;
int ip_encap_out_index = IPC_INTF_INDEX_INVALID;
Ici* ip_encap_ici_ptr = OPC_NIL;
InetT_Address_Range* output_addr_range_ptr;
// JPH SMF - Flag that indicates SMF operation
Boolean smf_enabled = OPC_FALSE;
/** Perform the appropriate preprocessing on arriving packets **/
/** to either discard the unwanted packet or gather necessary **/
/** information for further routing. **/
/** The packet is expected to be in the ip_dgram_v4 format **/
FIN (ip_rte_packet_arrival (pkpptr, instrm, intf_ici_fdstruct_pptr,
iface_info_pptr));
/* Make sure that the packet format is valid. */
switch (ip_rte_packet_format_valid (iprmd_ptr, *pkpptr))
{
case IpC_Packet_Format_Lacp_Pdu:
/* Pass the packet to the approprite process. */
ip_rte_lacp_pdu_handle (iprmd_ptr, *pkpptr);
/* Return false to indicate that no further processing */
/* is necessary. */
FRET (OPC_FALSE);
case IpC_Packet_Format_Ip_Dgram:
/* Continue processing. */
break;
case IpC_Packet_Format_Invalid:
/* Invalid packet format. The packet would have been */
/* already destroyed. */
FRET (OPC_FALSE);
}
/* Check if this is a bgutil packet. */
if (op_pk_encap_flag_is_set (*pkpptr, OMSC_BGUTIL_ENCAP_FLAG_INDEX))
{
/* Get a copy of the bgutil packet. */
op_pk_encap_pk_get (*pkpptr, "bgutil_tracer", &bgutil_pkptr);
/* Update the segmentation information in the tracer packet. */
oms_bgutil_segmentation_info_update (bgutil_pkptr, OPC_NIL, OmsC_Tracer_IP,
ip_dgram_overhead_bits_get (*pkpptr), OMSC_BGUTIL_DO_NOT_SEGMENT, 0.0,
oms_bgutil_tracer_segment_func, OPC_FALSE, OPC_NIL);
/* Destroy the copy packet. */
op_pk_destroy (bgutil_pkptr);
}
/* Initialize return information */
*intf_ici_fdstruct_pptr = OPC_NIL;
/* Get a handle to the data structure stored in "fields" */
/* field. This structure contains all the protocol header */
/* information as well as some internal information */
/* attached to each IP datagram for simulation efficiency. */
op_pk_nfd_access (*pkpptr, "fields", &pk_fd_ptr);
/* Find out whether this is an IPv4 packet of an IPv6 packet*/
addr_family = inet_address_family_get (&(pk_fd_ptr->dest_addr));
/* If this is a packet being tunneled from this node, then we */
/* need to bypass policy routing etc. since this packet has */
/* been delivered by this node back to this node, but on the */
/* stream on which the original packet had arrived previously. */
/* Also, if this is a v4 packet that contains a v6 packet, we */
/* must accept this packet even if the interface is not */
/* configured to handle v4 traffic. We must do this because the */
/* packet has been internally delivered to this interface by */
/* the tunneling code and has not actually come from the */
/* network. In order to help in these decisions, we need to */
/* know if this is a tunnel packet at the source. */
tunnel_pkt_at_src = pk_fd_ptr->tunnel_pkt_at_src;
/* Since the packet is going out of the source node, this field */
/* must be reset. */
pk_fd_ptr->tunnel_pkt_at_src = OPC_FALSE;
/* First find out whether or not the packet came from the */
/* lower layer. */
if ((iprmd_ptr->instrm_from_ip_encap == instrm) ||
(IpC_Pk_Instrm_Child == instrm))
{
/* The packet did not come from the lower layer */
packet_from_lower_layer = OPC_FALSE;
/* Check here if the packet is not control packet, */
/* Add the source node stat handler to IP header field */
if (ip_rte_pkt_is_routing_pkt_ext (pk_fd_ptr) == OPC_FALSE)
{
/* Store source stat handle */
pk_fd_ptr->src_num_hops_stat_hndl_ptr = &iprmd_ptr->locl_num_hops_src_hndl;
}
}
else
{
/* Packet is from the lower layer. */
packet_from_lower_layer = OPC_TRUE;
/* This packet came from a lower layer (e.g., ARP.) */
/* Check to see which interface it arrived on, so we */
/* can potentially forward this information to the */
/* higher layer (if the packet is eventually bound for */
/* the higher layer). */
if (ip_rte_pk_rcvd_intf_tbl_indx_get (iprmd_ptr, instrm, pk_fd_ptr, tunnel_pkt_at_src,
&minor_port_in, &input_intf_tbl_index) == OPC_COMPCODE_FAILURE)
{
ip_rte_dgram_discard (iprmd_ptr, *pkpptr, intf_ici_ptr, "Minor port could not be determined");
FRET (OPC_FALSE);
}
/* Get a pointer to the interface information of the */
/* corresponding interface. */
iface_info_ptr = inet_rte_intf_tbl_access (iprmd_ptr, input_intf_tbl_index);
*rcvd_iface_info_pptr = iface_info_ptr;
/* If this packet has come in on a serial interface, adjust */
/* the packet size to model stripping of the PPP header. */
/* Do this before the code branches off in IS-IS packets, */
/* labeled MPLS packets etc. */
/* If a packet is to be sent out over a tunnel, then the */
/* node delivers the packet to itself, on the original */
/* incoming interface. In such a case, we have already */
/* decremented the overhead for the first packet. We must */
/* not decrement the header size again. */
if (!tunnel_pkt_at_src)
ip_rte_link_header_size_adjust (*pkpptr, iface_info_ptr, IpC_Header_Remove);
// JPH SMF - test for SMF operation
if (iprmd_ptr->gateway_status == OPC_TRUE && ip_rte_intf_mcast_enabled(iface_info_ptr))
smf_enabled = OPC_TRUE;
// end JPH SMF
}
/* Check if this packet came from ISIS */
if (pk_fd_ptr->protocol == IpC_Protocol_Isis)
{
/** If it is an ISIS PDU, don't do any IP processing **/
/** at all -- send the PDU out/up immediately. **/
/** The IP protocol is used only as a delivery **/
/** mechanism from the neighbor. **/
if (packet_from_lower_layer == OPC_FALSE)
{
ip_rte_isis_pdu_send (iprmd_ptr, *pkpptr);
}
else
{
ip_rte_isis_pdu_recv (iprmd_ptr, *pkpptr, iface_info_ptr, instrm, input_intf_tbl_index, minor_port_in);
}
/* Return an OPC_FALSE so that it fools the parent */
/* function into thinking that this pk was dropped */
/* and that no further processing is necessary. */
FRET (OPC_FALSE);
}
/* Mobile IPv6 processing. The following processing just applies */
/* for IPv6 packets if MIPv6 is enabled in the current node. Also */
/* multicast and local link addresses are not currently supported */
/* by MIPv6. */
if (ip_rte_node_is_mipv6_enabled (iprmd_ptr) &&
inet_address_family_get (&(pk_fd_ptr->dest_addr)) == InetC_Addr_Family_v6 &&
!inet_address_is_multicast (pk_fd_ptr->dest_addr) &&
!inet_rte_ipv6_addr_is_link_local (pk_fd_ptr->dest_addr))
{
mipv6_sup_mobile_ipv6_packet_process (iprmd_ptr, &pk_fd_ptr, pkpptr, packet_from_lower_layer);
}
/* obtain whether the label trace for "ip_rte" is enabled */
ip_rte_trace = LTRACE_IP_ACTIVE;
/* Initialize output_port_info. Details are populated while performing */
/* route table lookup for unicast destinations. */
output_port_info = ip_rte_port_info_create (IPC_INTF_INDEX_INVALID, OPC_NIL);
/* If this is a labeled packet none of the IP header fields */
/* would be visible. This will have an effect on the down */
/* the line processing of this packet */
packet_is_labeled = op_pk_nfd_is_set (*pkpptr, "MPLS Shim Header");
/* The cases GTP, L2TP and firewall cases must be handled only */
/* if this is an IP packet and not an MPLS packet. We also need */
/* not consider the following cases if this is a tunnel packet */
/* that has been created by this node and delivered to itself */
/* after encapsulation. These conditions will not hold good for */
/* the GRE/IP-IP tunnel packet. */
if ((!packet_is_labeled) && (!tunnel_pkt_at_src))
{
/* If the node containing this IP module is a firewall then */
/* we need to check whether the arriving packet will be */
/* accepted by the proxy servers. */
if (ip_node_is_firewall (iprmd_ptr) &&
(!oms_dv_firewall_accept (*pkpptr, iprmd_ptr->proxy_info_table_lptr, &proxy_delay)))
{
/* The datagram could not make through the firewall. */
/* Destroy the packet and update the statistics. Also */
/* record that into the simulation log. */
ip_rte_dgram_discard (iprmd_ptr, *pkpptr, OPC_NIL, "Rejected at Firewall");
ipnl_firewall_dgram_reject_log_write ();
/* Indicate that the packet insertion failed. */
FRET (OPC_FALSE);
}
/* Check if this is an UMTS GGSN node. */
if (ip_gtp_is_enabled (iprmd_ptr))
{
/* See if the destination belongs to the UMTS network. */
/* Home Locator Register contains all UEs registered in */
/* the UMTS network. */
if (umts_gtp_support_hlr_entry_find (inet_ipv4_address_get (pk_fd_ptr->dest_addr)) == OPC_TRUE)
{
/* The destnation address belong to a UMTS node, */
/* deliver the datagram to the GTP module to be */
/* transported into GTP tunnels through the UMTS */
/* core network. */
umts_gtp_support_gtp_pdu_send (*pkpptr, iprmd_ptr->gtp_info_ptr->gtp_objid);
/* Return an OPC_FALSE so that it fools the parent */
/* function into thinking that this pk was dropped */
/* and that no further processing is necessary. */
FRET (OPC_FALSE);
}
}
/* Check IP VPN tunneling is enabled, there might be delay */
/* associated with encryption and decryption process. */
if (ip_l2tp_vpn_is_enabled (iprmd_ptr) &&
(OPC_TRUE == packet_from_lower_layer))
{
/* Get delay associated to VPN tunnel */
ip_rte_ip_vpn_tunnel_packet (iprmd_ptr, pkpptr, &vpn_delay);
/* The pkpptr might be replaced by a new IP packet if */
/* compulsory tunnel is used, refresh the pk_fd_ptr */
op_pk_nfd_access (*pkpptr, "fields", &pk_fd_ptr);
}
}
/* Create an ICI and associate it with the datagram. */
/* The ICI will carry information about the datagram */
/* that will be used later when processing the packet */
/* after queueing and forwarding to the output */
/* interface. */
intf_ici_ptr = op_ici_create ("ip_rte_ind_v4");
/* Create ip_rte_ind ICI fields data structure that */
/* contains routing information which is used during */
/* the life-cycle of the ICI in this process. */
intf_ici_fdstruct_ptr = ip_rte_ind_ici_fdstruct_create ();
*intf_ici_fdstruct_pptr = intf_ici_fdstruct_ptr;
intf_ici_fdstruct_ptr->instrm = instrm;
/* Set the rte_info_fields in the ICI. */
ip_rte_ind_ici_fields_set (intf_ici_ptr, intf_ici_fdstruct_ptr);
/* Set the ICI in the packet. */
op_pk_ici_set (*pkpptr, intf_ici_ptr);
/* We have now created the ICI structure and associated */
/* it with the packet. If it is a labeled packet, we */
/* can now exit out of this function, since further */
/* processing is not required. */
if (packet_is_labeled)
{
intf_ici_fdstruct_ptr->packet_is_labeled = OPC_TRUE;
intf_ici_fdstruct_ptr->intf_recvd_index = input_intf_tbl_index;
intf_ici_fdstruct_ptr->interface_received = inet_rte_intf_addr_get (iface_info_ptr, addr_family);
if (ip_mpls_is_enabled (iprmd_ptr))
{
intf_ici_fdstruct_ptr->mpls_redirect = OPC_TRUE;
}
else
{
intf_ici_fdstruct_ptr->destroy_pkt = OPC_TRUE;
intf_ici_fdstruct_ptr->drop_reason = prg_string_copy ("Labeled packet received on non MPLS enabled node");
}
FRET (OPC_TRUE);