1 Star 0 Fork 0

sdlhk/lldpad

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
dcb_protocol.c 110.64 KB
一键复制 编辑 原始数据 按行查看 历史
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057
/*******************************************************************************
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 <lldp-devel@open-lldp.org>
*******************************************************************************/
#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(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;
goto add_adapter_error;
}
if (!add_peer_apptlv(device_name, i)) {
LLDPAD_DBG("add_peer_apptlv error.\n");
sResult = cmd_failed;
goto add_adapter_error;
}
}
for (i = 0; i < DCB_MAX_LLKTLV; i++) {
if (!add_llink(device_name, &attribs.llink[i], i)) {
LLDPAD_DBG("%s add_llink error.\n",
device_name);
sResult = cmd_failed;
goto add_adapter_error;
}
if (!add_oper_llink(device_name, i)) {
LLDPAD_DBG("add_oper_llink error.\n");
sResult = cmd_failed;
goto add_adapter_error;
}
if (!add_peer_llink(device_name, i)) {
LLDPAD_DBG("add_peer_llink error.\n");
sResult = cmd_failed;
goto add_adapter_error;
}
}
if (get_dcb_support(device_name, &dcb_support) != cmd_success) {
sResult = cmd_failed;
goto add_adapter_error;
}
/* Initialize features state machines for PG and PFC and
* APPTLVs. */
if (run_feature_protocol(device_name,
DCB_LOCAL_CHANGE_PG, SUBTYPE_DEFAULT) !=
cmd_success) {
LLDPAD_DBG("run_feature_protocol error (PG)\n");
sResult = cmd_failed;
goto add_adapter_error;
}
if (run_feature_protocol(device_name,
DCB_LOCAL_CHANGE_PFC, SUBTYPE_DEFAULT) != cmd_success) {
LLDPAD_DBG("run_feature_protocol error (PFC)\n");
sResult = cmd_failed;
goto add_adapter_error;
}
/* If APPTLV subtypes are supported then run the
* feat_prot for those supported subtypes. */
for (i = 0; i < DCB_MAX_APPTLV ; i++) {
if (run_feature_protocol(device_name,
DCB_LOCAL_CHANGE_APPTLV(i), i) !=
cmd_success) {
LLDPAD_DBG("run_feature_protocol error (APP)\n");
sResult = cmd_failed;
goto add_adapter_error;
}
}
for (i = 0; i < DCB_MAX_LLKTLV ; i++) {
if (run_feature_protocol(device_name,
DCB_LOCAL_CHANGE_LLINK, i) != cmd_success) {
LLDPAD_DBG("run_feature_protocol error (LLINK)\n");
sResult = cmd_failed;
goto add_adapter_error;
}
}
EventFlag = 0;
DCB_SET_FLAGS(EventFlag, DCB_LOCAL_CHANGE_PG |
DCB_LOCAL_CHANGE_PFC | DCB_LOCAL_CHANGE_LLINK);
for (i = 0; i < DCB_MAX_APPTLV; i++)
DCB_SET_FLAGS(EventFlag, DCB_LOCAL_CHANGE_APPTLV(i));
/* Initialize control state machine */
if (run_control_protocol(device_name, EventFlag) !=
cmd_success) {
LLDPAD_DBG("run_control_protocol error.\n");
sResult = cmd_failed;
goto add_adapter_error;
}
add_adapter_error:
if (sResult != cmd_success) {
LLDPAD_DBG("add_adapter: Service unable to use network adapter\n");
return false;
}
return true;
}
int dcbx_remove_adapter(char *device_name)
{
char devName[MAX_DEVICE_NAME_LEN];
void *itp = NULL;
int not_default = 1;
int i = 0;
assert(device_name);
not_default = memcmp(DEF_CFG_STORE, device_name,
strlen(DEF_CFG_STORE));
strncpy (devName, device_name, MAX_DEVICE_NAME_LEN);
if (not_default)
handle_opermode_true(device_name);
features_it itfeat = features_find(&feature_struct, devName);
if (itfeat != NULL) {
LLDPAD_DBG("free: dcb support %p\n", itp);
features_erase(&itfeat);
} else {
LLDPAD_DBG("remove_adapter: dcb support not found\n");
}
pg_it itpg = pg_find(&pg, devName);
if (itpg != NULL) {
/* this line frees the param of this function! */
pg_erase(&itpg);
} else {
LLDPAD_DBG("remove_adapter: pg not found\n");
}
pfc_it itpfc = pfc_find(&pfc,devName);
if (itpfc != NULL) {
pfc_erase(&itpfc);
} else {
LLDPAD_DBG("remove_adapter: pfc not found\n");
}
pg_desc_it itbwg = pgdesc_find(&pg_desc, devName);
if (itbwg != NULL) {
pgdesc_erase(&itbwg);
} else if (not_default) {
LLDPAD_DBG("remove_adapter: pgid not found\n");
}
control_prot_it itcp = ctrl_prot_find(&dcb_control_prot, devName);
if (itcp != NULL) {
ctrl_prot_erase(&itcp);
} else if (not_default) {
LLDPAD_DBG("remove_adapter: ctrl not found\n");
}
pg_it itprpg = pg_find(&peer_pg, devName);
if (itprpg != NULL) {
pg_erase(&itprpg);
} else if (not_default) {
LLDPAD_DBG("remove_adapter: peer pg not found\n");
}
pfc_it itprpfc = pfc_find(&peer_pfc, devName);
if (itprpfc != NULL) {
pfc_erase(&itprpfc);
} else if (not_default) {
LLDPAD_DBG("remove_adapter: peer pfc not found\n");
}
control_prot_it itpcp = ctrl_prot_find(&dcb_peer_control_prot, devName);
if (itpcp != NULL) {
ctrl_prot_erase(&itpcp);
} else if (not_default) {
LLDPAD_DBG("remove_adapter: peer ctrl not found\n");
}
pg_it itopg = pg_find(&oper_pg, devName);
if (itopg != NULL) {
pg_erase(&itopg);
} else if (not_default) {
LLDPAD_DBG("remove_adapter: oper pg not found\n");
}
pfc_it itopfc = pfc_find(&oper_pfc, devName);
if (itopfc != NULL) {
pfc_erase(&itopfc);
} else if (not_default) {
LLDPAD_DBG("remove_adapter: oper pfc not found\n");
}
/* Get the APP TLV and erase. */
for (i = 0; i < DCB_MAX_APPTLV ; i++) {
app_it itapp = apptlv_find(&apptlv, devName, i);
if (itapp != NULL)
apptlv_erase(&itapp);
itapp = apptlv_find(&oper_apptlv, devName, i);
if (itapp != NULL)
apptlv_erase(&itapp);
itapp = apptlv_find(&peer_apptlv, devName, i);
if (itapp != NULL)
apptlv_erase(&itapp);
}
for (i = 0; i < DCB_MAX_LLKTLV ; i++) {
/* Release LLINK data store */
llink_it itllink = llink_find(&llink, devName, i);
if (itllink != NULL)
llink_erase(&itllink);
else
LLDPAD_DBG("remove_adapter: llink not found\n");
llink_it itprllink = llink_find(&peer_llink, devName, i);
if (itprllink != NULL)
llink_erase(&itprllink);
else if (not_default)
LLDPAD_DBG("remove_adapter: peer llink not found\n");
llink_it itollink = llink_find(&oper_llink, devName, i);
if (itollink != NULL)
llink_erase(&itollink);
else if (not_default)
LLDPAD_DBG("remove_adapter: oper llink not found\n");
}
lldpad_shm_set_dcbx(device_name, DCBX_SUBTYPE0);
return true;
}
cmd_status save_dcbx_state(const char *device_name)
{
dcbx_state state;
app_attribs app_data;
control_prot_it ctrl_prot = ctrl_prot_find(&dcb_control_prot,
device_name);
if (ctrl_prot == NULL)
return cmd_device_not_found;
state.SeqNo = ctrl_prot->second->SeqNo;
state.AckNo = ctrl_prot->second->AckNo;
if (get_app((char *)device_name, 0, &app_data) == cmd_success)
state.FCoEenable = app_data.protocol.Enable;
else
return cmd_bad_params;
if (get_app((char *)device_name, 1, &app_data) == cmd_success)
state.iSCSIenable = app_data.protocol.Enable;
else
return cmd_bad_params;
if (set_dcbx_state(device_name, &state))
return cmd_success;
else
return cmd_failed;
}
static int dcbx_free_app_config(char *device_name)
{
app_it Oper, Local;
appgroup_attribs app_data;
/* Free FCoE APP data */
Oper = apptlv_find(&oper_apptlv, device_name, APP_FCOE_STYPE);
Local = apptlv_find(&apptlv, device_name, APP_FCOE_STYPE);
if (Oper || Local) {
app_data.dcb_app_idtype = DCB_APP_IDTYPE_ETHTYPE;
app_data.dcb_app_id = APP_FCOE_ETHTYPE;
app_data.dcb_app_priority = 0;
set_hw_app(device_name, &app_data);
}
/* Free iSCSI APP data */
Oper = apptlv_find(&oper_apptlv, device_name, APP_ISCSI_STYPE);
Local = apptlv_find(&apptlv, device_name, APP_ISCSI_STYPE);
if (Oper || Local) {
app_data.dcb_app_idtype = DCB_APP_IDTYPE_PORTNUM;
app_data.dcb_app_id = APP_ISCSI_PORT;
app_data.dcb_app_priority = 0;
set_hw_app(device_name, &app_data);
}
/* Free FIP APP data */
Oper = apptlv_find(&oper_apptlv, device_name, APP_FIP_STYPE);
Local = apptlv_find(&apptlv, device_name, APP_FIP_STYPE);
if (Oper || Local) {
app_data.dcb_app_idtype = DCB_APP_IDTYPE_ETHTYPE;
app_data.dcb_app_id = APP_FIP_ETHTYPE;
app_data.dcb_app_priority = 0;
set_hw_app(device_name, &app_data);
}
return 0;
}
int dcbx_remove_all(void)
{
pg_it it;
clear_dcbx_state();
for (it = pg.lh_first; it != NULL; it = it->entries.le_next) {
if (!memcmp(DEF_CFG_STORE, it->ifname,
strlen(DEF_CFG_STORE))) {
continue;
}
save_dcbx_state(it->ifname);
/* Remove kernel APP entries */
dcbx_free_app_config(it->ifname);
}
return 0;
}
bool add_pg_defaults()
{
pg_attribs pg_data;
char sTmp[MAX_DESCRIPTION_LEN];
bool result = true;
int index, portion, rmndr, temp;
/* todo: - must be a better way and place to do this */
if (pg_not_initted) {
LIST_INIT(&pg);
LIST_INIT(&oper_pg);
LIST_INIT(&peer_pg);
pg_not_initted = false;
}
memset(&pg_data, 0, sizeof(pg_attribs));
pg_data.protocol.Enable = 1;
pg_data.protocol.Willing = 1;
pg_data.protocol.Advertise = 1;
portion = BW_PERCENT/MAX_BANDWIDTH_GROUPS;
rmndr = BW_PERCENT % MAX_BANDWIDTH_GROUPS;
temp = rmndr;
for (index=0; index < MAX_BANDWIDTH_GROUPS; index++) {
pg_data.tx.pg_percent[index] = (u8)portion;
if (temp >0) {
pg_data.tx.pg_percent[index] += 1;
temp--;
}
}
for (index=0; index < MAX_USER_PRIORITIES; index++) {
pg_data.tx.up[index].pgid = (u8)(index);
pg_data.tx.up[index].bwgid = (u8)index;
pg_data.tx.up[index].percent_of_pg_cap = BW_PERCENT;
pg_data.tx.up[index].strict_priority = DCB_NONE;
}
temp = rmndr;
for (index=0; index < MAX_BANDWIDTH_GROUPS; index++) {
pg_data.rx.pg_percent[index] = (u8)portion;
if (temp >0) {
pg_data.rx.pg_percent[index]++;
temp--;
}
}
for (index=0; index < MAX_USER_PRIORITIES; index++) {
pg_data.rx.up[index].pgid = (u8)(index);
pg_data.rx.up[index].bwgid = (u8)index;
pg_data.rx.up[index].percent_of_pg_cap = BW_PERCENT;
pg_data.rx.up[index].strict_priority = DCB_NONE;
}
snprintf(sTmp, MAX_DESCRIPTION_LEN, DEF_CFG_STORE);
/* Create pg default data store for the device. */
if (!add_pg(sTmp, &pg_data))
result = false;
return result;
}
bool add_pfc_defaults()
{
pfc_attribs pfc_data;
char sTmp[MAX_DESCRIPTION_LEN];
bool result = true;
int index;
/* todo: - must be a better way and place to do this */
if (pfc_not_initted) {
LIST_INIT(&pfc);
LIST_INIT(&oper_pfc);
LIST_INIT(&peer_pfc);
pfc_not_initted = false;
}
memset (&pfc_data, 0, sizeof(pfc_attribs));
pfc_data.protocol.Enable = 1;
pfc_data.protocol.Willing = 1;
pfc_data.protocol.Advertise = 1;
for (index=0; index < MAX_TRAFFIC_CLASSES; index++)
pfc_data.admin[index] = PFC_DISABLED;
snprintf(sTmp, MAX_DESCRIPTION_LEN, DEF_CFG_STORE);
/* Create pfc default data store for the device. */
if (!add_pfc(sTmp, &pfc_data))
result = false;
return result;
}
bool add_app_defaults(u32 subtype)
{
app_attribs app_data;
char sTmp[MAX_DESCRIPTION_LEN];
bool result = true;
/* todo: - must be a better way and place to do this */
if (app_not_initted) {
LIST_INIT(&apptlv);
LIST_INIT(&oper_apptlv);
LIST_INIT(&peer_apptlv);
app_not_initted = false;
}
memset(&app_data, 0, sizeof(app_attribs));
app_data.protocol.Enable = 1;
app_data.protocol.Willing = 1;
app_data.protocol.Advertise = 1;
snprintf(sTmp, MAX_DESCRIPTION_LEN, DEF_CFG_STORE);
switch (subtype) {
case APP_FCOE_STYPE: /* FCoE subtype */
app_data.Length = 1;
app_data.AppData[0] = APP_FCOE_DEFAULT_DATA;
break;
case APP_ISCSI_STYPE: /* iSCSI subtype */
app_data.Length = 1;
app_data.AppData[0] = APP_ISCSI_DEFAULT_DATA;
break;
case APP_FIP_STYPE: /* FIP subtype */
app_data.Length = 1;
app_data.AppData[0] = APP_FIP_DEFAULT_DATA;
default:
break;
}
/* Create app default data store for the device and app subtype. */
if (!add_apptlv(sTmp, &app_data, subtype, NULL))
result = false;
return result;
}
bool add_llink_defaults(u32 subtype)
{
llink_attribs llink_data;
char sTmp[MAX_DESCRIPTION_LEN];
bool result = true;
/* todo: - must be a better way and place to do this */
if (llink_not_initted) {
LIST_INIT(&llink);
LIST_INIT(&oper_llink);
LIST_INIT(&peer_llink);
llink_not_initted = false;
}
memset(&llink_data, 0, sizeof(llink_attribs));
llink_data.protocol.Enable = 1;
llink_data.protocol.Willing = 1;
llink_data.protocol.Advertise = 1;
llink_data.llink.llink_status = 0;
snprintf(sTmp, MAX_DESCRIPTION_LEN, DEF_CFG_STORE);
/* Create llink default data store for the device. */
if (!add_llink(sTmp, &llink_data, subtype))
result = false;
return result;
}
cmd_status get_pg(char *device_name, pg_attribs *pg_data)
{
cmd_status result = cmd_success;
full_dcb_attribs attribs;
if (!pg_data)
return cmd_bad_params;
memset(&attribs, 0, sizeof(attribs));
pg_it it = pg_find(&pg, device_name);
if (it != NULL) {
memcpy(pg_data, it->second, sizeof(*pg_data));
} else {
result = get_persistent(device_name, &attribs);
if (result == cmd_success)
memcpy(pg_data, &attribs.pg, sizeof(*pg_data));
else
result = cmd_device_not_found;
}
return result;
}
cmd_status get_oper_pg(char *device_name, pg_attribs *pg_data)
{
cmd_status result = cmd_success;
if (!pg_data)
return cmd_bad_params;
pg_it it = pg_find(&oper_pg, device_name);
if (it != NULL)
memcpy(pg_data, it->second, sizeof(*pg_data));
else
result = cmd_device_not_found;
return result;
}
cmd_status get_peer_pg(char *device_name, pg_attribs *pg_data)
{
cmd_status result = cmd_success;
if (!pg_data)
return cmd_bad_params;
pg_it it = pg_find(&peer_pg, device_name);
if (it != NULL)
memcpy(pg_data, it->second, sizeof(*pg_data));
else
result = cmd_device_not_found;
return result;
}
void mark_pg_sent(char *device_name)
{
pg_it it = pg_find(&pg, device_name);
if (it != NULL)
it->second->protocol.tlv_sent = true;
}
void mark_pfc_sent(char *device_name)
{
pfc_it it = pfc_find(&pfc, device_name);
if (it != NULL)
it->second->protocol.tlv_sent = true;
}
void mark_app_sent(char *device_name)
{
app_it it;
int i;
for (i = 0; i < DCB_MAX_APPTLV; i++) {
it = apptlv_find(&apptlv, device_name, i);
if (it != NULL)
it->second->protocol.tlv_sent = true;
}
}
void mark_llink_sent(char *device_name, u32 subtype)
{
llink_it it = llink_find(&llink, device_name, subtype);
if (it != NULL)
it->second->protocol.tlv_sent = true;
}
cmd_status put_pg(char *device_name, pg_attribs *pg_data, pfc_attribs *pfc_data)
{
full_dcb_attribs attribs;
full_dcb_attrib_ptrs attr_ptr;
u32 EventFlag = 0;
cmd_status result = cmd_success;
if (!pg_data)
return cmd_bad_params;
memset(&attribs, 0, sizeof(attribs));
pg_it it = pg_find(&pg, device_name);
if (it != NULL) {
/* Lock the data first */
/* detect no config change */
if (memcmp(it->second, pg_data, sizeof(*pg_data)) == 0)
goto Exit;
/* Check the rules */
memset(&attr_ptr, 0, sizeof(attr_ptr));
attr_ptr.pg = pg_data;
attr_ptr.pfc = pfc_data;
if (dcb_check_config(&attr_ptr) != cmd_success) {
LLDPAD_DBG("Rule checking failed in put_pg()\n");
result = cmd_bad_params;
goto Exit;
}
if (set_persistent(device_name, &attr_ptr) != cmd_success) {
LLDPAD_DBG("Set persistent failed put_pg()\n");
result = cmd_device_not_found;
goto Exit;
}
/* Copy the writable protocol * variables */
feature_protocol_attribs *dStore = &(it->second->protocol);
if (dStore->Enable && !(pg_data->protocol.Enable))
LLDPAD_INFO("%s PG disabled\n", device_name);
else if (!(dStore->Enable) && pg_data->protocol.Enable)
LLDPAD_INFO("%s PG enabled\n", device_name);
dStore->Advertise_prev = dStore->Advertise;
dStore->Advertise = pg_data->protocol.Advertise;
dStore->Enable = pg_data->protocol.Enable;
dStore->Willing = pg_data->protocol.Willing;
dStore->tlv_sent = false;
memcpy(&(it->second->rx), &(pg_data->rx), sizeof(pg_data->rx));
memcpy(&(it->second->tx), &(pg_data->tx), sizeof(pg_data->tx));
if (it->second->protocol.dcbx_st == DCBX_SUBTYPE2)
it->second->num_tcs = pg_data->num_tcs;
DCB_SET_FLAGS(EventFlag, DCB_LOCAL_CHANGE_PG);
/* Run the protocol */
result = run_dcb_protocol(device_name, EventFlag,
SUBTYPE_DEFAULT);
} else {
/* Not in DCB data store, so store in persistent storage */
if (get_persistent(device_name, &attribs) == cmd_success) {
memset(&attr_ptr, 0, sizeof(attr_ptr));
attr_ptr.pg = pg_data;
attr_ptr.pgid = &attribs.descript;
if (set_persistent(device_name, &attr_ptr) !=
cmd_success) {
LLDPAD_DBG("Set persistent failed in put_pg()\n");
result = cmd_device_not_found;
}
} else {
result = cmd_device_not_found;
}
}
Exit:
return result;
}
cmd_status put_peer_pg(char *device_name, pg_attribs *peer_pg_data)
{
/* this function relies on the caller to acquire the DCB lock */
cmd_status result = cmd_success;
feature_protocol_attribs *dStore;
if (!peer_pg_data)
return cmd_bad_params;
pg_it peer_it = pg_find(&peer_pg, device_name);
if (peer_it == NULL) {
LLDPAD_DBG("could not find peer_pg data for %s\n", device_name);
result = cmd_device_not_found;
goto Exit;
}
if (peer_pg_data->protocol.dcbx_st == DCBX_SUBTYPE2)
rebalance_uppcts(peer_pg_data);
/* detect config change */
if (memcmp(peer_it->second, peer_pg_data, sizeof(*peer_pg_data)) == 0)
goto Exit;
/* Copy the writable protocol variables. */
dStore = &(peer_it->second->protocol);
dStore->Advertise_prev = dStore->Advertise;
dStore->Advertise = peer_pg_data->protocol.Advertise;
dStore->Enable = peer_pg_data->protocol.Enable;
dStore->Willing = peer_pg_data->protocol.Willing;
dStore->Oper_version = peer_pg_data->protocol.Oper_version;
dStore->Max_version = peer_pg_data->protocol.Max_version;
dStore->TLVPresent = peer_pg_data->protocol.TLVPresent;
dStore->Error = peer_pg_data->protocol.Error;
dStore->dcbx_st = peer_pg_data->protocol.dcbx_st;
dStore->Error_Flag = peer_pg_data->protocol.Error_Flag;
memcpy(&(peer_it->second->rx), &(peer_pg_data->rx),
sizeof(peer_pg_data->rx));
memcpy(&(peer_it->second->tx), &(peer_pg_data->tx),
sizeof(peer_pg_data->tx));
if (peer_it->second->protocol.dcbx_st == DCBX_SUBTYPE2)
peer_it->second->num_tcs = peer_pg_data->num_tcs;
Exit:
return result;
}
cmd_status get_pfc(char *device_name, pfc_attribs *pfc_data)
{
cmd_status result = cmd_success;
full_dcb_attribs attribs;
memset(&attribs, 0, sizeof(attribs));
if (!pfc_data)
return cmd_bad_params;
pfc_it it = pfc_find(&pfc, device_name);
if (it != NULL) {
memcpy(pfc_data, it->second, sizeof(*pfc_data));
} else {
result = get_persistent(device_name, &attribs);
if (result == cmd_success)
memcpy(pfc_data, &attribs.pfc, sizeof(*pfc_data));
else
result = cmd_device_not_found;
}
return result;
}
cmd_status get_oper_pfc(char *device_name, pfc_attribs *pfc_data)
{
cmd_status result = cmd_success;
if (!pfc_data)
return cmd_bad_params;
pfc_it it = pfc_find(&oper_pfc, device_name);
if (it != NULL)
memcpy(pfc_data, it->second, sizeof(*pfc_data));
else
result = cmd_device_not_found;
return result;
}
cmd_status get_peer_pfc(char *device_name, pfc_attribs *pfc_data)
{
cmd_status result = cmd_success;
if (!pfc_data)
return cmd_bad_params;
pfc_it it = pfc_find(&peer_pfc, device_name);
if (it != NULL)
memcpy(pfc_data, it->second, sizeof(*pfc_data));
else
result = cmd_device_not_found;
return result;
}
cmd_status put_pfc(char *device_name, pfc_attribs *pfc_data)
{
u32 EventFlag = 0;
cmd_status result = cmd_success;
full_dcb_attribs attribs;
bool bChange = false;
full_dcb_attrib_ptrs attr_ptr;
if (!pfc_data)
return cmd_bad_params;
memset(&attribs, 0, sizeof(attribs));
pfc_it it = pfc_find(&pfc, device_name);
if (it != NULL) {
/* detect no config change */
if (memcmp(it->second, pfc_data, sizeof(*pfc_data)) == 0)
goto Exit;
bChange = true;
memset(&attr_ptr, 0, sizeof(attr_ptr));
attr_ptr.pfc = pfc_data;
if (set_persistent(device_name, &attr_ptr) != cmd_success) {
LLDPAD_DBG("Set persistent failed in put_pfc()\n");
result = cmd_device_not_found;
goto Exit;
}
feature_protocol_attribs *dStore = &(it->second->protocol);
if (dStore->Enable && !(pfc_data->protocol.Enable))
LLDPAD_INFO("%s PFC disabled\n", device_name);
else if (!(dStore->Enable) && pfc_data->protocol.Enable)
LLDPAD_INFO("%s PFC enabled\n", device_name);
dStore->Advertise_prev = dStore->Advertise;
dStore->Advertise = pfc_data->protocol.Advertise;
dStore->Enable = pfc_data->protocol.Enable;
dStore->Willing = pfc_data->protocol.Willing;
dStore->tlv_sent = false;
memcpy(it->second->admin, pfc_data->admin,
sizeof(pfc_data->admin));
if (it->second->protocol.dcbx_st == DCBX_SUBTYPE2)
it->second->num_tcs = pfc_data->num_tcs;
/* Run the protocol */
DCB_SET_FLAGS(EventFlag, DCB_LOCAL_CHANGE_PFC);
if (bChange)
result = run_dcb_protocol(device_name, EventFlag,
SUBTYPE_DEFAULT);
} else {
/* Store in persistent storage - not in DCB data store */
if (get_persistent(device_name, &attribs) == cmd_success) {
memset(&attr_ptr, 0, sizeof(attr_ptr));
attr_ptr.pfc = pfc_data;
attr_ptr.pgid = &attribs.descript;
if (set_persistent(device_name, &attr_ptr) !=
cmd_success) {
result = cmd_device_not_found;
}
} else
result = cmd_device_not_found;
}
Exit:
return result;
}
cmd_status put_peer_pfc(char *device_name, pfc_attribs *peer_pfc_data)
{
/* this function relies on the caller to acquire the DCB lock */
cmd_status result = cmd_success;
feature_protocol_attribs *dStore;
if (!peer_pfc_data)
return cmd_bad_params;
pfc_it peer_it = pfc_find(&peer_pfc, device_name);
if (peer_it == NULL){
LLDPAD_DBG("putting peer_pfc data - bad device name\n");
result = cmd_device_not_found;
goto Exit;
}
/* detect config change */
if (memcmp(peer_it->second, peer_pfc_data, sizeof(*peer_pfc_data)) == 0)
goto Exit;
dStore = &(peer_it->second->protocol);
dStore->Advertise_prev = dStore->Advertise;
dStore->Advertise = peer_pfc_data->protocol.Advertise;
dStore->Enable = peer_pfc_data->protocol.Enable;
dStore->Willing = peer_pfc_data->protocol.Willing;
dStore->Oper_version = peer_pfc_data->protocol.Oper_version;
dStore->Max_version = peer_pfc_data->protocol.Max_version;
dStore->TLVPresent = peer_pfc_data->protocol.TLVPresent;
dStore->Error = peer_pfc_data->protocol.Error;
dStore->dcbx_st = peer_pfc_data->protocol.dcbx_st;
dStore->Error_Flag = peer_pfc_data->protocol.Error_Flag;
memcpy(peer_it->second->admin, &peer_pfc_data->admin,
sizeof(peer_pfc_data->admin));
if (peer_it->second->protocol.dcbx_st == DCBX_SUBTYPE2)
peer_it->second->num_tcs = peer_pfc_data->num_tcs;
Exit:
return result;
}
cmd_status get_app(char *device_name, u32 subtype, app_attribs *app_data)
{
cmd_status result = cmd_success;
full_dcb_attribs attribs;
memset(&attribs, 0, sizeof(attribs));
app_it it = apptlv_find(&apptlv, device_name, subtype);
if (it != NULL) {
memcpy(app_data, it->second, sizeof(*app_data));
} else {
result = get_persistent(device_name, &attribs);
if (result == cmd_success) {
memcpy(app_data, &attribs.app[subtype],
sizeof(*app_data));
} else
result = cmd_device_not_found;
}
return result;
}
cmd_status get_oper_app(char *device_name, u32 subtype, app_attribs *app_data)
{
cmd_status result = cmd_success;
app_it it = apptlv_find(&oper_apptlv, device_name, subtype);
if (it != NULL)
memcpy(app_data, it->second, sizeof(*app_data));
else
result = cmd_device_not_found;
return result;
}
cmd_status get_peer_app(char *device_name, u32 subtype, app_attribs *app_data)
{
cmd_status result = cmd_success;
app_it it = apptlv_find(&peer_apptlv, device_name, subtype);
if (it != NULL)
memcpy(app_data, it->second, sizeof(*app_data));
else
result = cmd_device_not_found;
return result;
}
cmd_status put_app(char *device_name, u32 subtype, app_attribs *app_data)
{
full_dcb_attribs attribs;
full_dcb_attrib_ptrs attr_ptr;
u32 EventFlag = 0;
cmd_status result = cmd_success;
unsigned i;
if (!app_data)
return cmd_bad_params;
memset(&attribs, 0, sizeof(attribs));
app_it it = apptlv_find(&apptlv, device_name, subtype);
if (it != NULL) {
/* detect no config change */
if (memcmp(it->second, app_data,
sizeof(*app_data)) == 0) {
goto Exit;
}
/* Store in persistent storage */
memset(&attr_ptr, 0, sizeof(attr_ptr));
attr_ptr.app = app_data;
attr_ptr.app_subtype = (u8)subtype;
if (set_persistent(device_name, &attr_ptr) != cmd_success) {
LLDPAD_DBG("Set persistent failed in put_app()\n");
return cmd_device_not_found;
}
for (i = 0; i < DCB_MAX_APPTLV; i++) {
if (i == subtype)
continue;
app_it ait = apptlv_find(&apptlv, device_name, i);
memset(&attr_ptr, 0, sizeof(attr_ptr));
attr_ptr.app = ait->second;
attr_ptr.app->protocol.Enable = app_data->protocol.Enable;
attr_ptr.app->protocol.Willing = app_data->protocol.Willing;
attr_ptr.app_subtype = i;
if (set_persistent(device_name, &attr_ptr) != cmd_success) {
LLDPAD_DBG("Set persistent failed put_app()\n");
return cmd_device_not_found;
}
}
feature_protocol_attribs *dStore = &(it->second->protocol);
if (dStore->Enable && !(app_data->protocol.Enable))
LLDPAD_INFO("%s APP disabled\n", device_name);
else if (!(dStore->Enable) && app_data->protocol.Enable)
LLDPAD_INFO("%s APP enabled\n", device_name);
dStore->Advertise_prev = dStore->Advertise;
dStore->Advertise = app_data->protocol.Advertise;
dStore->Enable = app_data->protocol.Enable;
dStore->Willing = app_data->protocol.Willing;
dStore->tlv_sent = false;
if (app_data->Length) {
it->second->Length = app_data->Length;
memcpy(&(it->second->AppData), &(app_data->AppData),
app_data->Length);
}
DCB_SET_FLAGS(EventFlag, DCB_LOCAL_CHANGE_APPTLV(subtype));
result = run_dcb_protocol(device_name, EventFlag, subtype);
} else {
/* Not in DCB data store, store in persistent storage */
if (get_persistent(device_name, &attribs) == cmd_success) {
memset(&attr_ptr, 0, sizeof(attr_ptr));
attr_ptr.app = app_data;
attr_ptr.app_subtype = (u8)subtype;
attr_ptr.pgid = &attribs.descript;
if (set_persistent(device_name, &attr_ptr) !=
cmd_success) {
LLDPAD_DBG("Set persistent failed in put_app()\n");
result = cmd_device_not_found;
}
} else {
result = cmd_device_not_found;
}
}
Exit:
return result;
}
cmd_status put_peer_app(char *device_name, u32 subtype,
app_attribs *peer_app_data)
{
/* this function relies on the caller to acquire the DCB lock */
feature_protocol_attribs *dStore;
cmd_status result = cmd_success;
if (!peer_app_data)
return cmd_bad_params;
app_it peer_it = apptlv_find(&peer_apptlv, device_name, subtype);
if (peer_it == NULL) {
LLDPAD_DBG("putting peer_app data - bad device name\n");
result = cmd_device_not_found;
goto Exit;
}
if (memcmp(peer_it->second, peer_app_data, sizeof(*peer_app_data)) == 0)
goto Exit;
dStore = &(peer_it->second->protocol);
dStore->Advertise_prev = dStore->Advertise;
dStore->Advertise = peer_app_data->protocol.Advertise;
dStore->Enable = peer_app_data->protocol.Enable;
dStore->Willing = peer_app_data->protocol.Willing;
dStore->Oper_version = peer_app_data->protocol.Oper_version;
dStore->Max_version = peer_app_data->protocol.Max_version;
dStore->TLVPresent = peer_app_data->protocol.TLVPresent;
dStore->Error = peer_app_data->protocol.Error;
dStore->dcbx_st = peer_app_data->protocol.dcbx_st;
dStore->Error_Flag = peer_app_data->protocol.Error_Flag;
peer_it->second->Length = peer_app_data->Length;
memcpy(&(peer_it->second->AppData), &(peer_app_data->AppData),
peer_app_data->Length);
Exit:
return result;
}
cmd_status put_llink(char *device_name, u32 subtype, llink_attribs *llink_data)
{
full_dcb_attrib_ptrs attr_ptr;
full_dcb_attribs attribs;
u32 EventFlag = 0;
cmd_status result = cmd_success;
bool bChange = false;
if (!llink_data)
return cmd_bad_params;
memset(&attribs, 0, sizeof(attribs));
llink_it it = llink_find(&llink, device_name, subtype);
if (it != NULL) {
/* Lock the data first */
/* detect no config change */
if (memcmp(it->second, llink_data, sizeof(*llink_data)) == 0)
goto Exit;
bChange = true;
memset(&attr_ptr, 0, sizeof(attr_ptr));
attr_ptr.llink = llink_data;
attr_ptr.llink_subtype = LLINK_FCOE_STYPE;
if (set_persistent(device_name, &attr_ptr) != cmd_success) {
LLDPAD_DBG("Set persistent failed in put_llink()\n");
result = cmd_device_not_found;
goto Exit;
}
feature_protocol_attribs *dStore = &(it->second->protocol);
if (dStore->Enable && !(llink_data->protocol.Enable))
LLDPAD_INFO("%s LLINK disabled\n", device_name);
else if (!(dStore->Enable) && llink_data->protocol.Enable)
LLDPAD_INFO("%s LLINK enabled\n", device_name);
dStore->Advertise_prev = dStore->Advertise;
dStore->Advertise = llink_data->protocol.Advertise;
dStore->Enable = llink_data->protocol.Enable;
dStore->Willing = llink_data->protocol.Willing;
dStore->tlv_sent = false;
it->second->llink.llink_status = llink_data->llink.llink_status;
memcpy(&(it->second->llink), &(llink_data->llink),
sizeof(llink_data->llink));
/* Run the protocol */
DCB_SET_FLAGS(EventFlag, DCB_LOCAL_CHANGE_LLINK);
if (bChange) {
result = run_dcb_protocol(device_name, EventFlag,
SUBTYPE_DEFAULT);
}
} else {
/* Store in persistent storage - though not in DCB data store*/
if (get_persistent(device_name, &attribs) == cmd_success) {
memset(&attr_ptr, 0, sizeof(attr_ptr));
attr_ptr.llink = llink_data;
attr_ptr.llink_subtype = LLINK_FCOE_STYPE;
attr_ptr.pgid = &attribs.descript;
if (set_persistent(device_name, &attr_ptr)
!= cmd_success) {
result = cmd_device_not_found;
}
} else
result = cmd_device_not_found;
}
Exit:
return result;
}
cmd_status put_peer_llink(char *device_name, u32 subtype,
llink_attribs *peer_llink_data)
{
/* this function relies on the caller to acquire the DCB lock */
feature_protocol_attribs *dStore;
cmd_status result = cmd_success;
if (!peer_llink_data)
return cmd_bad_params;
llink_it peer_it = llink_find(&peer_llink, device_name, subtype);
if (peer_it == NULL){
LLDPAD_DBG("putting peer_llink data - bad device name\n");
result = cmd_device_not_found;
goto Exit;
}
/* detect config change */
if (memcmp(peer_it->second, peer_llink_data,
sizeof(*peer_llink_data)) == 0) {
goto Exit;
}
dStore = &(peer_it->second->protocol);
dStore->Advertise_prev = dStore->Advertise;
dStore->Advertise = peer_llink_data->protocol.Advertise;
dStore->Enable = peer_llink_data->protocol.Enable;
dStore->Willing = peer_llink_data->protocol.Willing;
dStore->Oper_version = peer_llink_data->protocol.Oper_version;
dStore->Max_version = peer_llink_data->protocol.Max_version;
dStore->TLVPresent = peer_llink_data->protocol.TLVPresent;
dStore->Error = peer_llink_data->protocol.Error;
dStore->dcbx_st = peer_llink_data->protocol.dcbx_st;
dStore->Error_Flag = peer_llink_data->protocol.Error_Flag;
memcpy(&(peer_it->second->llink), &(peer_llink_data->llink),
sizeof(peer_llink_data->llink));
Exit:
return result;
}
cmd_status get_llink(char *device_name, u32 subtype, llink_attribs *llink_data)
{
full_dcb_attribs attribs;
cmd_status result = cmd_success;
memset(&attribs, 0, sizeof(attribs));
if (!llink_data)
return cmd_bad_params;
llink_it it = llink_find(&llink, device_name, subtype);
if (it != NULL) {
memcpy(llink_data, it->second, sizeof(*llink_data));
} else {
result = get_persistent(device_name, &attribs);
if (result == cmd_success)
memcpy(llink_data, &attribs.llink[subtype],
sizeof(*llink_data));
else
result = cmd_device_not_found;
}
return result;
}
cmd_status get_oper_llink(char *device_name, u32 subtype,
llink_attribs *llink_data)
{
cmd_status result = cmd_success;
if (!llink_data)
return cmd_bad_params;
llink_it it = llink_find(&oper_llink, device_name, subtype);
if (it != NULL)
memcpy(llink_data, it->second, sizeof(*llink_data));
else
result = cmd_device_not_found;
return result;
}
cmd_status get_peer_llink(char *device_name, u32 subtype,
llink_attribs *llink_data)
{
cmd_status result = cmd_success;
if (!llink_data)
return cmd_bad_params;
llink_it it = llink_find(&peer_llink, device_name, subtype);
if (it != NULL)
memcpy(llink_data, it->second, sizeof(*llink_data));
else
result = cmd_device_not_found;
return result;
}
cmd_status get_control(char *device_name,
control_protocol_attribs *control_data)
{
cmd_status result = cmd_success;
if (!control_data)
return cmd_bad_params;
control_prot_it it = ctrl_prot_find(&dcb_control_prot, device_name);
if (it != NULL)
memcpy( control_data, it->second, sizeof(*control_data));
else
result = cmd_device_not_found;
return result;
}
cmd_status get_peer_control(char *device_name,
control_protocol_attribs *peer_control_data)
{
cmd_status result = cmd_success;
if (!peer_control_data)
return cmd_bad_params;
control_prot_it it = ctrl_prot_find(&dcb_peer_control_prot,
device_name);
if (it != NULL)
memcpy(peer_control_data, it->second,
sizeof(*peer_control_data));
else
result = cmd_device_not_found;
return result;
}
cmd_status put_peer_control(char *device_name,
control_protocol_attribs *peer_control_data)
{
/* this function relies on the caller to acquire the DCB lock */
control_protocol_attribs *dStore = NULL;
cmd_status result = cmd_success;
if (!peer_control_data)
return cmd_bad_params;
control_prot_it peer_ctrl_prot = ctrl_prot_find(&dcb_peer_control_prot,
device_name);
if (peer_ctrl_prot)
dStore = peer_ctrl_prot->second;
if (peer_ctrl_prot &&
((peer_control_data->Error_Flag & DUP_DCBX_TLV_CTRL) ||
(peer_control_data->Error_Flag & TOO_MANY_NGHBRS))) {
dStore->Error_Flag = peer_control_data->Error_Flag;
} else if (peer_ctrl_prot != NULL) {
dStore->SeqNo = peer_control_data->SeqNo;
dStore->AckNo = peer_control_data->AckNo;
dStore->Max_version = peer_control_data->Max_version;
dStore->Oper_version = peer_control_data->Oper_version;
dStore->RxDCBTLVState = peer_control_data->RxDCBTLVState;
dStore->Error_Flag = peer_control_data->Error_Flag;
} else {
result = cmd_device_not_found;
}
return result;
}
cmd_status get_bwg_descrpt(char *device_name, u8 bwgid, char **name)
{
full_dcb_attribs attribs;
cmd_status result = cmd_success;
int size;
if (*name != NULL) {
free(*name);
*name = NULL;
}
memset(&attribs, 0, sizeof(attribs));
pg_desc_it it = pgdesc_find(&pg_desc, device_name);
if ((it != NULL) &&
(bwgid < it->second->max_pgid_desc)) {
size = (int)strlen(it->second->pgid_desc[bwgid]) +
sizeof(char); /* Localization OK */
*name = (char*)malloc(size);
if (*name != NULL) {
strncpy(*name, it->second->pgid_desc[bwgid],
size); /* Localization OK */
} else {
goto Error;
}
} else {
result = get_persistent(device_name, &attribs);
if (result == cmd_success) {
size = (int)strlen(
attribs.descript.pgid_desc[bwgid]) +
sizeof(char);
*name = (char*)malloc(size);
if (*name != NULL) {
strncpy(*name,
attribs.descript.pgid_desc[bwgid],
size); /* Localization OK */
} else {
goto Error;
}
} else {
result = cmd_device_not_found;
}
}
return result;
Error:
LLDPAD_DBG("get_bwg_descrpt: Failed memory alloc\n");
return cmd_failed;
}
cmd_status put_bwg_descrpt(char *device_name, u8 bwgid, char *name)
{
full_dcb_attribs attribs;
full_dcb_attrib_ptrs attr_ptr;
cmd_status result = cmd_success;
unsigned int size;
if (!name)
return cmd_bad_params;
size = (unsigned int)strlen(name); /* Localization OK */
memset(&attribs, 0, sizeof(attribs));
pg_desc_it it = pgdesc_find(&pg_desc, device_name);
if ((it != NULL) &&
(bwgid < it->second->max_pgid_desc)) {
/* Only take as many characters as can be held */
if (!(size < sizeof(it->second->pgid_desc[bwgid])))
size = sizeof(it->second->pgid_desc[bwgid])-1;
memcpy(it->second->pgid_desc[bwgid], name, size);
/* Put a null at the end incase it was truncated */
it->second->pgid_desc[bwgid][size] = '\0';
memset(&attr_ptr, 0, sizeof(attr_ptr));
attr_ptr.pgid = it->second;
if (set_persistent(device_name, &attr_ptr) != cmd_success)
return cmd_device_not_found;
} else {
/* Store in persistent storage - though not in
* DCB data store */
if (get_persistent(device_name, &attribs) == cmd_success) {
if (!(size <
sizeof(attribs.descript.pgid_desc[bwgid])))
size = sizeof(
attribs.descript.pgid_desc[bwgid]) - 1;
memcpy(attribs.descript.pgid_desc[bwgid],
name, size);
/* Put a null at the end in case it was
* truncated */
attribs.descript.pgid_desc[bwgid][size] = '\0';
memset(&attr_ptr, 0, sizeof(attr_ptr));
attr_ptr.pgid = &attribs.descript;
if (set_persistent(device_name, &attr_ptr)
!= cmd_success) {
LLDPAD_DBG("Set persistent failed "
"in put_bwg_descrpt()\n");
result = cmd_device_not_found;
}
}
else
result = cmd_device_not_found;
}
return result;
}
/******************************************************************************
**
** Method: CopyConfigToOper
**
** Description: Function to copy local or peer PG or PFC or APPTLV
** configurations to oper configuration.
**
** Arguments: char *device_name
** u32 SrcFlag - Tells where to copy from (local or peer)
** u32 EventFlag
** u32 SubType - This is valid only for DCB_LOCAL_CHANGE_APPTLV and
** DCB_REMOTE_CHANGE_APPTLV
**
** Returns: true if successful, failure code otherwise.
**
******************************************************************************/
void CopyConfigToOper(char *device_name, u32 SrcFlag, u32 EventFlag,
u32 Subtype)
{
int i = 0;
/* this function relies on the caller to acquire the DCB lock */
LLDPAD_DBG(" CopyConfigToOper %s\n", device_name);
if (DCB_TEST_FLAGS(EventFlag, DCB_LOCAL_CHANGE_PG, DCB_LOCAL_CHANGE_PG)
|| DCB_TEST_FLAGS(EventFlag, DCB_REMOTE_CHANGE_PG,
DCB_REMOTE_CHANGE_PG)) {
/* Get the Local or Peer store */
pg_it Src;
pg_it localSrc = NULL;
if (SrcFlag == LOCAL_STORE) {
Src = localSrc = pg_find(&pg, device_name);
if (localSrc == NULL)
return;
} else if (SrcFlag == PEER_STORE) {
Src = pg_find(&peer_pg, device_name);
if (Src == NULL)
return;
localSrc = pg_find(&pg, device_name);
if (localSrc == NULL)
return;
} else {
/* We don't support */
return;
}
/* Get the Oper store */
pg_it Oper = pg_find(&oper_pg, device_name);
if (Oper == NULL)
return;
/* Copy Src to Oper. */
for (i = 0; i < MAX_USER_PRIORITIES; i++) {
Oper->second->tx.up[i].bwgid =
Src->second->tx.up[i].bwgid;
Oper->second->rx.up[i].bwgid =
Src->second->rx.up[i].bwgid;
Oper->second->tx.up[i].strict_priority =
Src->second->tx.up[i].strict_priority;
Oper->second->rx.up[i].strict_priority =
Src->second->rx.up[i].strict_priority;
Oper->second->tx.up[i].percent_of_pg_cap =
Src->second->tx.up[i].percent_of_pg_cap;
Oper->second->rx.up[i].percent_of_pg_cap =
Src->second->rx.up[i].percent_of_pg_cap;
if (SrcFlag == PEER_STORE) {
Oper->second->tx.up[i].pgid =
Src->second->tx.up[i].pgid;
Oper->second->rx.up[i].pgid =
Src->second->rx.up[i].pgid;
} else {
Oper->second->tx.up[i].pgid =
localSrc->second->tx.up[i].pgid;
Oper->second->rx.up[i].pgid =
localSrc->second->rx.up[i].pgid;
}
}
for (i = 0; i < MAX_BANDWIDTH_GROUPS; i++) {
Oper->second->tx.pg_percent[i] =
Src->second->tx.pg_percent[i];
Oper->second->rx.pg_percent[i] =
Src->second->rx.pg_percent[i];
}
} else if (DCB_TEST_FLAGS(EventFlag, DCB_LOCAL_CHANGE_PFC,
DCB_LOCAL_CHANGE_PFC) ||
DCB_TEST_FLAGS(EventFlag, DCB_REMOTE_CHANGE_PFC,
DCB_REMOTE_CHANGE_PFC)) {
/* Get the Local or Peer store */
pfc_it Src;
if (SrcFlag == LOCAL_STORE) {
Src = pfc_find(&pfc, device_name);
if (Src == NULL)
return;
}
else if (SrcFlag == PEER_STORE) {
Src = pfc_find(&peer_pfc, device_name);
if (Src == NULL)
return;
}
else {
/* We don't support */
return;
}
/* Get Oper store */
pfc_it Oper = pfc_find(&oper_pfc, device_name);
if (Oper == NULL)
return;
/* Copy Src to Oper. */
memcpy(&Oper->second->admin, &Src->second->admin,
sizeof(Src->second->admin));
} else if (DCB_TEST_FLAGS(EventFlag, DCB_LOCAL_CHANGE_APPTLV(Subtype),
DCB_LOCAL_CHANGE_APPTLV(Subtype))||
DCB_TEST_FLAGS(EventFlag,
DCB_REMOTE_CHANGE_APPTLV(Subtype),
DCB_REMOTE_CHANGE_APPTLV(Subtype))) {
/* Get the Local or Peer store */
app_it Src;
if (SrcFlag == LOCAL_STORE) {
Src = apptlv_find(&apptlv, device_name, Subtype);
if (Src == NULL)
return;
} else if (SrcFlag == PEER_STORE) {
Src = apptlv_find(&peer_apptlv, device_name,
Subtype);
if (Src == NULL)
return;
} else {
/* We don't support */
return;
}
/* Get Oper store */
app_it Oper = apptlv_find(&oper_apptlv, device_name,
Subtype);
if (Oper != NULL) {
/* Copy Src to Oper. */
LLDPAD_DBG(" Changing app data from %02x to %02x\n",
Oper->second->AppData[0],
Src->second->AppData[0]);
Oper->second->Length = Src->second->Length;
memcpy(Oper->second->AppData, Src->second->AppData,
Src->second->Length);
}
} else if (DCB_TEST_FLAGS(EventFlag, DCB_LOCAL_CHANGE_LLINK,
DCB_LOCAL_CHANGE_LLINK) ||
DCB_TEST_FLAGS(EventFlag, DCB_REMOTE_CHANGE_LLINK,
DCB_REMOTE_CHANGE_LLINK)) {
/* Get the Local or Peer store */
/* Get the Local or Peer store */
llink_it Src;
if (SrcFlag == LOCAL_STORE) {
Src = llink_find(&llink, device_name, Subtype);
if (Src == NULL)
return;
}
else if (SrcFlag == PEER_STORE) {
Src = llink_find(&peer_llink, device_name,
Subtype);
if (Src == NULL)
return;
}
else {
/* We don't support */
return;
}
/* Get Oper store */
llink_it Oper = llink_find(&oper_llink, device_name,
Subtype);
if (Oper == NULL) {
return;
}
/* Copy Src to Oper. */
memset(&Oper->second->llink, 0, sizeof(Oper->second->llink));
memcpy( &Oper->second->llink, &Src->second->llink,
sizeof(Src->second->llink));
}
}
/******************************************************************************
**
** Method: LocalPeerCompatible
**
** Description: Function to check if local and peer configurations matches.
**
** Arguments: char *device_name
** ULONG EventFlag
** ULONG SubType - This is valid only for DCB_LOCAL_CHANGE_APPTLV
** and DCB_REMOTE_CHANGE_APPTLV
**
** Returns: true if successful, failure code otherwise.
**
******************************************************************************/
bool LocalPeerCompatible(char *device_name, u32 EventFlag, u32 Subtype)
{
int i = 0;
if (DCB_TEST_FLAGS(EventFlag, DCB_LOCAL_CHANGE_PG, DCB_LOCAL_CHANGE_PG)
|| DCB_TEST_FLAGS(EventFlag, DCB_REMOTE_CHANGE_PG,
DCB_REMOTE_CHANGE_PG)) {
/* Get the Local and Peer PG store */
pg_it Local = pg_find(&pg, device_name);
pg_attribs *lpg;
pg_attribs *ppg;
bool match = false;
if (Local == NULL) {
goto Error;
}
pg_it Peer = pg_find(&peer_pg, device_name);
if (Peer == NULL) {
goto Error;
}
lpg = Local->second;
ppg = Peer->second;
match = true;
if (ppg->protocol.dcbx_st == DCBX_SUBTYPE1) {
for (i = 0; i < MAX_USER_PRIORITIES; i++) {
if (lpg->tx.up[i].bwgid !=
ppg->tx.up[i].bwgid)
match = false;
if (lpg->tx.up[i].strict_priority !=
ppg->tx.up[i].strict_priority)
match = false;
if (lpg->tx.up[i].percent_of_pg_cap !=
ppg->tx.up[i].percent_of_pg_cap)
match = false;
}
for (i = 0; i < MAX_BANDWIDTH_GROUPS; i++) {
if (lpg->tx.pg_percent[i] !=
ppg->tx.pg_percent[i])
match = false;
}
}
if (match) {
LLDPAD_DBG(" COMPAT PG - passed\n");
return true;
}
LLDPAD_DBG(" COMPAT PG - failed\n");
} else if (DCB_TEST_FLAGS(EventFlag, DCB_LOCAL_CHANGE_PFC,
DCB_LOCAL_CHANGE_PFC)||
DCB_TEST_FLAGS(EventFlag, DCB_REMOTE_CHANGE_PFC,
DCB_REMOTE_CHANGE_PFC)) {
/* Get the Local and Peer PFC store */
pfc_it Local = pfc_find(&pfc, device_name);
if (Local == NULL) {
goto Error;
}
pfc_it Peer = pfc_find(&peer_pfc, device_name);
if (Peer == NULL) {
goto Error;
}
if (!memcmp(&Local->second->admin,
&Peer->second->admin,
sizeof(Local->second->admin))) {
LLDPAD_DBG(" COMPAT PFC - passed\n");
return true;
}
LLDPAD_DBG(" COMPAT PFC - failed\n");
} else if (DCB_TEST_FLAGS(EventFlag, DCB_LOCAL_CHANGE_APPTLV(Subtype),
DCB_LOCAL_CHANGE_APPTLV(Subtype))||
DCB_TEST_FLAGS(EventFlag,
DCB_REMOTE_CHANGE_APPTLV(Subtype),
DCB_REMOTE_CHANGE_APPTLV(Subtype))) {
/* Get the Local and Peer APPTLV store */
app_it Local = apptlv_find(&apptlv, device_name, Subtype);
if (Local == NULL)
goto Error;
app_it Peer = apptlv_find(&peer_apptlv, device_name,
Subtype);
if (Peer == NULL)
goto Error;
if (Local->second->Length == Peer->second->Length) {
if (!memcmp(Local->second->AppData,
Peer->second->AppData,
Local->second->Length)) {
return true;
}
}
LLDPAD_DBG(" COMPAT APP - failed\n");
} else if (DCB_TEST_FLAGS(EventFlag, DCB_LOCAL_CHANGE_LLINK,
DCB_LOCAL_CHANGE_LLINK)||
DCB_TEST_FLAGS(EventFlag, DCB_REMOTE_CHANGE_LLINK,
DCB_REMOTE_CHANGE_LLINK)) {
LLDPAD_DBG(" COMPAT LLINK - failed\n");
return false;
}
return false;
Error:
LLDPAD_DBG(" LocalPeerCompatible: device not found\n");
return false;
}
/* returns: 0 on success
* 1 on failure
*/
int set_configuration(char *device_name, u32 EventFlag)
{
cmd_status sResult;
full_dcb_attrib_ptrs attr_ptr;
if (DCB_TEST_FLAGS(EventFlag, DCB_LOCAL_CHANGE_PG, DCB_LOCAL_CHANGE_PG)
|| DCB_TEST_FLAGS(EventFlag, DCB_REMOTE_CHANGE_PG,
DCB_REMOTE_CHANGE_PG)) {
/* Get Oper store */
pg_it Oper = pg_find(&oper_pg, device_name);
pg_it Local = pg_find(&pg, device_name);
if (Oper == NULL || Local == NULL)
return cmd_failed;
Oper->second->num_tcs = Local->second->num_tcs;
pgroup_attribs pg_data;
if (DCB_TEST_FLAGS(EventFlag, DCB_REMOTE_CHANGE_PG,
DCB_REMOTE_CHANGE_PG)) {
pfc_it op_pfc = pfc_find(&oper_pfc, device_name);
memset(&attr_ptr, 0, sizeof(attr_ptr));
attr_ptr.pg = (Oper->second);
attr_ptr.pfc = (op_pfc->second);
if ((sResult = dcb_check_config(&attr_ptr))
!= cmd_success) {
LLDPAD_DBG(" PG rule check returned error %d\n",
sResult); /* Localization OK */
return sResult;
}
}
memcpy(&(pg_data.rx), &(Oper->second->rx), sizeof(pg_data.rx));
memcpy(&(pg_data.tx), &(Oper->second->tx), sizeof(pg_data.tx));
return set_hw_pg(device_name, &pg_data,
Local->second->protocol.OperMode);
} else if (DCB_TEST_FLAGS(EventFlag, DCB_LOCAL_CHANGE_PFC,
DCB_LOCAL_CHANGE_PFC) ||
DCB_TEST_FLAGS(EventFlag, DCB_REMOTE_CHANGE_PFC,
DCB_REMOTE_CHANGE_PFC)) {
/* Get Oper store */
pfc_it Oper = pfc_find(&oper_pfc, device_name);
pfc_it Local = pfc_find(&pfc, device_name);
if (Oper == NULL || Local == NULL)
return cmd_failed;
return set_hw_pfc(device_name, Oper->second->admin,
Local->second->protocol.OperMode);
} else if (DCB_TEST_FLAGS(EventFlag, DCB_LOCAL_CHANGE_LLINK,
DCB_LOCAL_CHANGE_LLINK) ||
DCB_TEST_FLAGS(EventFlag, DCB_REMOTE_CHANGE_LLINK,
DCB_REMOTE_CHANGE_LLINK)) {
return cmd_success;
} else if (DCB_TEST_FLAGS(EventFlag,
DCB_LOCAL_CHANGE_APPTLV(APP_FCOE_STYPE),
DCB_LOCAL_CHANGE_APPTLV(APP_FCOE_STYPE)) ||
DCB_TEST_FLAGS(EventFlag,
DCB_REMOTE_CHANGE_APPTLV(APP_FCOE_STYPE),
DCB_REMOTE_CHANGE_APPTLV(APP_FCOE_STYPE))) {
appgroup_attribs app_data;
/* Get Oper store */
app_it Oper = apptlv_find(&oper_apptlv, device_name,
APP_FCOE_STYPE);
if (Oper == NULL)
return cmd_success;
app_data.dcb_app_idtype = DCB_APP_IDTYPE_ETHTYPE;
app_data.dcb_app_id = APP_FCOE_ETHTYPE;
app_data.dcb_app_priority = Oper->second->AppData[0];
return set_hw_app(device_name, &app_data);
} else if (DCB_TEST_FLAGS(EventFlag,
DCB_LOCAL_CHANGE_APPTLV(APP_FIP_STYPE),
DCB_LOCAL_CHANGE_APPTLV(APP_FIP_STYPE)) ||
DCB_TEST_FLAGS(EventFlag,
DCB_REMOTE_CHANGE_APPTLV(APP_FIP_STYPE),
DCB_REMOTE_CHANGE_APPTLV(APP_FIP_STYPE))) {
appgroup_attribs app_data;
/* Get Oper store */
app_it Oper = apptlv_find(&oper_apptlv, device_name,
APP_FIP_STYPE);
/* FIP subtype is only sent to kernel if Operational this
* way the FCoE stack and applications use the FCoE APP
* entry until FIP is operational.
*/
if (Oper == NULL ||
(Oper->second && Oper->second->protocol.OperMode == false))
return cmd_success;
app_data.dcb_app_idtype = DCB_APP_IDTYPE_ETHTYPE;
app_data.dcb_app_id = APP_FIP_ETHTYPE;
app_data.dcb_app_priority = Oper->second->AppData[0];
return set_hw_app(device_name, &app_data);
} else if (DCB_TEST_FLAGS(EventFlag, DCB_LOCAL_CHANGE_APPTLV(APP_ISCSI_STYPE),
DCB_LOCAL_CHANGE_APPTLV(APP_ISCSI_STYPE)) ||
DCB_TEST_FLAGS(EventFlag, DCB_REMOTE_CHANGE_APPTLV(APP_ISCSI_STYPE),
DCB_REMOTE_CHANGE_APPTLV(APP_ISCSI_STYPE))) {
appgroup_attribs app_data;
/* Get Oper store */
app_it Oper = apptlv_find(&oper_apptlv, device_name,
APP_ISCSI_STYPE);
app_it Local = apptlv_find(&apptlv, device_name,
APP_ISCSI_STYPE);
if (Oper == NULL || Local == NULL) {
return cmd_failed;
}
app_data.dcb_app_idtype = DCB_APP_IDTYPE_PORTNUM;
app_data.dcb_app_id = APP_ISCSI_PORT;
app_data.dcb_app_priority = Oper->second->AppData[0];
return set_hw_app(device_name, &app_data);
}
return cmd_success;
}
/******************************************************************************
**
** Method: handle_opermode_true
**
** Description: This routine is called by remove_adapter.
** For any feature whose OperMode is true, send an
** event since the port is going away - indicating an
** OperMode change.
**
** Arguments: char *device_name
**
** Returns: cmd_success if successful, failure code otherwise.
**
******************************************************************************/
static void handle_opermode_true(char *device_name)
{
pg_attribs pg_data;
pfc_attribs pfc_data;
app_attribs app_data;
llink_attribs llink_data;
int i = 0;
if (get_pg(device_name, &pg_data) == cmd_success)
if (pg_data.protocol.OperMode)
pg_event(device_name, EVENT_OPERMODE);
if (get_pfc(device_name, &pfc_data) == cmd_success)
if (pfc_data.protocol.OperMode)
pfc_event(device_name, EVENT_OPERMODE);
for (i = 0; i < DCB_MAX_APPTLV ; i++)
if (get_app(device_name, i, &app_data) == cmd_success)
if (app_data.protocol.OperMode)
app_event(device_name, i, EVENT_OPERMODE);
for (i = 0; i < DCB_MAX_LLKTLV ; i++)
if (get_llink(device_name, i, &llink_data) == cmd_success)
if (llink_data.protocol.OperMode)
llink_event(device_name, i, EVENT_OPERMODE);
}
/******************************************************************************
**
** Method: run_feature_protocol
**
** Description: This function runs feature state machine for a local or remote
** change.
** The function caller should acquire lock before calling this function.
** Caller must call this function per event.
**
** Arguments: char *device_name
** u32 EventFlag
** u32 SubType - This is valid only for DCB_LOCAL_CHANGE_APPTLV and
** DCB_REMOTE_CHANGE_APPTLV
**
** Returns: cmd_success if successful, failure code otherwise.
**
******************************************************************************/
cmd_status run_feature_protocol(char *device_name, u32 EventFlag, u32 Subtype)
{
feature_protocol_attribs *feat_prot = NULL;
feature_protocol_attribs *peer_feat_prot = NULL;
control_prot_it ctrl_prot = NULL;
control_prot_it peer_ctrl_prot = NULL;
bool ErrorChanged = false;
bool Err, local_change;
bool just_added = false;
pg_attribs old_pg_opcfg;
int old_pg_opmode = 0;
u32 pg_events = 0;
pfc_attribs old_pfc_opcfg;
int old_pfc_opmode = 0;
u32 pfc_events = 0;
app_attribs old_app_opcfg;
int old_app_opmode = 0;
u32 app_events = 0;
llink_attribs old_llink_opcfg;
int old_llink_opmode = 0;
u32 llink_events = 0;
int i, mask;
if (!dcbx_check_active(device_name))
return cmd_success;
memset(&old_pg_opcfg, 0, sizeof(pg_attribs));
memset(&old_pfc_opcfg, 0, sizeof(pfc_attribs));
memset(&old_app_opcfg, 0, sizeof(app_attribs));
memset(&old_llink_opcfg, 0, sizeof(llink_attribs));
/* Get the protocol store */
if (DCB_TEST_FLAGS(EventFlag, DCB_EVENT_FLAGS, DCB_LOCAL_CHANGE_PG) ||
DCB_TEST_FLAGS(EventFlag, DCB_EVENT_FLAGS,
DCB_REMOTE_CHANGE_PG)) {
/* Get the local feature protocol */
pg_it it = pg_find(&pg, device_name);
if (it != NULL) {
feat_prot = &it->second->protocol;
old_pg_opmode = feat_prot->OperMode;
} else {
goto ErrNoDevice;
}
/* Get the remote feature protocol */
pg_it it1 = pg_find(&peer_pg, device_name);
if (it1 != NULL) {
peer_feat_prot = &it1->second->protocol;
} else {
goto ErrNoDevice;
}
if ((peer_feat_prot->Error_Flag & DUP_DCBX_TLV_CTRL) ||
(peer_feat_prot->Error_Flag & DUP_DCBX_TLV_PG)) {
LLDPAD_DBG("** FLAG: MISSING PG TLV \n");
feat_prot->Error_Flag |= FEAT_ERR_MULTI_TLV;
} else {
feat_prot->Error_Flag &= ~FEAT_ERR_MULTI_TLV;
}
pg_it Oper = pg_find(&oper_pg, device_name);
if (Oper != NULL) {
memcpy(&(old_pg_opcfg.rx), &(Oper->second->rx),
sizeof(old_pg_opcfg.rx));
memcpy(&(old_pg_opcfg.tx), &(Oper->second->tx),
sizeof(old_pg_opcfg.tx));
} else {
goto ErrNoDevice;
}
}
if (DCB_TEST_FLAGS(EventFlag, DCB_EVENT_FLAGS, DCB_LOCAL_CHANGE_PFC) ||
DCB_TEST_FLAGS(EventFlag, DCB_EVENT_FLAGS,
DCB_REMOTE_CHANGE_PFC)) {
/* Get the local feature protocol */
pfc_it it = pfc_find(&pfc, device_name);
if (it != NULL) {
feat_prot = &it->second->protocol;
old_pfc_opmode = feat_prot->OperMode;
} else {
goto ErrNoDevice;
}
/* Get the remote feature protocol */
pfc_it it1 = pfc_find(&peer_pfc, device_name);
if (it1 != NULL) {
peer_feat_prot = &it1->second->protocol;
} else {
goto ErrNoDevice;
}
if ((peer_feat_prot->Error_Flag & DUP_DCBX_TLV_CTRL) ||
(peer_feat_prot->Error_Flag & DUP_DCBX_TLV_PFC)) {
LLDPAD_DBG("** FLAG: MISSING PFC TLV \n");
feat_prot->Error_Flag |= FEAT_ERR_MULTI_TLV;
} else {
feat_prot->Error_Flag &= ~FEAT_ERR_MULTI_TLV;
}
pfc_it Oper = pfc_find(&oper_pfc, device_name);
if (Oper != NULL) {
memcpy(&old_pfc_opcfg.admin, &Oper->second->admin,
sizeof(old_pfc_opcfg.admin));
} else {
goto ErrNoDevice;
}
}
if (DCB_TEST_FLAGS(EventFlag,
DCB_EVENT_FLAGS,
DCB_LOCAL_CHANGE_APPTLV(Subtype)) ||
DCB_TEST_FLAGS(EventFlag,
DCB_EVENT_FLAGS,
DCB_REMOTE_CHANGE_APPTLV(Subtype))) {
/* Get the local feature protocol */
app_it it = apptlv_find(&apptlv, device_name, Subtype);
if (it != NULL) {
feat_prot = &it->second->protocol;
old_app_opmode = feat_prot->OperMode;
} else {
goto ErrNoDevice;
}
/* Get the remote feature protocol */
app_it it1 = apptlv_find(&peer_apptlv, device_name, Subtype);
if (it1 != NULL) {
peer_feat_prot = &it1->second->protocol;
} else {
goto ErrNoDevice;
}
if ((peer_feat_prot->Error_Flag & DUP_DCBX_TLV_CTRL) ||
(peer_feat_prot->Error_Flag & DUP_DCBX_TLV_APP)) {
LLDPAD_DBG("** FLAG: MISSING APP TLV \n");
feat_prot->Error_Flag |= FEAT_ERR_MULTI_TLV;
} else {
feat_prot->Error_Flag &= ~FEAT_ERR_MULTI_TLV;
}
app_it Oper = apptlv_find(&oper_apptlv, device_name, Subtype);
if (Oper != NULL) {
old_app_opcfg.Length = Oper->second->Length;
memcpy(&old_app_opcfg.AppData[0],
&((*Oper).second->AppData[0]),
old_app_opcfg.Length);
} else {
goto ErrNoDevice;
}
}
if (DCB_TEST_FLAGS(EventFlag, DCB_EVENT_FLAGS, DCB_LOCAL_CHANGE_LLINK)
|| DCB_TEST_FLAGS(EventFlag, DCB_EVENT_FLAGS,
DCB_REMOTE_CHANGE_LLINK)) {
/* Get the local feature protocol */
llink_it it = llink_find(&llink, device_name, Subtype);
if (it != NULL) {
feat_prot = &it->second->protocol;
old_llink_opmode = feat_prot->OperMode;
} else {
goto ErrNoDevice;
}
/* Get the remote feature protocol */
llink_it it1 = llink_find(&peer_llink, device_name, Subtype);
if (it1 != NULL) {
peer_feat_prot = &it1->second->protocol;
} else {
goto ErrNoDevice;
}
if ((peer_feat_prot->Error_Flag & DUP_DCBX_TLV_CTRL) ||
(peer_feat_prot->Error_Flag & DUP_DCBX_TLV_LLINK)) {
LLDPAD_DBG("** FLAG: MISSING LLINK TLV \n");
feat_prot->Error_Flag |= FEAT_ERR_MULTI_TLV;
} else {
feat_prot->Error_Flag &= ~FEAT_ERR_MULTI_TLV;
}
llink_it Oper = llink_find(&oper_llink, device_name, Subtype);
if (Oper != NULL) {
memcpy(&old_llink_opcfg.llink, &Oper->second->llink,
sizeof(old_llink_opcfg.llink));
} else {
goto ErrNoDevice;
}
}
/* Get the local control protocol variables. */
ctrl_prot = ctrl_prot_find(&dcb_control_prot, device_name);
if (ctrl_prot == NULL)
goto ErrNoDevice;
/* Get the remote control protocol variables. */
peer_ctrl_prot = ctrl_prot_find(&dcb_peer_control_prot, device_name);
if (peer_ctrl_prot == NULL)
goto ErrNoDevice;
if ((feat_prot == NULL) || (peer_feat_prot == NULL))
goto ErrNoDevice;
if (peer_ctrl_prot->second->Error_Flag & TOO_MANY_NGHBRS) {
peer_feat_prot->TLVPresent = false;
LLDPAD_DBG("** Set Flag: TOO MANY NEIGHBORS \n");
feat_prot->Error_Flag |= FEAT_ERR_MULTI_PEER;
} else {
feat_prot->Error_Flag &= ~FEAT_ERR_MULTI_PEER;
}
if (feat_prot->State == DCB_INIT) {
feat_prot->Oper_version = feat_prot->Max_version;
feat_prot->OperMode = false;
feat_prot->Error = false;
/* Set the parameters. */
feat_prot->FeatureSeqNo =
ctrl_prot->second->SeqNo + 1;
/* If Syncd false, then control state machine will
* TX LLDP message with local config. */
feat_prot->Syncd = !(feat_prot->Advertise);
LLDPAD_DBG("Set Syncd to %u [%u]\n", feat_prot->Syncd, __LINE__);
feat_prot->State = DCB_LISTEN;
/* Ensure PFC settings are synced up on initialization */
if (DCB_TEST_FLAGS(EventFlag, DCB_EVENT_FLAGS,
DCB_LOCAL_CHANGE_PFC))
just_added = true;
}
if (feat_prot->State == DCB_LISTEN) {
LLDPAD_DBG("Feature state machine (flags %x)\n", EventFlag);
local_change = false;
mask = DCB_SET_ALL_FLAGS(LOCAL);
if (EventFlag & mask) {
local_change = true;
LLDPAD_DBG(" Local change*0x%x:", EventFlag);
LLDPAD_DBG(" %s", (EventFlag & DCB_LOCAL_CHANGE_PG) ?
"PG" : "");
LLDPAD_DBG(" %s", (EventFlag & DCB_LOCAL_CHANGE_PFC) ?
"PFC" : "");
for (i = 0; i < DCB_MAX_APPTLV; i++)
if (EventFlag & DCB_LOCAL_CHANGE_APPTLV(i))
LLDPAD_DBG(" APP%d", i);
LLDPAD_DBG(" %s", (EventFlag & DCB_LOCAL_CHANGE_LLINK) ?
"LLINK" : "");
LLDPAD_DBG("\n");
}
/* If local changed and we are already synched... */
if (local_change && feat_prot->Syncd) {
LLDPAD_DBG(" Local feature already synced\n");
/* If we are not synched, we won't be able
* to accept new local changes until we get
* back remote changes for previous local
* change. */
/* Set the parameters. */
feat_prot->FeatureSeqNo =
ctrl_prot->second->SeqNo + 1;
/* If Syncd false, then control state machine
* will TX LLDP message with local config. */
if ((feat_prot->Advertise == true) ||
(feat_prot->Advertise_prev == true)) {
feat_prot->Syncd = false;
LLDPAD_DBG(" Set Syncd to %u [%u]\n",
feat_prot->Syncd, __LINE__);
} else {
feat_prot->Syncd = true;
LLDPAD_DBG(" Set Syncd to %u [%u]\n",
feat_prot->Syncd, __LINE__);
feat_prot->tlv_sent = true;
}
}
/* F4 If don't advertise, then copy the local config to
* Oper config. */
if (!feat_prot->Advertise) {
LLDPAD_DBG(" F5 - Advertise mode OFF:");
LLDPAD_DBG(" %s", (EventFlag&(DCB_LOCAL_CHANGE_PG |
DCB_REMOTE_CHANGE_PG)) ? "PG" : "");
LLDPAD_DBG(" %s", (EventFlag&(DCB_LOCAL_CHANGE_PFC |
DCB_REMOTE_CHANGE_PFC)) ? "PFC" : "");
if (EventFlag & DCB_LOCAL_CHANGE_APPTLV(Subtype))
LLDPAD_DBG(" APP%d", Subtype);
LLDPAD_DBG(" %s", (EventFlag&(DCB_LOCAL_CHANGE_LLINK |
DCB_REMOTE_CHANGE_LLINK)) ? "LLINK" : "");
LLDPAD_DBG("\n");
/* copy the local config to Oper config. */
CopyConfigToOper(device_name, LOCAL_STORE,
EventFlag, Subtype);
/* State already in Listen so don't have to
* change. */
feat_prot->Error = false;
// maintain TOO_MANY_NGHBRS & FEAT_ERR_MULTI_TLV errors
Err = feat_prot->Error_Flag;
feat_prot->Error_Flag = FEAT_ERR_NONE;
if (Err & FEAT_ERR_MULTI_PEER) {
feat_prot->Error_Flag |= FEAT_ERR_MULTI_PEER;
}
if (Err & FEAT_ERR_MULTI_TLV) {
feat_prot->Error_Flag |= (Err & FEAT_ERR_MULTI_TLV);
}
feat_prot->OperMode = feat_prot->Enable;
set_configuration(device_name, EventFlag);
goto OperChange;
}
/* On first call from add_port() ensure that the HW
* configuration is synced with the DCBX operational state.
*/
if (just_added) {
CopyConfigToOper(device_name, LOCAL_STORE,
EventFlag, Subtype);
set_configuration(device_name, EventFlag);
}
/* Process remote change. */
mask = DCB_SET_ALL_FLAGS(REMOTE);
if (EventFlag & mask) {
LLDPAD_DBG(" Remote change: ");
LLDPAD_DBG(" %s", (EventFlag & DCB_REMOTE_CHANGE_PG) ?
"PG" : "");
LLDPAD_DBG(" %s", (EventFlag & DCB_REMOTE_CHANGE_PFC) ?
"PFC" : "");
if (EventFlag & DCB_REMOTE_CHANGE_APPTLV(Subtype))
LLDPAD_DBG(" App%d", Subtype);
LLDPAD_DBG(" %s", (EventFlag & DCB_REMOTE_CHANGE_LLINK) ?
"LLINK" : "");
LLDPAD_DBG("\n");
/* This version check is part of the Control
* protocol state machine that must be
* complete before proceeding with feature
* protocol state machine */
if (!((ctrl_prot->second->Oper_version ==
MIN(peer_ctrl_prot->second->Max_version,
ctrl_prot->second->Max_version)) &&
(ctrl_prot->second->Oper_version ==
peer_ctrl_prot->second->Oper_version)
)) {
goto ErrBadVersion;
}
if (feat_prot->dcbx_st == DCBX_SUBTYPE2) {
/* Handle Peer expiration */
if (peer_ctrl_prot->second->RxDCBTLVState ==
DCB_PEER_EXPIRED) {
LLDPAD_DBG(" F6.2 - Peer DCBX TLV Expired\n");
CopyConfigToOper(device_name,
LOCAL_STORE,EventFlag,Subtype);
feat_prot->OperMode = false;
feat_prot->Syncd = false;
feat_prot->Error = true;
feat_prot->FeatureSeqNo = 1;
feat_prot->Error_Flag |= FEAT_ERR_NO_TLV;
set_configuration(device_name,
EventFlag);
goto OperChange;
}
}
/* Handle feature TLV not present */
if (!peer_feat_prot->TLVPresent) {
LLDPAD_DBG(" F8 - Feature not present\n");
/* copy the local config to Oper config. */
CopyConfigToOper(device_name, LOCAL_STORE,
EventFlag, Subtype);
feat_prot->OperMode = false;
feat_prot->Syncd = true;
LLDPAD_DBG(" Set Syncd to %u [%u]\n",
feat_prot->Syncd, __LINE__);
feat_prot->Oper_version =
feat_prot->Max_version;
if (feat_prot->dcbx_st == DCBX_SUBTYPE2) {
feat_prot->Error = true;
} else {
feat_prot->Error = false;
}
feat_prot->Error_Flag |= FEAT_ERR_NO_TLV;
set_configuration(device_name, EventFlag);
goto OperChange;
} else {
feat_prot->Error_Flag &= ~FEAT_ERR_NO_TLV;
}
if (!feat_prot->Syncd &&
(peer_ctrl_prot->second->AckNo
!= feat_prot->FeatureSeqNo)) {
/* Wait for the Peer to synch up. */
LLDPAD_DBG(" Wait for Peer to synch: "
"Peer AckNo %d, FeatureSeqNo %d \n",
peer_ctrl_prot->second->AckNo,
feat_prot->FeatureSeqNo);
goto OperChange;
}
if (feat_prot->Error_Flag & FEAT_ERR_MULTI_TLV) {
LLDPAD_DBG(" F9.1 - Rcvd Multiple DCBX TLVs\n");
/* Copy Local config to Oper config. */
CopyConfigToOper(device_name, LOCAL_STORE,
EventFlag, Subtype);
feat_prot->OperMode = false;
Err = feat_prot->Error;
feat_prot->Error = true;
feat_prot->force_send = true;
/* Set_configuration to driver. */
if (set_configuration(device_name, EventFlag))
feat_prot->Error_Flag |= FEAT_ERR_CFG;
if (Err != feat_prot->Error) {
ErrorChanged = true;
}
goto ErrProt;
}
/* Check for the Oper version */
if (feat_prot->Oper_version !=
MIN(peer_feat_prot->Max_version,
feat_prot->Max_version)) {
/* Update Oper version and signal LLDP send. */
feat_prot->Oper_version =
MIN(peer_feat_prot->Max_version,
feat_prot->Max_version);
LLDPAD_DBG(" Update feature oper version to %d "
"and signal send\n",
feat_prot->Oper_version);
feat_prot->Syncd = false;
LLDPAD_DBG(" Set Syncd to %u [%u]\n",
feat_prot->Syncd, __LINE__);
feat_prot->FeatureSeqNo =
ctrl_prot->second->SeqNo + 1;
goto OperChange;
}
feat_prot->Syncd = true;
LLDPAD_DBG(" Set Syncd to %u [%u]\n",
feat_prot->Syncd, __LINE__);
/* F13/F14 */
if (feat_prot->Oper_version !=
peer_feat_prot->Oper_version ) {
/* Wait for Peer to synch up with * version */
LLDPAD_DBG(" Wait for the Peer to synch up ");
LLDPAD_DBG("with feature version.\n");
goto OperChange;
}
feat_prot->PeerWilling = peer_feat_prot->Willing;
/* F15 If feature is disabled on any side,
* then make Opermode false. */
if (!feat_prot->Enable || !peer_feat_prot->Enable) {
LLDPAD_DBG(" F16 - Feature is disabled\n");
/* Copy Local config to Oper config. */
CopyConfigToOper(device_name, LOCAL_STORE,
EventFlag, Subtype);
feat_prot->OperMode = false;
feat_prot->Error_Flag = FEAT_ERR_NONE;
Err = feat_prot->Error;
/* Set_configuration to driver. */
if (feat_prot->dcbx_st == DCBX_SUBTYPE2) {
feat_prot->Syncd = !(feat_prot->Error);
feat_prot->Error = false;
if (set_configuration(device_name,
EventFlag))
feat_prot->Error_Flag
|= FEAT_ERR_CFG;
} else {
feat_prot->Error = (set_configuration(
device_name, EventFlag) !=
cmd_success);
if (feat_prot->Error)
feat_prot->Error_Flag |=
FEAT_ERR_CFG;
}
if (Err != feat_prot->Error) {
ErrorChanged = true;
}
goto ErrProt;
}
/* F17 */
if (feat_prot->Willing && !feat_prot->PeerWilling) {
LLDPAD_DBG(" F18 - local willing, "
"peer NOT willing\n");
feat_prot->Error_Flag = FEAT_ERR_NONE;
Err = feat_prot->Error;
if (feat_prot->dcbx_st == DCBX_SUBTYPE2) {
feat_prot->OperMode =
!(peer_feat_prot->Error);
if (feat_prot->OperMode) {
/* Copy Peer cfg to Oper cfg */
CopyConfigToOper(device_name,
PEER_STORE, EventFlag,
Subtype);
} else {
/* Copy local cfg to Oper cfg*/
CopyConfigToOper(device_name,
LOCAL_STORE, EventFlag,
Subtype);
}
feat_prot->Syncd = !(feat_prot->Error);
feat_prot->Error = false;
/* Set_configuration to driver. */
if (set_configuration(device_name,
EventFlag))
feat_prot->Error_Flag |=
FEAT_ERR_CFG;
} else {
feat_prot->OperMode = true;
/* Copy Peer config to Oper config. */
CopyConfigToOper(device_name,
PEER_STORE, EventFlag,Subtype);
/* Set_configuration to driver. */
feat_prot->Error = (set_configuration(
device_name, EventFlag) !=
cmd_success);
if (feat_prot->Error)
feat_prot->Error_Flag |=
FEAT_ERR_CFG;
}
if (Err != feat_prot->Error) {
ErrorChanged = true;
}
goto ErrProt;
}
/* F19 */
if (!feat_prot->Willing && feat_prot->PeerWilling) {
LLDPAD_DBG(" F20 - local NOT willing, "
"peer willing\n");
/* Copy Local config to Oper config. */
CopyConfigToOper(device_name,
LOCAL_STORE, EventFlag, Subtype);
feat_prot->Error_Flag = FEAT_ERR_NONE;
Err = feat_prot->Error;
/* Set_configuration to driver. */
if (feat_prot->dcbx_st == DCBX_SUBTYPE2) {
feat_prot->OperMode =
!peer_feat_prot->Error;
feat_prot->Syncd = !(feat_prot->Error);
feat_prot->Error = false;
if (set_configuration(device_name,
EventFlag))
feat_prot->Error_Flag |=
FEAT_ERR_CFG;
} else {
feat_prot->OperMode = true;
feat_prot->Error = (set_configuration(
device_name, EventFlag) !=
cmd_success);
if (feat_prot->Error)
feat_prot->Error_Flag |=
FEAT_ERR_CFG;
}
if (Err != feat_prot->Error)
ErrorChanged = true;
goto ErrProt;
}
/* F21 */
if ((feat_prot->Willing == feat_prot->PeerWilling) &&
(LocalPeerCompatible(device_name,
EventFlag, Subtype))) {
LLDPAD_DBG(" F22 - local willing == peer willing\n");
/* Copy Local config to Oper config. */
CopyConfigToOper(device_name,
LOCAL_STORE, EventFlag, Subtype);
feat_prot->Error_Flag = FEAT_ERR_NONE;
Err = feat_prot->Error;
/* Set_configuration to driver. */
if (feat_prot->dcbx_st == DCBX_SUBTYPE2) {
feat_prot->OperMode =
!peer_feat_prot->Error;
feat_prot->Syncd = !(feat_prot->Error);
feat_prot->Error = false;
if (set_configuration(device_name,
EventFlag))
feat_prot->Error_Flag |=
FEAT_ERR_CFG;
} else {
feat_prot->OperMode = true;
feat_prot->Error = (set_configuration(
device_name, EventFlag) !=
cmd_success);
if (feat_prot->Error)
feat_prot->Error_Flag |=
FEAT_ERR_CFG;
}
if (Err != feat_prot->Error)
ErrorChanged = true;
} else {
LLDPAD_DBG(" F23 - Local & Peer config not"
" compatible\n");
/* Copy Local config to Oper config. */
CopyConfigToOper(device_name,
LOCAL_STORE, EventFlag, Subtype);
feat_prot->OperMode = false;
Err = feat_prot->Error;
/* Set default configuration */
if (feat_prot->dcbx_st == DCBX_SUBTYPE2) {
feat_prot->Syncd = feat_prot->Error;
feat_prot->Error = true;
if (set_configuration(device_name,
EventFlag))
feat_prot->Error_Flag |=
FEAT_ERR_CFG;
} else {
feat_prot->Error = true;
if (set_configuration(device_name,
EventFlag) != cmd_success)
feat_prot->Error_Flag |=
FEAT_ERR_CFG;
}
feat_prot->Error_Flag |= FEAT_ERR_MISMATCH;
if (Err != feat_prot->Error)
ErrorChanged = true;
}
ErrProt:
if (peer_feat_prot->Error)
feat_prot->Error_Flag |= FEAT_ERR_PEER;
if (feat_prot->dcbx_st == DCBX_SUBTYPE1) {
if (feat_prot->Error || peer_feat_prot->Error){
LLDPAD_DBG(" ## FEATURE ERROR: "
"%d, %d (Error_Flag 0x%x"
" EventFlag 0x%x)\n",
feat_prot->Error,
peer_feat_prot->Error,
feat_prot->Error_Flag,
EventFlag);
if (feat_prot->OperMode) {
feat_prot->OperMode = false;
/* Set default configuration */
set_configuration(device_name,
EventFlag);
}
}
}
if (ErrorChanged) {
LLDPAD_DBG(" ErrorChanged \n");
if (feat_prot->dcbx_st == DCBX_SUBTYPE1) {
feat_prot->Syncd = false;
LLDPAD_DBG(" Set Syncd to %u [%u]\n",
feat_prot->Syncd, __LINE__);
}
feat_prot->FeatureSeqNo =
ctrl_prot->second->SeqNo+ 1;
}
}
OperChange:
if (DCB_TEST_FLAGS(EventFlag, DCB_EVENT_FLAGS,
DCB_LOCAL_CHANGE_PG) ||
DCB_TEST_FLAGS(EventFlag, DCB_EVENT_FLAGS,
DCB_REMOTE_CHANGE_PG)) {
pg_it Oper = pg_find(&oper_pg, device_name);
if (Oper == NULL)
goto ErrNoDevice;
if (memcmp(&(old_pg_opcfg.tx), &(Oper->second->tx),
sizeof(old_pg_opcfg.tx)) != 0)
pg_events = pg_events | EVENT_OPERATTR;
if (feat_prot->OperMode != old_pg_opmode) {
pg_events = pg_events | EVENT_OPERMODE;
if (feat_prot->OperMode) {
LLDPAD_INFO("%s PG oper mode true\n",
device_name);
} else {
LLDPAD_INFO("%s PG oper mode false\n",
device_name);
}
}
}
if (DCB_TEST_FLAGS(EventFlag, DCB_EVENT_FLAGS,
DCB_LOCAL_CHANGE_PFC)||
DCB_TEST_FLAGS(EventFlag, DCB_EVENT_FLAGS,
DCB_REMOTE_CHANGE_PFC)) {
pfc_it Oper = pfc_find(&oper_pfc, device_name);
if (Oper == NULL)
goto ErrNoDevice;
if (memcmp(&(old_pfc_opcfg.admin),
&(Oper->second->admin),
sizeof(old_pfc_opcfg.admin)) != 0)
pfc_events = pfc_events | EVENT_OPERATTR;
if (feat_prot->OperMode != old_pfc_opmode) {
pfc_events = pfc_events | EVENT_OPERMODE;
if (feat_prot->OperMode) {
LLDPAD_INFO("%s PFC oper mode true\n",
device_name);
} else {
LLDPAD_INFO("%s PFC oper mode false\n",
device_name);
}
}
}
if (DCB_TEST_FLAGS(EventFlag, DCB_EVENT_FLAGS,
DCB_LOCAL_CHANGE_APPTLV(Subtype)) ||
DCB_TEST_FLAGS(EventFlag, DCB_EVENT_FLAGS,
DCB_REMOTE_CHANGE_APPTLV(Subtype))) {
app_it Oper = apptlv_find(&oper_apptlv, device_name,
Subtype);
if (Oper == NULL)
goto ErrNoDevice;
if ((old_app_opcfg.Length != Oper->second->Length)
|| (old_app_opcfg.Length &&
(memcmp(old_app_opcfg.AppData,
Oper->second->AppData,
old_app_opcfg.Length) != 0))) {
app_events = app_events | EVENT_OPERATTR;
}
if (feat_prot->OperMode != old_app_opmode) {
app_events = app_events | EVENT_OPERMODE;
if (feat_prot->OperMode) {
LLDPAD_INFO("%s APP oper mode true\n",
device_name);
} else {
LLDPAD_INFO("%s APP oper mode false\n",
device_name);
}
}
}
if (DCB_TEST_FLAGS(EventFlag, DCB_EVENT_FLAGS,
DCB_LOCAL_CHANGE_LLINK)||
DCB_TEST_FLAGS(EventFlag, DCB_EVENT_FLAGS,
DCB_REMOTE_CHANGE_LLINK)) {
llink_it Oper = llink_find(&oper_llink, device_name,
Subtype);
if (Oper == NULL)
goto ErrNoDevice;
if (memcmp(&(old_llink_opcfg.llink),
&(Oper->second->llink),
sizeof(old_llink_opcfg.llink)) != 0) {
llink_events = llink_events | EVENT_OPERATTR;
LLDPAD_DBG("llink opcfg changed \n");
}
if (feat_prot->OperMode != old_llink_opmode) {
llink_events = llink_events | EVENT_OPERMODE;
if (feat_prot->OperMode) {
LLDPAD_DBG("llink opmode = true\n");
} else {
LLDPAD_DBG("llink opmode = false\n");
}
}
}
}
if (pg_events)
pg_event(device_name, pg_events);
if (pfc_events)
pfc_event(device_name, pfc_events);
if (app_events)
app_event(device_name, Subtype, app_events);
if (llink_events)
llink_event(device_name, Subtype, llink_events);
return cmd_success;
ErrNoDevice:
return cmd_device_not_found;
ErrBadVersion:
LLDPAD_DBG(" Versions not compatible\n");
return cmd_ctrl_vers_not_compatible;
}
cmd_status GetDCBTLVState(char *device_name, u8 *State)
{
/* Get the remote control protocol variables. */
control_prot_it peer_ctrl_prot = ctrl_prot_find(&dcb_peer_control_prot,
device_name);
if (peer_ctrl_prot == NULL)
return cmd_device_not_found;
*State = (u8)peer_ctrl_prot->second->RxDCBTLVState;
return cmd_success;
}
bool FeaturesSynched(char *device_name)
{
int i = 0;
pg_it it = pg_find(&pg, device_name);
if (it == NULL)
return false;
if (it->second->protocol.State == DCB_LISTEN) {
if ((it->second->protocol.Syncd == false) ||
(it->second->protocol.tlv_sent == false))
return false;
}
/* Get the local PFC feature protocol */
pfc_it it1 = pfc_find(&pfc, device_name);
if (it1 == NULL)
return false;
if (it1->second->protocol.State == DCB_LISTEN) {
if (it1->second->protocol.Syncd == false ||
it1->second->protocol.tlv_sent == false)
return false;
}
/* Get the APP TLV feature protocol. */
for (i = 0; i < DCB_MAX_APPTLV ; i++) {
app_it it2 = apptlv_find(&apptlv, device_name, i);
if (it2 == NULL)
return false;
if (it2->second->protocol.State == DCB_LISTEN) {
if (it2->second->protocol.Syncd == false ||
it2->second->protocol.tlv_sent ==false)
return false;
}
}
for (i = 0; i < DCB_MAX_LLKTLV ; i++) {
/* Get the local LLINK feature protocol */
llink_it it4 = llink_find(&llink, device_name, i);
if (it4 == NULL)
return false;
if (it4->second->protocol.State == DCB_LISTEN) {
if (it4->second->protocol.Syncd == false ||
it4->second->protocol.tlv_sent == false)
return false;
}
}
return true;
}
/* Set the Syncd value to true for features which are not advertising.
*/
void update_feature_syncd(char *device_name)
{
int i = 0;
/* Get the local PG feature protocol */
pg_it it = pg_find(&pg, device_name);
if (it != NULL) {
if (it->second->protocol.Advertise == false)
it->second->protocol.Syncd = true;
if (it->second->protocol.force_send == true)
it->second->protocol.Syncd = true;
}
/* Get the local PFC feature protocol */
pfc_it it1 = pfc_find(&pfc, device_name);
if (it1 != NULL) {
if (it1->second->protocol.Advertise == false)
it1->second->protocol.Syncd = true;
if (it1->second->protocol.force_send == true)
it1->second->protocol.Syncd = true;
}
/* Get the APP TLV feature protocol. */
for (i = 0; i < DCB_MAX_APPTLV ; i++) {
app_it it2 = apptlv_find(&apptlv, device_name, i);
if (it2 != NULL) {
if (it2->second->protocol.Advertise == false)
it2->second->protocol.Syncd = true;
if (it2->second->protocol.force_send == true)
it2->second->protocol.Syncd = true;
}
}
for (i = 0; i < DCB_MAX_LLKTLV ; i++) {
/* Get the local LLINK feature protocol */
llink_it it4 = llink_find(&llink, device_name, i);
if (it4 != NULL) {
if (it4->second->protocol.Advertise == false)
it4->second->protocol.Syncd = true;
if (it4->second->protocol.force_send == true)
it4->second->protocol.Syncd = true;
}
}
}
/******************************************************************************
**
** Method: run_control_protocol
**
** Description: This function runs control state machine for a local or
** remote change.
** The function caller should acquire lock before calling this function.
** Caller must call this function for local or remote change but not both.
**
** Arguments: char *device_name
** u32 EventFlag
** Returns: cmd_success if successful, failure code otherwise.
**
*******************************************************************************/
cmd_status run_control_protocol(char *device_name, u32 EventFlag)
{
pg_attribs pg_dstore;
int i, mask;
if (!dcbx_check_active(device_name))
return cmd_success;
/* Get the local control protocol variables. */
control_prot_it ctrl_prot = ctrl_prot_find(&dcb_control_prot,
device_name);
if (ctrl_prot == NULL)
return cmd_device_not_found;
/* Get the remote control protocol variables. */
control_prot_it peer_ctrl_prot = ctrl_prot_find(&dcb_peer_control_prot,
device_name);
if (peer_ctrl_prot == NULL)
return cmd_device_not_found;
if (ctrl_prot->second->State == DCB_INIT) {
/* Set the parameters. */
ctrl_prot->second->Oper_version =
ctrl_prot->second->Max_version;
ctrl_prot->second->State = DCB_LISTEN;
}
if (ctrl_prot->second->State == DCB_LISTEN) {
LLDPAD_DBG("DCB Ctrl in LISTEN \n");
/* Process local change if any. */
mask = DCB_SET_ALL_FLAGS(LOCAL);
if (EventFlag & mask) {
LLDPAD_DBG(" Local change detected: ");
LLDPAD_DBG(" %s", (EventFlag & DCB_LOCAL_CHANGE_PG) ?
"PG" : "");
LLDPAD_DBG(" %s", (EventFlag & DCB_LOCAL_CHANGE_PFC) ?
"PFC" : "");
for (i = 0; i < DCB_MAX_APPTLV; i++)
if (EventFlag & DCB_LOCAL_CHANGE_APPTLV(i))
LLDPAD_DBG(" APP%d", i);
LLDPAD_DBG(" %s", (EventFlag & DCB_LOCAL_CHANGE_LLINK) ?
"LLINK" : "");
LLDPAD_DBG("\n");
if (ctrl_prot->second->SeqNo ==
ctrl_prot->second->MyAckNo) {
LLDPAD_DBG(" Local SeqNo == Local AckNo\n");
if (!FeaturesSynched(device_name)) {
update_feature_syncd(device_name);
ctrl_prot->second->SeqNo++;
LLDPAD_DBG(" *** Sending packet -- ");
LLDPAD_DBG("SeqNo = %d \t AckNo = %d \n",
ctrl_prot->second->SeqNo,
ctrl_prot->second->AckNo);
/* Send new DCB ctrl & feature TLVs */
somethingChangedLocal(device_name, NEAREST_BRIDGE);
}
}
return cmd_success;
}
/* Process remote change if any. */
mask = DCB_SET_ALL_FLAGS(REMOTE);
if (EventFlag & mask) {
bool SendDCBTLV = false;
LLDPAD_DBG(" Remote change detected(0x%x): ", EventFlag);
LLDPAD_DBG(" %s", (EventFlag & DCB_REMOTE_CHANGE_PG) ?
"PG" : "");
LLDPAD_DBG(" %s", (EventFlag & DCB_REMOTE_CHANGE_PFC) ?
"PFC" : "");
for (i = 0; i < DCB_MAX_APPTLV; i++)
if (EventFlag & DCB_REMOTE_CHANGE_APPTLV(i))
LLDPAD_DBG(" APP%d", i);
LLDPAD_DBG(" %s", (EventFlag & DCB_REMOTE_CHANGE_LLINK) ?
"LLINK" : "");
LLDPAD_DBG("\n");
u8 State;
if (GetDCBTLVState(device_name, &State) ==
cmd_success) {
if (State == DCB_PEER_EXPIRED) {
ctrl_prot->second->SeqNo = 0;
ctrl_prot->second->AckNo = 0;
ctrl_prot->second->MyAckNo = 0;
ctrl_prot->second->Oper_version =
ctrl_prot->second->Max_version;
peer_ctrl_prot->second->RxDCBTLVState =
DCB_PEER_RESET;
LLDPAD_DBG(" Ctrl_prot Peer expired\n");
if (get_pg(device_name, &pg_dstore) !=
cmd_success) {
LLDPAD_DBG("unable to get local pg"
" cfg from data store\n");
return cmd_device_not_found;
}
if (pg_dstore.protocol.dcbx_st ==
DCBX_SUBTYPE2) {
return cmd_success;
} else {
/* Send the updated DCB TLV */
SendDCBTLV = true;
goto send;
}
}
}
if (peer_ctrl_prot->second->Error_Flag &
DUP_DCBX_TLV_CTRL) {
LLDPAD_DBG("** HANDLE: DUP CTRL TLVs \n");
goto send;
}
if (ctrl_prot->second->Oper_version !=
MIN(peer_ctrl_prot->second->Max_version,
ctrl_prot->second->Max_version)) {
ctrl_prot->second->Oper_version =
MIN(peer_ctrl_prot->second->Max_version,
ctrl_prot->second->Max_version);
/* Send the updated DCB TLV */
SendDCBTLV = true;
LLDPAD_DBG(" Change Oper Version \n");
goto send;
}
if (ctrl_prot->second->Oper_version !=
peer_ctrl_prot->second->Oper_version) {
/* Wait for peer to synch up. */
LLDPAD_DBG(" Wait for Peer to synch \n");
goto send;
}
/* Update MyAck */
ctrl_prot->second->MyAckNo =
peer_ctrl_prot->second->AckNo;
/* If received new Peer TLV, then acknowledge the
* Peer TLV
* MyAckNo == 0 means peer has started over, so
* also acknowledge in this case.
*/
if ((ctrl_prot->second->AckNo !=
peer_ctrl_prot->second->SeqNo) ||
(ctrl_prot->second->MyAckNo == 0)) {
if (!(peer_ctrl_prot->second->Error_Flag
& TOO_MANY_NGHBRS)) {
ctrl_prot->second->AckNo =
peer_ctrl_prot->second->SeqNo;
SendDCBTLV = true;
}
}
/* If changes in feature then send message with latest
* DCB and FeatureTLV */
send:
LLDPAD_DBG(" Current -- SeqNo = %d \t MyAckNo = %d \n",
ctrl_prot->second->SeqNo,
ctrl_prot->second->MyAckNo);
if ((ctrl_prot->second->SeqNo ==
ctrl_prot->second->MyAckNo) &&
(!FeaturesSynched(device_name))) {
LLDPAD_DBG(" Features not synced \n");
update_feature_syncd(device_name);
/* Send LLDP message. */
ctrl_prot->second->SeqNo++;
LLDPAD_DBG(" *** Sending Packet -- ");
LLDPAD_DBG("SeqNo = %d \t AckNo = %d \n",
ctrl_prot->second->SeqNo,
ctrl_prot->second->AckNo);
/* Send new DCB control & feature TLVs*/
somethingChangedLocal(device_name, NEAREST_BRIDGE);
return cmd_success;
}
if (SendDCBTLV) {
LLDPAD_DBG(" SendDCBTLV is set \n");
/* if you didn't send LLDP message above then
* send one without changing feature TLVs. */
LLDPAD_DBG(" *** Sending Packet -- ");
LLDPAD_DBG("SeqNo = %d \t AckNo = %d \n",
ctrl_prot->second->SeqNo,
ctrl_prot->second->AckNo);
/* Send new DCB TLVs with old feature TLVs. */
somethingChangedLocal(device_name, NEAREST_BRIDGE);
}
}
}
return cmd_success;
}
/******************************************************************************
**
** Method: run_dcb_protocol
**
** Description: This function runs both feature and control state machines
** for the features that are specified in the event flag. The function
** caller should acquire lock per port before calling this function.
** Caller can only club together local PG*PFC*APPTLV or
** remote PG*PFC*APPTLV eventflags and call this function.
**
** Arguments: char *device_name
** u32 EventFlag
** u32 SubType - This is valid for APPTLV event flags only.
** If >= DCB_MAX_APPTLV, then we process all Subtypes
** for APPTLV flags.
** Returns: cmd_success if successful, failure code otherwise.
**
*******************************************************************************/
cmd_status run_dcb_protocol(char *device_name, u32 EventFlag, u32 Subtype)
{
cmd_status result = cmd_success;
bool LocalChange = false;
u32 i, SubTypeMin, SubTypeMax;
struct dcbx_tlvs *tlvs;
int mask;
LLDPAD_DBG("running DCB protocol for %s, flags:%04x\n", device_name,
EventFlag);
if (!dcbx_check_active(device_name))
return result;
/* if valid use SubType param, otherwise process all SubTypes */
if (Subtype < DCB_MAX_APPTLV) {
SubTypeMin = Subtype;
SubTypeMax = Subtype+1;
} else {
SubTypeMin = 0;
SubTypeMax = DCB_MAX_APPTLV;
}
/* Run the feature state machines:
*
* Order is important PFC must be run before PG features to
* allow up2tc remappings to account for PFC attributes.
*/
if (DCB_TEST_FLAGS(EventFlag, DCB_LOCAL_CHANGE_PFC,
DCB_LOCAL_CHANGE_PFC)
&& (result != cmd_ctrl_vers_not_compatible)) {
result = run_feature_protocol(device_name,
DCB_LOCAL_CHANGE_PFC, SUBTYPE_DEFAULT);
LocalChange = true;
}
if (DCB_TEST_FLAGS(EventFlag, DCB_LOCAL_CHANGE_PG, DCB_LOCAL_CHANGE_PG)
&& (result != cmd_ctrl_vers_not_compatible)) {
result = run_feature_protocol(device_name, DCB_LOCAL_CHANGE_PG,
SUBTYPE_DEFAULT);
LocalChange = true;
}
mask = 0;
for (i = 0; i < DCB_MAX_APPTLV; i++)
mask |= DCB_LOCAL_CHANGE_APPTLV(i);
if ((EventFlag & mask) && (result != cmd_ctrl_vers_not_compatible)) {
for (i = SubTypeMin; i < SubTypeMax; i++) {
result = run_feature_protocol(device_name,
DCB_LOCAL_CHANGE_APPTLV(i), i);
}
LocalChange = true;
}
if (DCB_TEST_FLAGS(EventFlag, DCB_LOCAL_CHANGE_LLINK,
DCB_LOCAL_CHANGE_LLINK)
&& (result != cmd_ctrl_vers_not_compatible)) {
result = run_feature_protocol(device_name,
DCB_LOCAL_CHANGE_LLINK, i);
LocalChange = true;
}
/* Only allow local or remote change at a time:
*
* Order is important PFC must be run before PG features to
* allow up2tc remappings to account for PFC attributes.
*/
if (!LocalChange) {
if (DCB_TEST_FLAGS(EventFlag, DCB_REMOTE_CHANGE_PFC,
DCB_REMOTE_CHANGE_PFC)
&& (result != cmd_ctrl_vers_not_compatible)) {
result = run_feature_protocol(device_name,
DCB_REMOTE_CHANGE_PFC, SUBTYPE_DEFAULT);
}
if (DCB_TEST_FLAGS(EventFlag, DCB_REMOTE_CHANGE_PG,
DCB_REMOTE_CHANGE_PG)
&& (result != cmd_ctrl_vers_not_compatible)) {
result = run_feature_protocol(device_name,
DCB_REMOTE_CHANGE_PG, SUBTYPE_DEFAULT);
}
mask = 0;
for (i = 0; i < DCB_MAX_APPTLV; i++)
mask |= DCB_REMOTE_CHANGE_APPTLV(i);
if ((EventFlag & mask) &&
(result != cmd_ctrl_vers_not_compatible)) {
for (i = SubTypeMin; i < SubTypeMax; i++) {
result = run_feature_protocol(device_name,
DCB_REMOTE_CHANGE_APPTLV(i), i);
}
}
if (DCB_TEST_FLAGS(EventFlag, DCB_REMOTE_CHANGE_LLINK,
DCB_REMOTE_CHANGE_LLINK)
&& (result != cmd_ctrl_vers_not_compatible)) {
result = run_feature_protocol(device_name,
DCB_REMOTE_CHANGE_LLINK, SUBTYPE_DEFAULT);
}
}
/* apply all feature setting to the driver: linux only */
tlvs = dcbx_data(device_name);
if (tlvs && tlvs->operup) {
LLDPAD_DBG("%s: %s: Managed DCB device coming online, program HW\n",
__func__, device_name);
set_hw_all(device_name);
}
/* Run the control state machine. */
result = run_control_protocol(device_name, EventFlag);
return result;
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C
1
https://gitee.com/sdlhk/lldpad.git
git@gitee.com:sdlhk/lldpad.git
sdlhk
lldpad
lldpad
master

搜索帮助