forked from vyos-legacy/vyatta-quagga
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathisis_pdu.c
2622 lines (2307 loc) · 68.1 KB
/
isis_pdu.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
/*
* IS-IS Rout(e)ing protocol - isis_pdu.c
* PDU processing
*
* Copyright (C) 2001,2002 Sampo Saaristo
* Tampere University of Technology
* Institute of Communications Engineering
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public Licenseas published by the Free
* Software Foundation; either version 2 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, write to the Free Software Foundation, Inc.,
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <zebra.h>
#include "memory.h"
#include "thread.h"
#include "linklist.h"
#include "log.h"
#include "stream.h"
#include "vty.h"
#include "hash.h"
#include "prefix.h"
#include "if.h"
#include "checksum.h"
#include "isisd/dict.h"
#include "isisd/include-netbsd/iso.h"
#include "isisd/isis_constants.h"
#include "isisd/isis_common.h"
#include "isisd/isis_adjacency.h"
#include "isisd/isis_circuit.h"
#include "isisd/isis_network.h"
#include "isisd/isis_misc.h"
#include "isisd/isis_dr.h"
#include "isisd/isis_flags.h"
#include "isisd/isis_tlv.h"
#include "isisd/isisd.h"
#include "isisd/isis_dynhn.h"
#include "isisd/isis_lsp.h"
#include "isisd/isis_pdu.h"
#include "isisd/iso_checksum.h"
#include "isisd/isis_csm.h"
#include "isisd/isis_events.h"
extern struct thread_master *master;
extern struct isis *isis;
#define ISIS_MINIMUM_FIXED_HDR_LEN 15
#define ISIS_MIN_PDU_LEN 13 /* partial seqnum pdu with id_len=2 */
#ifndef PNBBY
#define PNBBY 8
#endif /* PNBBY */
/* Utility mask array. */
static const u_char maskbit[] = {
0x00, 0x80, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc, 0xfe, 0xff
};
/*
* HELPER FUNCS
*/
/*
* Compares two sets of area addresses
*/
static int
area_match (struct list *left, struct list *right)
{
struct area_addr *addr1, *addr2;
struct listnode *node1, *node2;
for (ALL_LIST_ELEMENTS_RO (left, node1, addr1))
{
for (ALL_LIST_ELEMENTS_RO (right, node2, addr2))
{
if (addr1->addr_len == addr2->addr_len &&
!memcmp (addr1->area_addr, addr2->area_addr, (int) addr1->addr_len))
return 1; /* match */
}
}
return 0; /* mismatch */
}
/*
* Check if ip2 is in the ip1's network (function like Prefix.h:prefix_match() )
* param ip1 the IS interface ip address structure
* param ip2 the IIH's ip address
* return 0 the IIH's IP is not in the IS's subnetwork
* 1 the IIH's IP is in the IS's subnetwork
*/
static int
ip_same_subnet (struct prefix_ipv4 *ip1, struct in_addr *ip2)
{
u_char *addr1, *addr2;
int shift, offset, offsetloop;
int len;
addr1 = (u_char *) & ip1->prefix.s_addr;
addr2 = (u_char *) & ip2->s_addr;
len = ip1->prefixlen;
shift = len % PNBBY;
offsetloop = offset = len / PNBBY;
while (offsetloop--)
if (addr1[offsetloop] != addr2[offsetloop])
return 0;
if (shift)
if (maskbit[shift] & (addr1[offset] ^ addr2[offset]))
return 0;
return 1; /* match */
}
/*
* Compares two set of ip addresses
* param left the local interface's ip addresses
* param right the iih interface's ip address
* return 0 no match;
* 1 match;
*/
static int
ip_match (struct list *left, struct list *right)
{
struct prefix_ipv4 *ip1;
struct in_addr *ip2;
struct listnode *node1, *node2;
if ((left == NULL) || (right == NULL))
return 0;
for (ALL_LIST_ELEMENTS_RO (left, node1, ip1))
{
for (ALL_LIST_ELEMENTS_RO (right, node2, ip2))
{
if (ip_same_subnet (ip1, ip2))
{
return 1; /* match */
}
}
}
return 0;
}
/*
* Checks whether we should accept a PDU of given level
*/
static int
accept_level (int level, int circuit_t)
{
int retval = ((circuit_t & level) == level); /* simple approach */
return retval;
}
int
authentication_check (struct isis_passwd *one, struct isis_passwd *theother)
{
if (one->type != theother->type)
{
zlog_warn ("Unsupported authentication type %d", theother->type);
return 1; /* Auth fail (different authentication types) */
}
switch (one->type)
{
case ISIS_PASSWD_TYPE_CLEARTXT:
if (one->len != theother->len)
return 1; /* Auth fail () - passwd len mismatch */
return memcmp (one->passwd, theother->passwd, one->len);
break;
default:
zlog_warn ("Unsupported authentication type");
break;
}
return 0; /* Auth pass */
}
/*
* Processing helper functions
*/
static void
tlvs_to_adj_nlpids (struct tlvs *tlvs, struct isis_adjacency *adj)
{
int i;
struct nlpids *tlv_nlpids;
if (tlvs->nlpids)
{
tlv_nlpids = tlvs->nlpids;
adj->nlpids.count = tlv_nlpids->count;
for (i = 0; i < tlv_nlpids->count; i++)
{
adj->nlpids.nlpids[i] = tlv_nlpids->nlpids[i];
}
}
}
static void
del_ip_addr (void *val)
{
XFREE (MTYPE_ISIS_TMP, val);
}
static void
tlvs_to_adj_ipv4_addrs (struct tlvs *tlvs, struct isis_adjacency *adj)
{
struct listnode *node;
struct in_addr *ipv4_addr, *malloced;
if (adj->ipv4_addrs)
{
adj->ipv4_addrs->del = del_ip_addr;
list_delete (adj->ipv4_addrs);
}
adj->ipv4_addrs = list_new ();
if (tlvs->ipv4_addrs)
{
for (ALL_LIST_ELEMENTS_RO (tlvs->ipv4_addrs, node, ipv4_addr))
{
malloced = XMALLOC (MTYPE_ISIS_TMP, sizeof (struct in_addr));
memcpy (malloced, ipv4_addr, sizeof (struct in_addr));
listnode_add (adj->ipv4_addrs, malloced);
}
}
}
#ifdef HAVE_IPV6
static void
tlvs_to_adj_ipv6_addrs (struct tlvs *tlvs, struct isis_adjacency *adj)
{
struct listnode *node;
struct in6_addr *ipv6_addr, *malloced;
if (adj->ipv6_addrs)
{
adj->ipv6_addrs->del = del_ip_addr;
list_delete (adj->ipv6_addrs);
}
adj->ipv6_addrs = list_new ();
if (tlvs->ipv6_addrs)
{
for (ALL_LIST_ELEMENTS_RO (tlvs->ipv6_addrs, node, ipv6_addr))
{
malloced = XMALLOC (MTYPE_ISIS_TMP, sizeof (struct in6_addr));
memcpy (malloced, ipv6_addr, sizeof (struct in6_addr));
listnode_add (adj->ipv6_addrs, malloced);
}
}
}
#endif /* HAVE_IPV6 */
/*
* RECEIVE SIDE
*/
/*
* Process P2P IIH
* ISO - 10589
* Section 8.2.5 - Receiving point-to-point IIH PDUs
*
*/
static int
process_p2p_hello (struct isis_circuit *circuit)
{
int retval = ISIS_OK;
struct isis_p2p_hello_hdr *hdr;
struct isis_adjacency *adj;
u_int32_t expected = 0, found;
struct tlvs tlvs;
if ((stream_get_endp (circuit->rcv_stream) -
stream_get_getp (circuit->rcv_stream)) < ISIS_P2PHELLO_HDRLEN)
{
zlog_warn ("Packet too short");
return ISIS_WARNING;
}
/* 8.2.5.1 PDU acceptance tests */
/* 8.2.5.1 a) external domain untrue */
/* FIXME: not useful at all? */
/* 8.2.5.1 b) ID Length mismatch */
/* checked at the handle_pdu */
/* 8.2.5.2 IIH PDU Processing */
/* 8.2.5.2 a) 1) Maximum Area Addresses */
/* Already checked, and can also be ommited */
/*
* Get the header
*/
hdr = (struct isis_p2p_hello_hdr *) STREAM_PNT (circuit->rcv_stream);
circuit->rcv_stream->getp += ISIS_P2PHELLO_HDRLEN;
/* hdr.circuit_t = stream_getc (stream);
stream_get (hdr.source_id, stream, ISIS_SYS_ID_LEN);
hdr.hold_time = stream_getw (stream);
hdr.pdu_len = stream_getw (stream);
hdr.local_id = stream_getc (stream); */
/*
* My interpertation of the ISO, if no adj exists we will create one for
* the circuit
*/
if (isis->debugs & DEBUG_ADJ_PACKETS)
{
zlog_debug ("ISIS-Adj (%s): Rcvd P2P IIH from (%s), cir type %s,"
" cir id %02d, length %d",
circuit->area->area_tag, circuit->interface->name,
circuit_t2string (circuit->circuit_is_type),
circuit->circuit_id, ntohs (hdr->pdu_len));
}
adj = circuit->u.p2p.neighbor;
if (!adj)
{
adj = isis_new_adj (hdr->source_id, NULL, 0, circuit);
if (adj == NULL)
return ISIS_ERROR;
circuit->u.p2p.neighbor = adj;
isis_adj_state_change (adj, ISIS_ADJ_INITIALIZING, NULL);
adj->sys_type = ISIS_SYSTYPE_UNKNOWN;
}
/* 8.2.6 Monitoring point-to-point adjacencies */
adj->hold_time = ntohs (hdr->hold_time);
adj->last_upd = time (NULL);
/*
* Lets get the TLVS now
*/
expected |= TLVFLAG_AREA_ADDRS;
expected |= TLVFLAG_AUTH_INFO;
expected |= TLVFLAG_NLPID;
expected |= TLVFLAG_IPV4_ADDR;
expected |= TLVFLAG_IPV6_ADDR;
retval = parse_tlvs (circuit->area->area_tag,
STREAM_PNT (circuit->rcv_stream),
ntohs (hdr->pdu_len) - ISIS_P2PHELLO_HDRLEN
- ISIS_FIXED_HDR_LEN, &expected, &found, &tlvs);
if (retval > ISIS_WARNING)
{
free_tlvs (&tlvs);
return retval;
};
/* 8.2.5.1 c) Authentication */
if (circuit->passwd.type)
{
if (!(found & TLVFLAG_AUTH_INFO) ||
authentication_check (&circuit->passwd, &tlvs.auth_info))
{
isis_event_auth_failure (circuit->area->area_tag,
"P2P hello authentication failure",
hdr->source_id);
return ISIS_OK;
}
}
/* we do this now because the adj may not survive till the end... */
/* we need to copy addresses to the adj */
tlvs_to_adj_ipv4_addrs (&tlvs, adj);
#ifdef HAVE_IPV6
tlvs_to_adj_ipv6_addrs (&tlvs, adj);
#endif /* HAVE_IPV6 */
/* lets take care of the expiry */
THREAD_TIMER_OFF (adj->t_expire);
THREAD_TIMER_ON (master, adj->t_expire, isis_adj_expire, adj,
(long) adj->hold_time);
/* 8.2.5.2 a) a match was detected */
if (area_match (circuit->area->area_addrs, tlvs.area_addrs))
{
/* 8.2.5.2 a) 2) If the system is L1 - table 5 */
if (circuit->area->is_type == IS_LEVEL_1)
{
switch (hdr->circuit_t)
{
case IS_LEVEL_1:
case IS_LEVEL_1_AND_2:
if (adj->adj_state != ISIS_ADJ_UP)
{
/* (4) adj state up */
isis_adj_state_change (adj, ISIS_ADJ_UP, NULL);
/* (5) adj usage level 1 */
adj->adj_usage = ISIS_ADJ_LEVEL1;
}
else if (adj->adj_usage == ISIS_ADJ_LEVEL1)
{
; /* accept */
}
break;
case IS_LEVEL_2:
if (adj->adj_state != ISIS_ADJ_UP)
{
/* (7) reject - wrong system type event */
zlog_warn ("wrongSystemType");
return ISIS_WARNING; /* Reject */
}
else if (adj->adj_usage == ISIS_ADJ_LEVEL1)
{
/* (6) down - wrong system */
isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
}
break;
}
}
/* 8.2.5.2 a) 3) If the system is L1L2 - table 6 */
if (circuit->area->is_type == IS_LEVEL_1_AND_2)
{
switch (hdr->circuit_t)
{
case IS_LEVEL_1:
if (adj->adj_state != ISIS_ADJ_UP)
{
/* (6) adj state up */
isis_adj_state_change (adj, ISIS_ADJ_UP, NULL);
/* (7) adj usage level 1 */
adj->adj_usage = ISIS_ADJ_LEVEL1;
}
else if (adj->adj_usage == ISIS_ADJ_LEVEL1)
{
; /* accept */
}
else if ((adj->adj_usage == ISIS_ADJ_LEVEL1AND2) ||
(adj->adj_usage == ISIS_ADJ_LEVEL2))
{
/* (8) down - wrong system */
isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
}
break;
case IS_LEVEL_2:
if (adj->adj_state != ISIS_ADJ_UP)
{
/* (6) adj state up */
isis_adj_state_change (adj, ISIS_ADJ_UP, NULL);
/* (9) adj usage level 2 */
adj->adj_usage = ISIS_ADJ_LEVEL2;
}
else if ((adj->adj_usage == ISIS_ADJ_LEVEL1) ||
(adj->adj_usage == ISIS_ADJ_LEVEL1AND2))
{
/* (8) down - wrong system */
isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
}
else if (adj->adj_usage == ISIS_ADJ_LEVEL2)
{
; /* Accept */
}
break;
case IS_LEVEL_1_AND_2:
if (adj->adj_state != ISIS_ADJ_UP)
{
/* (6) adj state up */
isis_adj_state_change (adj, ISIS_ADJ_UP, NULL);
/* (10) adj usage level 1 */
adj->adj_usage = ISIS_ADJ_LEVEL1AND2;
}
else if ((adj->adj_usage == ISIS_ADJ_LEVEL1) ||
(adj->adj_usage == ISIS_ADJ_LEVEL2))
{
/* (8) down - wrong system */
isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
}
else if (adj->adj_usage == ISIS_ADJ_LEVEL1AND2)
{
; /* Accept */
}
break;
}
}
/* 8.2.5.2 a) 4) If the system is L2 - table 7 */
if (circuit->area->is_type == IS_LEVEL_2)
{
switch (hdr->circuit_t)
{
case IS_LEVEL_1:
if (adj->adj_state != ISIS_ADJ_UP)
{
/* (5) reject - wrong system type event */
zlog_warn ("wrongSystemType");
return ISIS_WARNING; /* Reject */
}
else if ((adj->adj_usage == ISIS_ADJ_LEVEL1AND2) ||
(adj->adj_usage == ISIS_ADJ_LEVEL2))
{
/* (6) down - wrong system */
isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
}
break;
case IS_LEVEL_1_AND_2:
case IS_LEVEL_2:
if (adj->adj_state != ISIS_ADJ_UP)
{
/* (7) adj state up */
isis_adj_state_change (adj, ISIS_ADJ_UP, NULL);
/* (8) adj usage level 2 */
adj->adj_usage = ISIS_ADJ_LEVEL2;
}
else if (adj->adj_usage == ISIS_ADJ_LEVEL1AND2)
{
/* (6) down - wrong system */
isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
}
else if (adj->adj_usage == ISIS_ADJ_LEVEL2)
{
; /* Accept */
}
break;
}
}
}
/* 8.2.5.2 b) if no match was detected */
else
{
if (circuit->area->is_type == IS_LEVEL_1)
{
/* 8.2.5.2 b) 1) is_type L1 and adj is not up */
if (adj->adj_state != ISIS_ADJ_UP)
{
isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Area Mismatch");
/* 8.2.5.2 b) 2)is_type L1 and adj is up */
}
else
{
isis_adj_state_change (adj, ISIS_ADJ_DOWN,
"Down - Area Mismatch");
}
}
/* 8.2.5.2 b 3 If the system is L2 or L1L2 - table 8 */
else
{
switch (hdr->circuit_t)
{
case IS_LEVEL_1:
if (adj->adj_state != ISIS_ADJ_UP)
{
/* (6) reject - Area Mismatch event */
zlog_warn ("AreaMismatch");
return ISIS_WARNING; /* Reject */
}
else if (adj->adj_usage == ISIS_ADJ_LEVEL1)
{
/* (7) down - area mismatch */
isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Area Mismatch");
}
else if ((adj->adj_usage == ISIS_ADJ_LEVEL1AND2) ||
(adj->adj_usage == ISIS_ADJ_LEVEL2))
{
/* (7) down - wrong system */
isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
}
break;
case IS_LEVEL_1_AND_2:
case IS_LEVEL_2:
if (adj->adj_state != ISIS_ADJ_UP)
{
/* (8) adj state up */
isis_adj_state_change (adj, ISIS_ADJ_UP, NULL);
/* (9) adj usage level 2 */
adj->adj_usage = ISIS_ADJ_LEVEL2;
}
else if (adj->adj_usage == ISIS_ADJ_LEVEL1)
{
/* (7) down - wrong system */
isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System");
}
else if (adj->adj_usage == ISIS_ADJ_LEVEL1AND2)
{
if (hdr->circuit_t == IS_LEVEL_2)
{
/* (7) down - wrong system */
isis_adj_state_change (adj, ISIS_ADJ_DOWN,
"Wrong System");
}
else
{
/* (7) down - area mismatch */
isis_adj_state_change (adj, ISIS_ADJ_DOWN,
"Area Mismatch");
}
}
else if (adj->adj_usage == ISIS_ADJ_LEVEL2)
{
; /* Accept */
}
break;
}
}
}
/* 8.2.5.2 c) if the action was up - comparing circuit IDs */
/* FIXME - Missing parts */
/* some of my own understanding of the ISO, why the heck does
* it not say what should I change the system_type to...
*/
switch (adj->adj_usage)
{
case ISIS_ADJ_LEVEL1:
adj->sys_type = ISIS_SYSTYPE_L1_IS;
break;
case ISIS_ADJ_LEVEL2:
adj->sys_type = ISIS_SYSTYPE_L2_IS;
break;
case ISIS_ADJ_LEVEL1AND2:
adj->sys_type = ISIS_SYSTYPE_L2_IS;
break;
case ISIS_ADJ_NONE:
adj->sys_type = ISIS_SYSTYPE_UNKNOWN;
break;
}
adj->circuit_t = hdr->circuit_t;
adj->level = hdr->circuit_t;
free_tlvs (&tlvs);
return retval;
}
/*
* Process IS-IS LAN Level 1/2 Hello PDU
*/
static int
process_lan_hello (int level, struct isis_circuit *circuit, u_char * ssnpa)
{
int retval = ISIS_OK;
struct isis_lan_hello_hdr hdr;
struct isis_adjacency *adj;
u_int32_t expected = 0, found;
struct tlvs tlvs;
u_char *snpa;
struct listnode *node;
if ((stream_get_endp (circuit->rcv_stream) -
stream_get_getp (circuit->rcv_stream)) < ISIS_LANHELLO_HDRLEN)
{
zlog_warn ("Packet too short");
return ISIS_WARNING;
}
if (circuit->ext_domain)
{
zlog_debug ("level %d LAN Hello received over circuit with "
"externalDomain = true", level);
return ISIS_WARNING;
}
if (!accept_level (level, circuit->circuit_is_type))
{
if (isis->debugs & DEBUG_ADJ_PACKETS)
{
zlog_debug ("ISIS-Adj (%s): Interface level mismatch, %s",
circuit->area->area_tag, circuit->interface->name);
}
return ISIS_WARNING;
}
#if 0
/* Cisco's debug message compatability */
if (!accept_level (level, circuit->area->is_type))
{
if (isis->debugs & DEBUG_ADJ_PACKETS)
{
zlog_debug ("ISIS-Adj (%s): is type mismatch",
circuit->area->area_tag);
}
return ISIS_WARNING;
}
#endif
/*
* Fill the header
*/
hdr.circuit_t = stream_getc (circuit->rcv_stream);
stream_get (hdr.source_id, circuit->rcv_stream, ISIS_SYS_ID_LEN);
hdr.hold_time = stream_getw (circuit->rcv_stream);
hdr.pdu_len = stream_getw (circuit->rcv_stream);
hdr.prio = stream_getc (circuit->rcv_stream);
stream_get (hdr.lan_id, circuit->rcv_stream, ISIS_SYS_ID_LEN + 1);
if (hdr.circuit_t != IS_LEVEL_1 && hdr.circuit_t != IS_LEVEL_2 &&
hdr.circuit_t != IS_LEVEL_1_AND_2)
{
zlog_warn ("Level %d LAN Hello with Circuit Type %d", level,
hdr.circuit_t);
return ISIS_ERROR;
}
/*
* Then get the tlvs
*/
expected |= TLVFLAG_AUTH_INFO;
expected |= TLVFLAG_AREA_ADDRS;
expected |= TLVFLAG_LAN_NEIGHS;
expected |= TLVFLAG_NLPID;
expected |= TLVFLAG_IPV4_ADDR;
expected |= TLVFLAG_IPV6_ADDR;
retval = parse_tlvs (circuit->area->area_tag,
STREAM_PNT (circuit->rcv_stream),
hdr.pdu_len - ISIS_LANHELLO_HDRLEN -
ISIS_FIXED_HDR_LEN, &expected, &found, &tlvs);
if (retval > ISIS_WARNING)
{
zlog_warn ("parse_tlvs() failed");
goto out;
}
if (!(found & TLVFLAG_AREA_ADDRS))
{
zlog_warn ("No Area addresses TLV in Level %d LAN IS to IS hello",
level);
retval = ISIS_WARNING;
goto out;
}
if (circuit->passwd.type)
{
if (!(found & TLVFLAG_AUTH_INFO) ||
authentication_check (&circuit->passwd, &tlvs.auth_info))
{
isis_event_auth_failure (circuit->area->area_tag,
"LAN hello authentication failure",
hdr.source_id);
retval = ISIS_WARNING;
goto out;
}
}
/*
* Accept the level 1 adjacency only if a match between local and
* remote area addresses is found
*/
if (level == 1 && !area_match (circuit->area->area_addrs, tlvs.area_addrs))
{
if (isis->debugs & DEBUG_ADJ_PACKETS)
{
zlog_debug ("ISIS-Adj (%s): Area mismatch, level %d IIH on %s",
circuit->area->area_tag, level,
circuit->interface->name);
}
retval = ISIS_OK;
goto out;
}
/*
* it's own IIH PDU - discard silently
*/
if (!memcmp (circuit->u.bc.snpa, ssnpa, ETH_ALEN))
{
zlog_debug ("ISIS-Adj (%s): it's own IIH PDU - discarded",
circuit->area->area_tag);
retval = ISIS_OK;
goto out;
}
/*
* check if it's own interface ip match iih ip addrs
*/
if (!(found & TLVFLAG_IPV4_ADDR)
|| !ip_match (circuit->ip_addrs, tlvs.ipv4_addrs))
{
zlog_debug
("ISIS-Adj: No usable IP interface addresses in LAN IIH from %s\n",
circuit->interface->name);
retval = ISIS_WARNING;
goto out;
}
adj = isis_adj_lookup (hdr.source_id, circuit->u.bc.adjdb[level - 1]);
if (!adj)
{
/*
* Do as in 8.4.2.5
*/
adj = isis_new_adj (hdr.source_id, ssnpa, level, circuit);
if (adj == NULL)
{
retval = ISIS_ERROR;
goto out;
}
adj->level = level;
isis_adj_state_change (adj, ISIS_ADJ_INITIALIZING, NULL);
if (level == 1)
{
adj->sys_type = ISIS_SYSTYPE_L1_IS;
}
else
{
adj->sys_type = ISIS_SYSTYPE_L2_IS;
}
list_delete_all_node (circuit->u.bc.lan_neighs[level - 1]);
isis_adj_build_neigh_list (circuit->u.bc.adjdb[level - 1],
circuit->u.bc.lan_neighs[level - 1]);
}
if(adj->dis_record[level-1].dis==ISIS_IS_DIS)
switch (level)
{
case 1:
if (memcmp (circuit->u.bc.l1_desig_is, hdr.lan_id, ISIS_SYS_ID_LEN + 1))
{
thread_add_event (master, isis_event_dis_status_change, circuit, 0);
memcpy (&circuit->u.bc.l1_desig_is, hdr.lan_id,
ISIS_SYS_ID_LEN + 1);
}
break;
case 2:
if (memcmp (circuit->u.bc.l2_desig_is, hdr.lan_id, ISIS_SYS_ID_LEN + 1))
{
thread_add_event (master, isis_event_dis_status_change, circuit, 0);
memcpy (&circuit->u.bc.l2_desig_is, hdr.lan_id,
ISIS_SYS_ID_LEN + 1);
}
break;
}
adj->hold_time = hdr.hold_time;
adj->last_upd = time (NULL);
adj->prio[level - 1] = hdr.prio;
memcpy (adj->lanid, hdr.lan_id, ISIS_SYS_ID_LEN + 1);
/* which protocol are spoken ??? */
if (found & TLVFLAG_NLPID)
tlvs_to_adj_nlpids (&tlvs, adj);
/* we need to copy addresses to the adj */
if (found & TLVFLAG_IPV4_ADDR)
tlvs_to_adj_ipv4_addrs (&tlvs, adj);
#ifdef HAVE_IPV6
if (found & TLVFLAG_IPV6_ADDR)
tlvs_to_adj_ipv6_addrs (&tlvs, adj);
#endif /* HAVE_IPV6 */
adj->circuit_t = hdr.circuit_t;
/* lets take care of the expiry */
THREAD_TIMER_OFF (adj->t_expire);
THREAD_TIMER_ON (master, adj->t_expire, isis_adj_expire, adj,
(long) adj->hold_time);
/*
* If the snpa for this circuit is found from LAN Neighbours TLV
* we have two-way communication -> adjacency can be put to state "up"
*/
if (found & TLVFLAG_LAN_NEIGHS)
{
if (adj->adj_state != ISIS_ADJ_UP)
{
for (ALL_LIST_ELEMENTS_RO (tlvs.lan_neighs, node, snpa))
if (!memcmp (snpa, circuit->u.bc.snpa, ETH_ALEN))
{
isis_adj_state_change (adj, ISIS_ADJ_UP,
"own SNPA found in LAN Neighbours TLV");
}
}
}
out:
/* DEBUG_ADJ_PACKETS */
if (isis->debugs & DEBUG_ADJ_PACKETS)
{
/* FIXME: is this place right? fix missing info */
zlog_debug ("ISIS-Adj (%s): Rcvd L%d LAN IIH from %s on %s, cirType %s, "
"cirID %u, length %ld",
circuit->area->area_tag,
level, snpa_print (ssnpa), circuit->interface->name,
circuit_t2string (circuit->circuit_is_type),
circuit->circuit_id,
/* FIXME: use %z when we stop supporting old compilers. */
(unsigned long) stream_get_endp (circuit->rcv_stream));
}
free_tlvs (&tlvs);
return retval;
}
/*
* Process Level 1/2 Link State
* ISO - 10589
* Section 7.3.15.1 - Action on receipt of a link state PDU
*/
static int
process_lsp (int level, struct isis_circuit *circuit, u_char * ssnpa)
{
struct isis_link_state_hdr *hdr;
struct isis_adjacency *adj = NULL;
struct isis_lsp *lsp, *lsp0 = NULL;
int retval = ISIS_OK, comp = 0;
u_char lspid[ISIS_SYS_ID_LEN + 2];
struct isis_passwd *passwd;
/* Sanity check - FIXME: move to correct place */
if ((stream_get_endp (circuit->rcv_stream) -
stream_get_getp (circuit->rcv_stream)) < ISIS_LSP_HDR_LEN)
{
zlog_warn ("Packet too short");
return ISIS_WARNING;
}
/* Reference the header */
hdr = (struct isis_link_state_hdr *) STREAM_PNT (circuit->rcv_stream);
if (isis->debugs & DEBUG_UPDATE_PACKETS)
{
zlog_debug ("ISIS-Upd (%s): Rcvd L%d LSP %s, seq 0x%08x, cksum 0x%04x, "
"lifetime %us, len %lu, on %s",
circuit->area->area_tag,
level,
rawlspid_print (hdr->lsp_id),
ntohl (hdr->seq_num),
ntohs (hdr->checksum),
ntohs (hdr->rem_lifetime),
/* FIXME: use %z when we stop supporting old compilers. */
(unsigned long) stream_get_endp (circuit->rcv_stream),
circuit->interface->name);
}
assert (ntohs (hdr->pdu_len) > ISIS_LSP_HDR_LEN);
/* Checksum sanity check - FIXME: move to correct place */
/* 12 = sysid+pdu+remtime */
if (iso_csum_verify (STREAM_PNT (circuit->rcv_stream) + 4,
ntohs (hdr->pdu_len) - 12, &hdr->checksum))
{
zlog_debug ("ISIS-Upd (%s): LSP %s invalid LSP checksum 0x%04x",
circuit->area->area_tag,
rawlspid_print (hdr->lsp_id), ntohs (hdr->checksum));
return ISIS_WARNING;
}
/* 7.3.15.1 a) 1 - external domain circuit will discard lsps */
if (circuit->ext_domain)
{
zlog_debug
("ISIS-Upd (%s): LSP %s received at level %d over circuit with "
"externalDomain = true", circuit->area->area_tag,
rawlspid_print (hdr->lsp_id), level);
return ISIS_WARNING;
}
/* 7.3.15.1 a) 2,3 - manualL2OnlyMode not implemented */
if (!accept_level (level, circuit->circuit_is_type))
{
zlog_debug ("ISIS-Upd (%s): LSP %s received at level %d over circuit of"
" type %s",
circuit->area->area_tag,
rawlspid_print (hdr->lsp_id),
level, circuit_t2string (circuit->circuit_is_type));
return ISIS_WARNING;
}
/* 7.3.15.1 a) 4 - need to make sure IDLength matches */
/* 7.3.15.1 a) 5 - maximum area match, can be ommited since we only use 3 */
/* 7.3.15.1 a) 7 - password check */
(level == ISIS_LEVEL1) ? (passwd = &circuit->area->area_passwd) :
(passwd = &circuit->area->domain_passwd);
if (passwd->type)