📄 kofn.c
字号:
/* * Copyright (C) 2001, University of California, Santa Barbara * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * Other copyrights might apply to parts of this software and are so * noted when applicable. *//* * Parts of this program has been derived from PIM sparse-mode pimd. * The pimd program is covered by the license in the accompanying file * named "LICENSE.pimd". * * The pimd program is COPYRIGHT 1998 by University of Southern California. * */#include <netinet/in.h>#include <sys/types.h>#include <stdlib.h>#include "aodvConst.h"#include "callout.h"#include "const.h"#include "debug.h"#include "inet.h"int kofn_flag = FALSE;struct KOFNEntry { u_int32_t neigh; int count; struct KOFNEntry *next;};static struct KOFNEntry *firstKOFNEntry = NULL;static struct KOFNEntry *find(u_int32_t dest){ struct KOFNEntry *entry = NULL; trace(TRACE_KOFN,"kofn:find(%s)",inet_fmt_h(dest,s1)); for(entry = firstKOFNEntry ; entry != NULL ; entry = entry->next){ if (entry->neigh == dest) { trace(TRACE_KOFN,"kofn:find:returning entry"); return entry; } } trace(TRACE_KOFN,"kofn:returning NULL"); return NULL;}static void removeEntry(struct KOFNEntry *entry){ struct KOFNEntry *toMe = NULL; trace(TRACE_KOFN,"KOFN:removeEntry"); //go through list and find who is pointing to entry if(firstKOFNEntry != NULL && entry != NULL){ trace(TRACE_KOFN,"KOFN:removeEntry(%s)" ,inet_fmt_h(entry->neigh,s1)); if(entry==firstKOFNEntry){ trace(TRACE_KOFN,"KOFN:removeEntry==firstEntry"); firstKOFNEntry=firstKOFNEntry->next; //free KOFNEntry free(entry); entry = NULL; return; }else{ for(toMe = firstKOFNEntry ; toMe != NULL ; toMe = entry->next) { if (toMe->next == entry) { trace(TRACE_KOFN,"KOFN:entry!=firstEntry"); toMe->next=entry->next; //free KOFNEntry free(entry); entry = NULL; return; } } trace(TRACE_KOFN,"KOFN: remove(entry not found)"); } }}static void dec(u_int32_t dest){ struct KOFNEntry *entry = NULL; trace(TRACE_KOFN, "dec(dest=%s" ,inet_fmt_h(dest,s1)); entry=find(dest); if(entry != NULL){ entry->count--; if(entry->count <= 0){ removeEntry(entry); } }}static void insert(struct KOFNEntry *entry){ struct KOFNEntry *first = NULL; first=firstKOFNEntry; firstKOFNEntry=entry; firstKOFNEntry->next=first;}int addkofn(u_int32_t neigh){ struct KOFNEntry *entry = NULL; trace(TRACE_KOFN, "addkofn(neigh=%s" ,inet_fmt_h(neigh,s1)); entry = find(neigh); if(entry == NULL){ //create entry entry = (struct KOFNEntry *)malloc(sizeof(struct KOFNEntry)); if(entry == NULL){ log(LOG_ERR,TRUE,"unable to allocate memory, KOFNEntry"); } entry->count = 1; entry->neigh = neigh; insert(entry); }else{ entry->count++; } //set timer to decrement count trace(TRACE_KOFN|TRACE_TIMER ,"kofn:timer:%u" ,ALLOWED_HELLO_LOSS * HELLO_INTERVAL); timer_setTimer(ALLOWED_HELLO_LOSS * HELLO_INTERVAL ,(cfunc_t)dec ,(void *)neigh); return entry->count;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -