-
Notifications
You must be signed in to change notification settings - Fork 46
/
dcb_protocol.c
4050 lines (3562 loc) · 110 KB
/
dcb_protocol.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
/*******************************************************************************
LLDP Agent Daemon (LLDPAD) Software
Copyright(c) 2007-2010 Intel Corporation.
This program is free software; you can redistribute it and/or modify it
under the terms and conditions of the GNU General Public License,
version 2, as published by the Free Software Foundation.
This program is distributed in the hope 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.,
51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
The full GNU General Public License is included in this distribution in
the file called "COPYING".
Contact Information:
open-lldp Mailing List <[email protected]>
*******************************************************************************/
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#include <stdbool.h>
#include <sys/queue.h>
#include "lldp/ports.h"
#include "dcb_types.h"
#include "dcb_protocol.h"
#include "dcb_driver_interface.h"
#include "dcb_persist_store.h"
#include "dcb_rule_chk.h"
#include "dcb_events.h"
#include "messages.h"
#include "lldp.h"
#include "tlv_dcbx.h"
#include "lldp_rtnl.h"
#include "lldpad_shm.h"
#include "linux/if.h"
#include "linux/dcbnl.h"
static void handle_opermode_true(char *device_name);
u8 gdcbx_subtype = DCBX_SUBTYPE2;
int set_configuration(char *device_name, u32 EventFlag);
int pg_not_initted = true;
struct pg_store1 {
char ifname[MAX_DESCRIPTION_LEN];
pg_attribs *second;
LIST_ENTRY(pg_store1) entries;
};
typedef struct pg_store1 * pg_it;
LIST_HEAD(pghead, pg_store1) pg, peer_pg, oper_pg;
/*todo: check MAX_DESCRIPTION_LEN?*/
struct pg_store1 *pg_find(struct pghead *head, char *ifname)
{
struct pg_store1 *p = NULL;
for (p = head->lh_first; p != NULL; p = p->entries.le_next)
if (!strcmp(p->ifname, ifname))
return p;
return p;
}
void pg_insert(struct pghead *head, char *ifname, pg_attribs *store)
{
struct pg_store1 *entry = NULL;
entry = (struct pg_store1 *)malloc(sizeof(struct pg_store1));
if (!entry)
return;
STRNCPY_TERMINATED(entry->ifname, ifname, sizeof(entry->ifname));
entry->second = store;
LIST_INSERT_HEAD(head, entry, entries);
}
void pg_erase(pg_it *p)
{
/* save the reserved memory here so we can free
* it since erase wipes out the it structure
* (but does not free the memory) */
void *itp = (void *)(*p)->second;
/* this line frees the param of this function! */
LIST_REMOVE(*p, entries);
if (itp) {
free (itp);
itp = NULL;
}
free(*p);
*p = NULL;
}
int pfc_not_initted = true;
struct pfc_store {
char ifname[MAX_DESCRIPTION_LEN];
pfc_attribs *second;
LIST_ENTRY(pfc_store) entries;
};
typedef struct pfc_store * pfc_it;
LIST_HEAD(pfchead, pfc_store) pfc, peer_pfc, oper_pfc;
struct pfc_store *pfc_find(struct pfchead *head, char *ifname)
{
struct pfc_store *p = NULL;
for (p = head->lh_first; p != NULL; p = p->entries.le_next)
if (!strcmp(p->ifname, ifname))
return p;
return p;
}
void pfc_insert(struct pfchead *head, char *ifname, pfc_attribs *store)
{
struct pfc_store *entry;
entry = (struct pfc_store *) malloc(sizeof(struct pfc_store));
if (!entry)
return;
strcpy(entry->ifname, ifname);
entry->second = store;
LIST_INSERT_HEAD(head, entry, entries);
}
void pfc_erase(pfc_it *p)
{
void *itp = (void *)(*p)->second;
LIST_REMOVE(*p, entries);
if (itp) {
free(itp);
itp = NULL;
}
free(*p);
*p = NULL;
}
int pgdesc_not_initted = true;
struct pg_desc_store {
char ifname[MAX_DESCRIPTION_LEN];
pg_info *second;
LIST_ENTRY(pg_desc_store) entries;
};
typedef struct pg_desc_store * pg_desc_it;
LIST_HEAD(pgdesc_head, pg_desc_store) pg_desc;
struct pg_desc_store *pgdesc_find(struct pgdesc_head *head, char *ifname)
{
struct pg_desc_store *p = NULL;
for (p = head->lh_first; p != NULL; p = p->entries.le_next)
if (!strcmp(p->ifname, ifname))
return p;
return p;
}
void pgdesc_insert(struct pgdesc_head *head, char *ifname, pg_info *store)
{
struct pg_desc_store *entry;
entry = (struct pg_desc_store *) malloc(sizeof(struct pg_desc_store));
if (!entry)
return;
strcpy(entry->ifname, ifname);
entry->second = store;
LIST_INSERT_HEAD(head, entry, entries);
}
void pgdesc_erase(pg_desc_it *p)
{
void *itp = (void *)(*p)->second;
LIST_REMOVE(*p, entries);
if (itp) {
free(itp);
itp = NULL;
}
free(*p);
*p = NULL;
}
int app_not_initted = true;
struct app_store {
char ifname[MAX_DESCRIPTION_LEN];
u32 app_subtype;
app_attribs *second;
LIST_ENTRY(app_store) entries;
};
typedef struct app_store * app_it;
LIST_HEAD(apphead, app_store) apptlv, peer_apptlv, oper_apptlv;
struct app_store *apptlv_find(struct apphead *head, char *ifname, u32 subtype)
{
struct app_store *p = NULL;
for (p = head->lh_first; p != NULL; p = p->entries.le_next)
if (!strcmp(p->ifname, ifname) && (p->app_subtype == subtype))
return p;
return p;
}
void apptlv_insert(struct apphead *head, char *ifname, u32 subtype,
app_attribs *store)
{
struct app_store *entry;
entry = (struct app_store *) malloc(sizeof(struct app_store));
if (!entry)
return;
strcpy(entry->ifname, ifname);
entry->second = store;
entry->app_subtype = subtype;
LIST_INSERT_HEAD(head, entry, entries);
}
void apptlv_erase(app_it *p)
{
void *itp = (void *)(*p)->second;
LIST_REMOVE(*p, entries);
if (itp) {
free (itp);
itp = NULL;
}
free(*p);
*p = NULL;
}
int llink_not_initted = true;
struct llink_store {
char ifname[MAX_DESCRIPTION_LEN];
u32 llink_subtype;
llink_attribs *second;
LIST_ENTRY(llink_store) entries;
};
typedef struct llink_store * llink_it;
LIST_HEAD(llinkhead, llink_store) llink, peer_llink, oper_llink;
struct llink_store *llink_find(struct llinkhead *head, char *ifname,
u32 subtype)
{
struct llink_store *p = NULL;
for (p = head->lh_first; p != NULL; p = p->entries.le_next)
if (!strcmp(p->ifname, ifname) && p->llink_subtype == subtype)
return p;
return p;
}
void llink_insert(struct llinkhead *head, char *ifname, llink_attribs *store,
u32 subtype)
{
struct llink_store *entry;
entry = (struct llink_store *) malloc(sizeof(struct llink_store));
if (!entry)
return;
strcpy(entry->ifname, ifname);
entry->second = store;
entry->llink_subtype = subtype;
LIST_INSERT_HEAD(head, entry, entries);
}
void llink_erase(llink_it *p)
{
void *itp = (void *)(*p)->second;
LIST_REMOVE(*p, entries);
if (itp) {
free(itp);
itp = NULL;
}
free(*p);
*p = NULL;
}
int ctrl_not_initted = true;
struct dcb_control_protocol {
char ifname[MAX_DESCRIPTION_LEN];
control_protocol_attribs *second;
LIST_ENTRY(dcb_control_protocol) entries;
};
typedef struct dcb_control_protocol * control_prot_it;
LIST_HEAD(control_prot_head, dcb_control_protocol)\
dcb_control_prot, dcb_peer_control_prot;
struct dcb_control_protocol *ctrl_prot_find(struct control_prot_head *head,
const char *ifname)
{
struct dcb_control_protocol *p = NULL;
for (p = head->lh_first; p != NULL; p = p->entries.le_next)
if (!strcmp(p->ifname, ifname))
return p;
return p;
}
void ctrl_prot_insert(struct control_prot_head *head, char *ifname,
control_protocol_attribs *store)
{
struct dcb_control_protocol *entry;
entry = (struct dcb_control_protocol *)
malloc(sizeof(struct dcb_control_protocol));
if (!entry)
return;
strcpy(entry->ifname, ifname);
entry->second = store;
LIST_INSERT_HEAD(head, entry, entries);
}
void ctrl_prot_erase(control_prot_it *p)
{
void *itp = (void *)(*p)->second;
LIST_REMOVE(*p, entries);
if (itp) {
free(itp);
itp = NULL;
}
free(*p);
*p = NULL;
}
int feature_not_initted = true;
struct features_store {
char ifname[MAX_DESCRIPTION_LEN];
feature_support *second;
LIST_ENTRY(features_store) entries;
};
typedef struct features_store * features_it;
LIST_HEAD(featurehead, features_store) feature_struct;
struct features_store *features_find(struct featurehead *head, char *ifname)
{
struct features_store *p = NULL;
for (p = head->lh_first; p != NULL; p = p->entries.le_next)
if (!strcmp(p->ifname, ifname))
return p;
return p;
}
void features_insert(struct featurehead *head, char *ifname,
feature_support *store)
{
struct features_store *entry;
entry = (struct features_store *)malloc(sizeof(struct features_store));
if (!entry)
return;
strcpy(entry->ifname, ifname);
entry->second = store;
LIST_INSERT_HEAD(head, entry, entries);
}
void features_erase(features_it *p)
{
void *itp = (void *)(*p)->second;
LIST_REMOVE(*p, entries);
if (itp) {
free(itp);
itp = NULL;
}
free(*p);
*p = NULL;
}
/* Add the store pointer to init_pg, i.e. memset store to 0,
* then copy attribs to store
*/
void init_pg(pg_attribs *Attrib, pg_attribs *Store)
{
memset(Store,0,sizeof(*Store));
Attrib->protocol.Max_version = DCB_PG_MAX_VERSION;
Attrib->protocol.State = DCB_INIT;
Attrib->protocol.Advertise_prev = false;
Attrib->protocol.tlv_sent = false;
Attrib->protocol.dcbx_st = gdcbx_subtype & MASK_DCBX_FORCE;
memcpy(Store, Attrib, sizeof (*Attrib));
}
/* pass in the pointer to attrib */
bool add_pg(char *device_name, pg_attribs *Attrib)
{
pg_it it = pg_find(&pg, device_name);
if (it == NULL) {
/* Device not present: add */
pg_attribs *store =
(pg_attribs*) malloc(sizeof(*store));
if (!store)
return false;
init_pg(Attrib, store);
pg_insert(&pg, device_name, store);
} else { /* already in data store, just update it */
it->second->protocol.Advertise_prev =
(*it).second->protocol.Advertise;
it->second->protocol.Advertise = Attrib->protocol.Advertise;
it->second->protocol.Enable = Attrib->protocol.Enable;
it->second->protocol.Willing = Attrib->protocol.Willing;
memcpy(&(it->second->rx), &(Attrib->rx), sizeof(Attrib->rx));
memcpy(&(it->second->tx), &(Attrib->tx), sizeof(Attrib->tx));
}
return true;
}
void init_oper_pg(pg_attribs *Attrib)
{
char sTmp[MAX_DESCRIPTION_LEN];
memset(Attrib,0,sizeof(*Attrib));
snprintf(sTmp, MAX_DESCRIPTION_LEN, DEF_CFG_STORE);
pg_it itpg = pg_find(&pg, sTmp);
if (itpg == NULL)
return;
memcpy(&(Attrib->rx), &(itpg->second->rx), sizeof(Attrib->rx));
memcpy(&(Attrib->tx), &(itpg->second->tx), sizeof(Attrib->tx));
}
bool add_oper_pg(char *device_name)
{
pg_it it = pg_find(&oper_pg, device_name);
if (it == NULL) {
/* Device not present: add */
pg_attribs *store =
(pg_attribs*) malloc(sizeof(*store));
if (!store)
return false;
init_oper_pg( store);
pg_insert(&oper_pg, device_name, store);
}
return true;
}
void init_peer_pg(pg_attribs *Attrib)
{
memset(Attrib,0,sizeof(*Attrib));
Attrib->protocol.TLVPresent = false;
}
bool add_peer_pg(char *device_name)
{
pg_it it = pg_find(&peer_pg, device_name);
if (it == NULL) {
/* Device not present: add */
pg_attribs *store = (pg_attribs*) malloc(sizeof(*store));
if (!store)
return false;
init_peer_pg( store);
pg_insert(&peer_pg, device_name, store);
}
return true;
}
void init_apptlv(app_attribs *Attrib, app_attribs *Store)
{
memset(Store,0,sizeof(*Store));
Attrib->protocol.Max_version = DCB_APPTLV_MAX_VERSION;
Attrib->protocol.State = DCB_INIT;
Attrib->protocol.Advertise_prev = false;
Attrib->protocol.tlv_sent = false;
Attrib->protocol.dcbx_st = gdcbx_subtype & MASK_DCBX_FORCE;
memcpy(Store, Attrib, sizeof (*Attrib));
}
bool valid_subtype(dcbx_state *state, u32 Subtype)
{
if (state == NULL)
return 0;
switch (Subtype) {
case APP_FCOE_STYPE:
return state->FCoEenable;
case APP_ISCSI_STYPE:
return state->iSCSIenable;
case APP_FIP_STYPE:
return state->FIPenable;
default:
return 0;
}
}
bool add_apptlv(char *device_name, app_attribs *Attrib, u32 Subtype,
dcbx_state *state)
{
full_dcb_attrib_ptrs attr_ptr;
/* If FCoE is enabled in the DCBX state record,
* then enable the FCoE App object and persist the change.
*/
if (valid_subtype(state, Subtype) && !Attrib->protocol.Enable) {
Attrib->protocol.Enable = true;
memset(&attr_ptr, 0, sizeof(attr_ptr));
attr_ptr.app = Attrib;
attr_ptr.app_subtype = (u8)Subtype;
if (set_persistent(device_name, &attr_ptr) !=
cmd_success) {
LLDPAD_DBG("Set persistent failed in add_apptlv, "
" subtype: %d\n", Subtype);
return false;
}
}
app_it it = apptlv_find(&apptlv, device_name, Subtype);
if (it == NULL) {
/* Device not present: add */
app_attribs *store = (app_attribs*)malloc(sizeof(*store));
if (!store)
return false;
init_apptlv(Attrib, store);
apptlv_insert(&apptlv, device_name, Subtype, store);
}
else { /* already in data store, just update it */
it->second->protocol.Advertise_prev =
it->second->protocol.Advertise;
it->second->protocol.Advertise = Attrib->protocol.Advertise;
it->second->protocol.Enable = Attrib->protocol.Enable;
it->second->protocol.Willing = Attrib->protocol.Willing;
it->second->Length = Attrib->Length;
memcpy(it->second->AppData, Attrib->AppData, Attrib->Length);
}
return true;
}
void init_oper_apptlv(app_attribs *Store, u32 Subtype)
{
memset(Store,0,sizeof(*Store));
app_it itapp = apptlv_find(&oper_apptlv, DEF_CFG_STORE, Subtype);
if (!itapp)
return;
Store->Length = itapp->second->Length;
memcpy(&Store->AppData, &itapp->second->AppData, Store->Length);
}
bool add_oper_apptlv(char *device_name, u32 Subtype)
{
app_it it = apptlv_find(&oper_apptlv, device_name, Subtype);
if (it == NULL) {
/* Device not present: add */
app_attribs *store = (app_attribs*)malloc(sizeof(*store));
if (!store)
return false;
init_oper_apptlv(store, Subtype);
apptlv_insert(&oper_apptlv, device_name, Subtype, store);
}
return true;
}
void init_peer_apptlv(app_attribs *Store)
{
memset(Store,0,sizeof(*Store));
}
bool add_peer_apptlv(char *device_name, u32 Subtype)
{
app_it it = apptlv_find(&peer_apptlv, device_name, Subtype);
if (it == NULL) {
/* Device not present: add */
app_attribs *store = (app_attribs*)malloc(sizeof(*store));
if (!store)
return false;
init_peer_apptlv(store);
apptlv_insert(&peer_apptlv, device_name, Subtype, store);
}
return true;
}
void init_control_prot(control_protocol_attribs *Attrib, dcbx_state *state)
{
memset(Attrib,0,sizeof(*Attrib));
Attrib->State = DCB_INIT;
Attrib->Max_version = DCB_MAX_VERSION;
Attrib->SeqNo = state->SeqNo;
Attrib->AckNo = state->AckNo;
Attrib->MyAckNo = state->SeqNo;
}
bool add_control_protocol(char *device_name, dcbx_state *state)
{
control_prot_it it = ctrl_prot_find(&dcb_control_prot, device_name);
if (it == NULL) {
/* Device not present: add */
control_protocol_attribs *store =
(control_protocol_attribs*)malloc(sizeof(*store));
if (!store)
return false;
init_control_prot(store, state);
ctrl_prot_insert(&dcb_control_prot, device_name, store);
} else if (get_operstate(device_name) == IF_OPER_DORMANT) {
init_control_prot(it->second, state);
}
return true;
}
void init_peer_control_prot(control_protocol_attribs *Attrib)
{
memset(Attrib,0,sizeof(*Attrib));
Attrib->Oper_version = DCB_MAX_VERSION;
Attrib->Max_version = DCB_MAX_VERSION;
Attrib->RxDCBTLVState = DCB_PEER_NONE;
}
bool add_peer_control_protocol(char *device_name)
{
control_prot_it it = ctrl_prot_find(&dcb_peer_control_prot,
device_name);
if (it == NULL) {
/* Device not present: add */
control_protocol_attribs *store =
(control_protocol_attribs*)malloc(sizeof(*store));
if (!store)
return false;
init_peer_control_prot( store);
ctrl_prot_insert(&dcb_peer_control_prot, device_name, store);
}
return true;
}
void init_pfc(pfc_attribs *Attrib, pfc_attribs *Store)
{
memset(Store,0,sizeof(*Store));
Attrib->protocol.Max_version = DCB_PFC_MAX_VERSION;
Attrib->protocol.State = DCB_INIT;
Attrib->protocol.Advertise_prev = false;
Attrib->protocol.tlv_sent = false;
Attrib->protocol.dcbx_st = gdcbx_subtype & MASK_DCBX_FORCE;
memcpy(Store, Attrib, sizeof(*Attrib));
}
bool add_pfc(char *device_name, pfc_attribs *Attrib)
{
pfc_it it = pfc_find(&pfc, device_name);
if (it == NULL) {
/* Device not present: add */
pfc_attribs *store =
(pfc_attribs*)malloc(sizeof(*store));
if (!store)
return false;
init_pfc(Attrib, store);
pfc_insert(&pfc, device_name, store);
} else { /* already present in store, just update */
it->second->protocol.Advertise_prev =
it->second->protocol.Advertise;
it->second->protocol.Advertise = Attrib->protocol.Advertise;
it->second->protocol.Enable = Attrib->protocol.Enable;
it->second->protocol.Willing = Attrib->protocol.Willing;
memcpy(it->second->admin, Attrib->admin,
sizeof(Attrib->admin));
}
return true;
}
void init_oper_pfc(pfc_attribs *Attrib)
{
char sTmp[MAX_DESCRIPTION_LEN];
memset(Attrib,0,sizeof(*Attrib));
snprintf(sTmp, MAX_DESCRIPTION_LEN, DEF_CFG_STORE);
pfc_it itpfc = pfc_find(&oper_pfc, sTmp);
if (itpfc == NULL)
return;
memcpy(&(Attrib->admin), &(itpfc->second->admin), sizeof(Attrib->admin));
}
bool add_oper_pfc(char *device_name)
{
pfc_it it = pfc_find(&oper_pfc, device_name);
if (it == NULL) {
/* Device not present: add */
pfc_attribs *store = (pfc_attribs*)malloc(sizeof(*store));
if (!store)
return false;
init_oper_pfc(store);
pfc_insert(&oper_pfc, device_name, store);
}
return true;
}
void init_peer_pfc(pfc_attribs *Attrib)
{
memset(Attrib,0,sizeof(*Attrib));
Attrib->protocol.TLVPresent = false;
}
bool add_peer_pfc(char *device_name)
{
pfc_it it = pfc_find(&peer_pfc, device_name);
if (it == NULL) {
/* Device not present: add */
pfc_attribs *store = (pfc_attribs*)malloc(sizeof(*store));
if (!store)
return false;
init_peer_pfc(store);
pfc_insert(&peer_pfc, device_name, store);
}
return true;
}
void init_bwg_desc(pg_info *Attrib, pg_info *Store)
{
memset(Store,0,sizeof(*Store));
memcpy(Store, Attrib, sizeof(*Attrib));
}
bool add_bwg_desc(char *device_name, pg_info *Attrib)
{
pg_desc_it it = pgdesc_find(&pg_desc, device_name);
if (it == NULL) {
/* Device not present: add */
pg_info *store = (pg_info*)malloc(sizeof(*store));
if (!store)
return false;
init_bwg_desc(Attrib, store);
store->max_pgid_desc = 8;
pgdesc_insert(&pg_desc, device_name, store);
}
return true;
}
/* Logical Link */
void init_llink(llink_attribs *Attrib, llink_attribs *Store)
{
memset(Store,0,sizeof(*Store));
Attrib->protocol.Max_version = DCB_LLINK_MAX_VERSION;
Attrib->protocol.State = DCB_INIT;
Attrib->protocol.Advertise_prev = false;
Attrib->protocol.tlv_sent = false;
Attrib->protocol.dcbx_st = gdcbx_subtype & MASK_DCBX_FORCE;
memcpy(Store, Attrib, sizeof(*Attrib));
}
bool add_llink(char *device_name, llink_attribs *Attrib, u32 subtype)
{
llink_it it = llink_find(&llink, device_name, subtype);
if (it == NULL) {
/* Device not present: add */
llink_attribs *store = (llink_attribs*)malloc(sizeof(*store));
if (!store)
return false;
init_llink(Attrib, store);
llink_insert(&llink, device_name, store, subtype);
} else { /* already present in store, just update */
it->second->protocol.Advertise_prev =
it->second->protocol.Advertise;
it->second->protocol.Advertise = Attrib->protocol.Advertise;
it->second->protocol.Enable = Attrib->protocol.Enable;
it->second->protocol.Willing = Attrib->protocol.Willing;
memcpy(&(it->second->llink), &(Attrib->llink),
sizeof(Attrib->llink));
}
return true;
}
void init_oper_llink(llink_attribs *Attrib, u32 subtype)
{
memset(Attrib,0,sizeof(*Attrib));
llink_it itllink = llink_find(&oper_llink, DEF_CFG_STORE, subtype);
if (itllink == NULL)
return;
memcpy(&(Attrib->llink), &(itllink->second->llink),
sizeof(Attrib->llink));
}
bool add_oper_llink(char *device_name, u32 subtype)
{
llink_it it = llink_find(&oper_llink, device_name, subtype);
if (it == NULL) {
/* Device not present: add */
llink_attribs *store = (llink_attribs*)malloc(sizeof(*store));
if (!store)
return false;
init_oper_llink(store, subtype);
llink_insert(&oper_llink, device_name, store, subtype);
}
return true;
}
void init_peer_llink(llink_attribs *Attrib)
{
memset(Attrib,0,sizeof(*Attrib));
Attrib->protocol.TLVPresent = false;
}
bool add_peer_llink(char *device_name, u32 subtype)
{
llink_it it = llink_find(&peer_llink, device_name, subtype);
if (it == NULL) {
/* Device not present: add */
llink_attribs *store = (llink_attribs*)malloc(sizeof(*store));
if (!store)
return false;
init_peer_llink(store);
llink_insert(&peer_llink, device_name, store, subtype);
}
return true;
}
bool init_dcb_support(char *device_name, full_dcb_attribs *attrib)
{
feature_support dcb_support;
memset(&dcb_support, 0, sizeof(feature_support));
if (get_dcb_capabilities(device_name, &dcb_support) != 0)
return false;
/*if (!dcb_support.pg) {
* attrib->pg.protocol.Enable = false;
* attrib->pg.protocol.Advertise = false;
*}
*if (!dcb_support.pfc) {
* attrib->pfc.protocol.Enable = false;
* attrib->pfc.protocol.Advertise = false;
*}
*/
if (get_dcb_numtcs(device_name, &attrib->pg.num_tcs,
&attrib->pfc.num_tcs) != 0) {
return false;
}
features_it it = features_find(&feature_struct, device_name);
if (it == NULL) {
/* Device not present: add */
feature_support *store = (feature_support*)
malloc(sizeof(*store));
if (!store)
return false;
memcpy(store, (void *)&dcb_support, sizeof(*store));
features_insert(&feature_struct, device_name, store);
}
return true;
}
cmd_status get_dcb_support(char *device_name, feature_support *dcb_support)
{
cmd_status result = cmd_success;
feature_support features;
full_dcb_attribs attribs;
memset(&attribs, 0, sizeof(attribs));
memset(&features, 0, sizeof(feature_support));
if (!dcb_support)
return cmd_bad_params;
features_it it = features_find(&feature_struct, device_name);
if (it != NULL) {
memcpy(dcb_support, it->second, sizeof(*dcb_support));
} else {
if (get_persistent(device_name, &attribs) != cmd_success) {
result = cmd_device_not_found;
goto Exit;
}
if (!init_dcb_support(device_name, &attribs)) {
result = cmd_device_not_found;
goto Exit;
}
/*todo: this was called twice?*/
memset(&features, 0, sizeof(feature_support));
features_it it = features_find(&feature_struct, device_name);
if (it != NULL) {
memcpy(dcb_support, it->second, sizeof(*dcb_support));
} else {
result = cmd_device_not_found;
}
}
Exit:
return result;
}
void remove_dcb_support(void)
{
while (feature_struct.lh_first != NULL) /* Delete. */
features_erase(&feature_struct.lh_first);
}
int dcbx_add_adapter(char *device_name)
{
u32 EventFlag = 0;
full_dcb_attrib_ptrs attr_ptr;
full_dcb_attribs attribs;
feature_support dcb_support = { .pg = 0 };
cmd_status sResult = cmd_success;
dcbx_state state;
int i = 0;
memset(&attribs, 0, sizeof(attribs));
sResult = get_persistent(device_name, &attribs);
if (sResult != cmd_success) {
LLDPAD_DBG("get_persistent returned error %d\n", sResult);
sResult = cmd_failed;
goto add_adapter_error;
}
LLDPAD_DBG(" dcbx subtype = %d\n", gdcbx_subtype);
memset (&attr_ptr, 0, sizeof(attr_ptr));
attr_ptr.pg = &(attribs.pg);
attr_ptr.pfc = &(attribs.pfc);
memset(&state, 0, sizeof(state));
get_dcbx_state(device_name, &state);
/* Create data stores for the device. */
if (!init_dcb_support(device_name, &attribs)) {
sResult = cmd_failed;
goto add_adapter_error;
}
sResult = dcb_check_config(&attr_ptr);
if (sResult != cmd_success)
LLDPAD_WARN("Rule checker returned error %d\n", sResult);
if (!add_pg(device_name, &attribs.pg)) {
LLDPAD_DBG("add_pg error.\n");
sResult = cmd_failed;
goto add_adapter_error;
}
if (!add_pfc(device_name, &attribs.pfc)) {
LLDPAD_DBG("add_pfc error.\n");
sResult = cmd_failed;
goto add_adapter_error;
}
if (!add_bwg_desc(device_name, &attribs.descript)) {
LLDPAD_DBG("add_bwg_desc error.\n");
sResult = cmd_failed;
goto add_adapter_error;
}
if (!add_control_protocol(device_name, &state)) {
LLDPAD_DBG("add_control_protocol error.\n");
sResult = cmd_failed;
goto add_adapter_error;
}
if (!add_peer_pg(device_name)) {
LLDPAD_DBG("add_peer_pg error.\n");
sResult = cmd_failed;
goto add_adapter_error;
}
if (!add_peer_pfc(device_name)) {
LLDPAD_DBG("add_peer_pfc error.\n");
sResult = cmd_failed;
goto add_adapter_error;
}
if (!add_peer_control_protocol(device_name)) {
LLDPAD_DBG("add_peer_control_protocol error.\n");
sResult = cmd_failed;
goto add_adapter_error;
}
if (!add_oper_pg(device_name)) {
LLDPAD_DBG("add_oper_pg error.\n");
sResult = cmd_failed;
goto add_adapter_error;
}
if (!add_oper_pfc(device_name)) {
LLDPAD_DBG("add_oper_pfc error.\n");
sResult = cmd_failed;
goto add_adapter_error;
}
/* Add APPTLV for supported Subtypes. */
for (i = 0; i < DCB_MAX_APPTLV; i++) {
if (!add_apptlv(device_name,
&attribs.app[i], i, &state)) {
LLDPAD_DBG("add_apptlv error.\n");
sResult = cmd_failed;
goto add_adapter_error;
}
if (!add_oper_apptlv(device_name, i)) {
LLDPAD_DBG("add_oper_apptlv error.\n");
sResult = cmd_failed;