📄 ip.h
字号:
/*
* FILENAME: ip.h
*
* Copyright 2000 By InterNiche Technologies Inc. All rights reserved
*
* IP protocol definitions
*
* MODULE: INET
*
*
* PORTABLE: yes
*/
/* Additional Copyrights: */
/* Portions Copyright 1990, 1993 by NetPort Software.
* Portions Copyright 1986 by Carnegie Mellon
* Portions Copyright 1983 by the Massachusetts Institute of
* Technology
*/
#ifndef _IPHFILE_H_
#define _IPHFILE_H_ 1
/* Internet status. Keeps track of packets gone through and errors.
* 10/16/90 - scrapped old structure in favor of MIB for SNMP support.
* -JB-
*/
struct IpMib {
u_long ipForwarding; /* 1= we are a gateway; 2 = host */
u_long ipDefaultTTL; /* IP time to live */
u_long ipInReceives; /* total received datagrams (bad too) */
u_long ipInHdrErrors; /* Header Err (xsum, ver, ttl, etc) */
u_long ipInAddrErrors; /* nonsense IP addresses */
u_long ipForwDatagrams; /* routed packets */
u_long ipUnknownProtos; /* unknown protocol types */
u_long ipInDiscards; /* dropped (ie no buffer space) */
u_long ipInDelivers; /* delivered receive packets */
u_long ipOutRequests; /* sends (not includeing routed) */
u_long ipOutDiscards; /* sends dropped (no buffer) */
u_long ipOutNoRoutes; /* dropped, can't route */
u_long ipReasmTimeout; /* fragment reassembly timeouts */
u_long ipReasmReqds; /* frags received */
u_long ipReasmOKs; /* packets successfully reassembled */
u_long ipReasmFails; /* packets reassemblys failed */
u_long ipFragOKs; /* packets we fragmented for send */
u_long ipFragFails; /* packets we wanted to frag and couldnt */
u_long ipFragCreates; /* fragments we made */
u_long ipRoutingDiscards;
};
typedef struct IpMib * IPMIB;
extern struct IpMib ip_mib;
#ifdef BTREE_ROUTES
/* enum values to support the route table btree software */
enum AVLSKEW { NONE, LEFT, RIGHT };
enum AVLRES { BT_ERROR = 0, BT_OK, BT_BALANCE };
typedef unsigned long AVLDATUM;
#endif /* BTREE_ROUTES */
/* This ip route structure was generated by the NetPort MIB compiler
* from rfc1213. It replaces the old RtMib structure, which was built
* by hand
*/
/* More fields added to the table for RIP. This mechanism of adding
* more fields to the same table saves lot of complexity of code.
* That is there is only one Routing Table used by IP and RIP. Common
* calls to add_route(), del_route, etc. Fields of RTMIB used by RIP
* are as follows ipRouteDest; Destination ipRouteIfIndex; Interface
* ( 1 based value) of this route ipRouteMetric1; Time To Live for
* this route ipRouteNextHop; Gateway thru which we can reach
* ipRouteDest ipRouteMask; Subnet Mask New fields for RIP are
* ipRouteFlags; Flag is set to have triggered updates
* ipRouteProxyRoute As needed by RIP2 ipRouteMainTimer To check for
* Time To Live for this route ipRouteSecondaryTimer Extra time for
* the entry to live !! ipRouteRouteTag As needed by RIP2
* ipRouteDistMetric Distance metric of RIP2 We could have used
* ipRouteMetric2, etc. but having a specific field makes code more
* readable
*/
struct RtMib
{
u_long ipRouteDest;
long ipRouteIfIndex; /* do not use as nets[] index! */
long ipRouteMetric1;
long ipRouteMetric2;
long ipRouteMetric3;
long ipRouteMetric4;
u_long ipRouteNextHop;
long ipRouteType;
long ipRouteProto;
u_long ipRouteAge;
u_long ipRouteMask;
long ipRouteMetric5;
void * ipRouteInfo; /* 32 bit ptr */
/* end of rfc1213 (MIB-2) fields */
#ifdef RIP_SUPPORT
u_long ipRouteMainTimer ;
/* We keep the route entry for about 120s after the timeout has occured.
* This is done so that info about this broken route can be passed to
* other gateways
*/
u_long ipRouteSecondaryTimer ;
u_long ipRouteProxyRoute;/* For Proxy RIP-2, 0 if none */
/* Precisely the NextHop field of RIP2 pkt */
u_short ipRouteRouteTag; /* Route tag to send */
u_long ipRouteDistMetric;
#endif
/* flags for this route table entry (see below) */
int ipRouteFlags ;
/* pointer to net for route. This is informationally redundant of
* the field ipRouteIfIndex above, however it's more pratical now
* that we support dynamic interfaces which do not appear in the
* static nets[] array.
*/
struct net * ifp;
#ifdef BTREE_ROUTES
/* these strutures are kept in a binary tree. */
struct RtMib * left; /* btree brach to higher side of tree */
struct RtMib * right; /* btree brach to lower side of tree */
enum AVLSKEW skew; /* which branch is longer */
#endif /* BTREE_ROUTES */
};
/* IP routing logic needs to ignore certain RIP_PRIVATE entries in
* the route table, thus some RIP ipRouteFlags defines are set here.
* These are also defined in RIP module with ifndefs for RIPp prots
* to non-InterNiche IP stacks.
*/
#define RIP_PRIVATE 0x01 /* Private route entry */
#define RIP_TRIGGER 0x02 /* Do triggered update for entry */
#define RIP_VALID 0x04 /* valid RIP entry */
typedef struct RtMib * RTMIB;
extern RTMIB rt_mib;
extern unsigned ipRoutes; /* number of entrys alloced */
#ifdef BTREE_ROUTES
/* AVL tree code entry points in rtbtree.c */
enum AVLRES avlinsert(struct RtMib ** parent, struct RtMib * new);
enum AVLRES avlremove(struct RtMib **n, ip_addr key);
struct RtMib * avlaccess(struct RtMib * n, ip_addr key);
void avldepthfirst(struct RtMib * n,
void(*func)(struct RtMib * n, long param, int depth),
long param, int depth);
#endif /* BTREE_ROUTES */
extern RTMIB cachedRoute; /* last route entry used */
extern queue bigfreeq; /* big free buffers */
extern queue lilfreeq; /* small free buffers */
/* values for ipRouteProto; */
#define IPRP_OTHER 1 /* none of the following */
#define IPRP_LOCAL 2 /* non-prot source, e.g., manually configured */
#define IPRP_NETMGMT 3 /* set via SNMP, CMIP, etc */
#define IPRP_ICMP 4 /* set via ICMP */
#define IPRP_EGP 5
#define IPRP_GGP 6
#define IPRP_HELLO 7
#define IPRP_RIP 8 /* set via RIP */
/* there's about 10 more we dont support */
/* values for ipRouteType; */
#define IPRT_OTHER 1 /* none of the following */
#define IPRT_INVALID 2 /* invalidated */
#define IPRT_DIRECT 3 /* directly connected net */
#define IPRT_INDIRECT 4 /* non-local host/net/subnet */
struct ip {
u_char ip_ver_ihl; /* 4 bit version, 4 bit hdr len in 32bit words */
u_char ip_tos; /* Type of Service */
unshort ip_len; /* Total packet length including header */
unshort ip_id; /* ID for fragmentation */
unshort ip_flgs_foff; /* mask in flags as needed */
u_char ip_time; /* Time to live (secs) */
u_char ip_prot; /* protocol */
unshort ip_chksum; /* Header checksum */
ip_addr ip_src; /* Source name */
ip_addr ip_dest; /* Destination name */
};
/* Some useful definitions */
#define IPHSIZ sizeof(struct ip) /* internet header size */
#define IP_VER 4 /* internet version */
#define IP_TSRV 0 /* default type of service */
#define IP_ID 0 /* kernel fills in IN id */
#define IP_FLGS 0 /* no fragmentation yet */
/* fragmentation flag bits, for masking into 16bit flags/offset word */
#define IP_FLG_DF 0x4000 /* Don't Fragment (DF) bit */
#define IP_FLG_MF 0x2000 /* More Fragments (MF) bit */
#define IP_FLG_MASK 0xe000 /* for masking out all flags from word */
#define IP_FOFF 0 /* " " " */
#ifndef IP_TTL /* maximum time to live */
#define IP_TTL 30 /* overridable from ipport.h_h */
#endif
#define IPXSUM 0 /* initial checksum */
/* ethernet-ish packet types in NET endian: */
#define IP_TYPE htons(0x0800)
#define ARP_TYPE htons(0x0806)
/* Some macros for finding IP offsets in incoming packets */
#define ip_head(ppkt) (struct ip *)(ppkt->nb_prot)
#define ip_hlen(pip) (((pip)->ip_ver_ihl & 0x0f) << 2)
#define ip_data(pip) ((char *)(pip) + ip_hlen(pip))
#define ip_optlen(pip) (ip_hlen(pip) - 20)
/* prototype IP routines */
int ip_write(u_char prot, PACKET);
int ip_rcv(PACKET); /* low level process of incomming IP */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -