📄 ospfh.h
字号:
/* The Ospfh data structure*/
#include <stdio.h>
#include <stdlib.h>
#include <winsock2.h>
#include <ws2tcpip.h>
#include <string.h>
#include <direct.h>
// #include "tools.h"
#include "mysql.h"
typedef unsigned int u_int32_t;
typedef unsigned short u_int16_t;
typedef unsigned char u_int8_t;
/* Macro Definination in ospfd.h*/
#define IPVERSION 4
#define OSPF_VERSION 2
/* Default protocol, port number. */
#ifndef IPPROTO_OSPFIGP
#define IPPROTO_OSPFIGP 89
#endif /* IPPROTO_OSPFIGP */
/* IP TTL for OSPF protocol. */
#define OSPF_IP_TTL 1
#define WEIGHT_VALUE_INFINIT 100
/* Default configuration file name for ospfd. */
#define OSPF_DEFAULT_CONFIG "ospfd.conf"
/* Architectual Constants */
#ifdef DEBUG
#define OSPF_LS_REFRESH_TIME 60
#else
#define OSPF_LS_REFRESH_TIME 1800
#endif
#define OSPF_MIN_LS_INTERVAL 5
#define OSPF_MIN_LS_ARRIVAL 1
#define OSPF_LSA_MAXAGE 3600
#define OSPF_CHECK_AGE 300
#define OSPF_LSA_MAXAGE_DIFF 900
#define OSPF_LS_INFINITY 0xffffff
#define OSPF_DEFAULT_DESTINATION 0x00000000 /* 0.0.0.0 */
#define OSPF_INITIAL_SEQUENCE_NUMBER 0x80000001
#define OSPF_MAX_SEQUENCE_NUMBER 0x7fffffff
#define OSPF_MAX_LSA_SIZE 1500
#define OSPF_LSA_MAXAGE_CHECK_INTERVAL 30
#ifdef HAVE_NSSA
#define OSPF_LOOPer 0x7f000000 /* 127.0.0.0 */
#endif /* HAVE_NSSA */
#define OSPF_AREA_BACKBONE 0x00000000 /* 0.0.0.0 */
#define DEFALT_IP_ADDRESS "0.0.0.0"
#define DEFALT_ANCESTOR_ADDRESS "255.255.255.255"
#define BROADCAST_ADDRESS "192.168.0.255"
#define LSA_HEADER_SIZE 20
//#define LSA_LP_SIZE 93
/* OSPF SPF timer values. */
#define OSPF_SPF_DELAY_DEFAULT 5
#define OSPF_SPF_HOLDTIME_DEFAULT 10
/* Timer value. */
#define OSPF_ROUTER_ID_UPDATE_DELAY 1
#define OSPF_LS_REFRESH_SHIFT (60 * 15)
#define OSPF_LS_REFRESH_JITTER 60
#define OSPF_IF_MTU 1500
#define MAX_PACKET 1000
#define OSPF_RETRANSMIT_INTERVAL_DEFAULT 5
#define OSPF_TRANSMIT_DELAY_DEFAULT 1
#define OSPF_AUTH_SIMPLE_SIZE 4
//DD.h
#define OSPF_PACKET_MAX 1500
#define OSPF_SEND_PACKET_DIRECT 1
#define OSPF_SEND_PACKET_INDIRECT 2
/* Flag manipulation macros. */
#define CHECK_FLAG(V,F) ((V) & (F))
#define SET_FLAG(V,F) (V) = (V) | (F)
#define UNSET_FLAG(V,F) (V) = (V) & ~(F)
#define OSPF_TOP_TIMER_ON(T,F,V) \
do { \
if (!(T)) \
(T) = thread_add_timer (master, (F), top, (V)); \
} while (0)
#define OSPF_TIMER_OFF(X) \
do { \
if (X) \
{ \
thread_cancel (X); \
(X) = NULL; \
} \
} while (0)
#define OSPF_NSM_TIMER_ON(T,F,V) \
do { \
if (!(T)) \
(T) = thread_add_timer (master, (F), nbr, (V)); \
} while (0)
//此处增加了两种消息类型
/*OSPF MSG Type definition*/
#define OSPF_MSG_HELLO 1 /* OSPF Hello Message. */
#define OSPF_MSG_DB_DESC 2 /* OSPF Database Descriptoin Message. */
#define OSPF_MSG_LS_REQ 3 /* OSPF Link State Request Message. */
#define OSPF_MSG_LS_UPD 4 /* OSPF Link State Update Message. */
#define OSPF_MSG_LS_ACK 5 /* OSPF Link State Acknoledgement Message. */
#define OSPF_MSG_LS_FEED_UP 253 /* OSPF Link State Update Message. */
#define OSPF_MSG_LS_FEED_DOWN 254 /* OSPF Link State Update Message. */
/*OSPF LSA Range definition*/
#define OSPF_MIN_LSA 1
#define OSPF_MAX_LSA 12
#define OSPF_MAX_LAYERNUM 4
/* OSPF Database Description flags. */
#define OSPF_MAX_PACKET_SIZE 65535 /* includes IP Header size. */
#define OSPF_LS_REQ_MIN_SIZE 0
#define OSPF_LS_UPD_MIN_SIZE 4
#define OSPF_LS_ACK_MIN_SIZE 0
#define OSPF_LSA_KEY_SIZE 12 /*type(4) + id(4) + ar(4)*/
#define OSPF_LS_FEED_DOWN_SIZE 4
#define OSPF_LS_FEED_DOWN_LSDB_ID_SIZE 1
#define OSPF_LS_FEED_DOWN_ENTRY_ID_SIZE 1
#define OSPF_LSA_HEADER_SIZE 20
#define OSPF_HEADER_SIZE 24
/* OSPF LSA Link Type. */
#define LSA_LINK_TYPE_POINTOPOINT 1
#define DEFALT_RC_ID 0x00000000
#define OSPF_SEND_PACKET_DIRECT 1
#define OSPF_SEND_PACKET_INDIRECT 2
/* Max bit/byte length of IPv4 address. */
#define IPV4_MAX_BYTELEN 4
#define IPV4_MAX_BITLEN 32
#define IPV4_MAX_PREFIXLEN 32
#define IPV4_ADDR_CMP(D,S) memcmp ((D), (S), IPV4_MAX_BYTELEN)
#define IPV4_ADDR_SAME(D,S) (memcmp ((D), (S), IPV4_MAX_BYTELEN) == 0)
#define IPV4_ADDR_COPY(D,S) memcpy ((D), (S), IPV4_MAX_BYTELEN)
#define STREAM_PNT(S) ((S)->data + (S)->getp)
#define CHECK_SIZE(S, Z) \
if (((S)->putp + (Z)) > (S)->size) \
(Z) = (S)->size - (S)->putp
#define PSIZE(a) (((a) + 7) / (8))
#define IS_LSA_MAXAGE(L) (LS_AGE ((L)) == OSPF_LSA_MAXAGE)
#define STREAM_DATA(S) ((S)->data)
struct ip
{
unsigned char h_verlen; //4位首部长度,4位IP版本号
unsigned char tos; //8位服务类型TOS
unsigned short total_len; //16位总长度(字节)
unsigned short ident; //16位标识
unsigned short frag_and_flags; //3位标志位
unsigned char ttl; //8位生存时间 TTL
unsigned char proto; //8位协议 (TCP, UDP 或其他)
unsigned short checksum; //16位IP首部校验和
struct in_addr sourceIP; //32位源IP地址
struct in_addr destIP; //32位目的IP地址
};
struct iovec
{
void *iov_base; /* 缓冲区开始的地址 */
size_t iov_len; /* 缓冲区的长度 */
};
/* OSPF LSA header. */
struct lsa_header
{
u_int16_t ls_age;
u_char options;
u_char type;
u_int32_t id;
struct in_addr adv_router;
u_int32_t ls_seqnum;
u_int16_t checksum;
u_int16_t length;
};
/* OSPF LSA. */
struct ospf_lsa
{
/* LSA origination flag. */
u_char flags;
#define OSPF_LSA_SELF 0x01
#define OSPF_LSA_SELF_CHECKED 0x02
#define OSPF_LSA_RECEIVED 0x04
#define OSPF_LSA_APPROVED 0x08
#define OSPF_LSA_DISCARD 0x10
#ifdef HAVE_NSSA
#define OSPF_LSA_LOCAL_XLT 0x20
#endif /* HAVE_NSSA */
unsigned char id;
/* LSA data. */
struct lsa_header *data;
/* Received time stamp. */
struct timeval tv_recv;
/* Last time it was originated */
struct timeval tv_orig;
/* All of reference count, also lock to remove. */
int lock;
/* References to this LSA in neighbor retransmission lists*/
int retransmit_counter;
struct mpls_te_link *lp;
/* Parent LSDB. */
struct list *lsa_list;
};
#define OSPFH_WRITE_ON() \
do \
{ \
if (ospf_top->t_write == NULL) \
ospf_top->t_write = \
thread_add_write (master, ospfh_write_and_send, ospf_top, ospf_top->fd); \
} while (0)
//一系列TIMER_ON已去掉,是否需要,
/*packet struct*/
struct stream
{
struct stream *next;
unsigned char *data;
/* Put pointer. */
unsigned long putp;
/* Get pointer. */
unsigned long getp;
/* End of pointer. */
unsigned long endp;
/* Data size. */
unsigned long size;
};
struct stream_fifo
{
unsigned long count;
struct stream *head;
struct stream *tail;
};
struct ospf_packet
{
struct ospf_packet *next;
/* Pointer to data stream. */
struct stream *s;
/* IP destination address. */
// struct in_addr dst;
/* OSPF packet length. */
u_int16_t length;
};
/* OSPF packet queue structure. */
struct ospf_fifo
{
unsigned long count;
struct ospf_packet *head;
struct ospf_packet *tail;
};
/* OSPF packet header structure. */
struct ospf_header
{
u_char version; /* OSPF Version. */
u_char type; /* Packet Type. */
u_int16_t length; /* Packet Length. */
struct in_addr router_id; /* Router ID. */
struct in_addr area_id; /* Area ID. */
u_int16_t checksum; /* Check Sum. */
u_int16_t auth_type; /* Authentication Type. */
/* Authentication Data. */
union
{
/* Simple Authentication. */
u_char auth_data [OSPF_AUTH_SIMPLE_SIZE];
/* Cryptographic Authentication. */
struct
{
u_int16_t zero; /* Should be 0. */
u_char key_id; /* Key ID. */
u_char auth_data_len; /* Auth Data Length. */
u_int32_t crypt_seqnum; /* Cryptographic Sequence Number. */
} crypt;
} u;
};
//linklist
struct listnode
{
struct listnode *next;
struct listnode *prev;
void *data;
};
struct list
{
struct listnode *head;
struct listnode *tail;
unsigned int count;
int (*cmp) (void *val1, void *val2);
void (*del) (void *val);
};
#define nextnode(X) ((X) = (X)->next)
#define listhead(X) ((X)->head)
#define listcount(X) ((X)->count)
#define list_isempty(X) ((X)->head == NULL && (X)->tail == NULL)
#define getdata(X) ((X)->data)
/* List iteration macro. */
#define LIST_LOOP(L,V,N) \
for ((N) = (L)->head; (N); (N) = (N)->next) \
if (((V) = (N)->data) != NULL)
/* List node add macro. */
#define LISTNODE_ADD(L,N) \
do { \
(N)->prev = (L)->tail; \
if ((L)->head == NULL) \
(L)->head = (N); \
else \
(L)->tail->next = (N); \
(L)->tail = (N); \
} while (0)
/* List node delete macro. */
#define LISTNODE_DELETE(L,N) \
do { \
if ((N)->prev) \
(N)->prev->next = (N)->next; \
else \
(L)->head = (N)->next; \
if ((N)->next) \
(N)->next->prev = (N)->prev; \
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -