XINU
Functions | Variables
net.c File Reference
#include <xinu.h>
#include <stdio.h>
Include dependency graph for net.c:

Go to the source code of this file.

Functions

void eth_hton (struct netpacket *pktptr)
 
void eth_ntoh (struct netpacket *pktptr)
 
uint16 getport ()
 
void net_init (void)
 
process netin ()
 

Variables

bpid32 netbufpool
 
struct network NetData
 
uint32 netportseed
 

Function Documentation

◆ eth_hton()

void eth_hton ( struct netpacket pktptr)

Definition at line 127 of file net.c.

References htons, and netpacket::net_ethtype.

Referenced by arp_in(), arp_resolve(), and ip_out().

130 {
131  pktptr->net_ethtype = htons(pktptr->net_ethtype);
132 }
uint16 net_ethtype
Definition: net.h:19
#define htons(x)
Definition: prototypes.h:619
Here is the caller graph for this function:

◆ eth_ntoh()

void eth_ntoh ( struct netpacket pktptr)

Definition at line 139 of file net.c.

References netpacket::net_ethtype, and ntohs.

Referenced by netin().

142 {
143  pktptr->net_ethtype = ntohs(pktptr->net_ethtype);
144 }
uint16 net_ethtype
Definition: net.h:19
#define ntohs(x)
Definition: prototypes.h:622
Here is the caller graph for this function:

◆ getport()

uint16 getport ( void  )

Definition at line 150 of file net.c.

References netportseed.

Referenced by tftpget_mb().

151 {
152  netportseed = 1103515245 * netportseed + 12345;
153  return 50000 + ((uint16)((netportseed >> 16)) % 15535);
154 }
unsigned short uint16
符号なし16ビット整数(unsigned short)
Definition: kernel.h:17
uint32 netportseed
Definition: net.c:8
Here is the caller graph for this function:

◆ net_init()

void net_init ( void  )

Definition at line 15 of file net.c.

References arp_init(), control(), create(), ETH_ADDR_LEN, ETH_CTRL_GET_MAC, ETHER0, getticks(), icmp_init(), ICMP_QSIZ, ICMP_SLOTS, ipoqueue, ipout(), iqentry::iqhead, iqentry::iqsem, iqentry::iqtail, memset(), mkbufpool(), netbufpool, NetData, netin(), netportseed, NETPRIO, NETSTK, NULL, NULLCH, PACKLEN, panic(), resume(), semcreate(), SYSERR, udp_init(), UDP_QSIZ, and UDP_SLOTS.

Referenced by nulluser().

16 {
17  int32 nbufs; /* Total no of buffers */
18 
19  /* Initialize the network data structure */
20 
21  memset((char *)&NetData, NULLCH, sizeof(struct network));
22 
23  /* Obtain the Ethernet MAC address */
24 
25  control(ETHER0, ETH_CTRL_GET_MAC, (int32)NetData.ethucast, 0);
26 
27  memset((char *)NetData.ethbcast, 0xFF, ETH_ADDR_LEN);
28 
29  /* Initialize the random port seed */
30 
32 
33  /* Create the network buffer pool */
34 
35  nbufs = UDP_SLOTS * UDP_QSIZ + ICMP_SLOTS * ICMP_QSIZ + 1;
36 
37  netbufpool = mkbufpool(PACKLEN, nbufs);
38 
39  /* Initialize the ARP cache */
40 
41  arp_init();
42 
43  /* Initialize UDP */
44 
45  udp_init();
46 
47  /* Initialize ICMP */
48 
49  icmp_init();
50 
51  /* Initialize the IP output queue */
52 
53  ipoqueue.iqhead = 0;
54  ipoqueue.iqtail = 0;
56  if((int32)ipoqueue.iqsem == SYSERR) {
57  panic("Cannot create ip output queue semaphore");
58  return;
59  }
60 
61  /* Create the IP output process */
62 
63  resume(create(ipout, NETSTK, NETPRIO, "ipout", 0, NULL));
64 
65  /* Create a network input process */
66 
67  resume(create(netin, NETSTK, NETPRIO, "netin", 0, NULL));
68 }
#define NULL
連結リスト用のNULLポインタ
Definition: kernel.h:68
sid32 semcreate(int32)
未使用セマフォを割り当て、そのセマフォへのインデックス(セマフォID)を返す。
Definition: semcreate.c:22
sid32 iqsem
パケット(pkts)をカウントするセマフォ
Definition: ip.h:37
#define NETSTK
Definition: net.h:3
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
process netin()
Definition: net.c:76
#define ICMP_SLOTS
Definition: icmp.h:3
#define UDP_SLOTS
Definition: udp.h:3
void icmp_init(void)
Definition: icmp.c:12
bpid32 mkbufpool(int32, int32)
バッファプール用のメモリを割り当て、バッファ同士をリンクする。
Definition: mkbufpool.c:38
syscall control(did32, int32, int32, int32)
Definition: control.c:9
int32 iqhead
次に送信するパケットのインデックス
Definition: ip.h:33
void udp_init(void)
Definition: udp.c:12
Definition: net.h:54
#define ETH_CTRL_GET_MAC
Definition: ether.h:45
#define ICMP_QSIZ
Definition: icmp.h:4
uint32 getticks(void)
CPUリセット以降のclock tick数を取得する。
Definition: getticks.c:14
struct iqentry ipoqueue
ネットワーク送信キュー
Definition: ip.c:6
#define UDP_QSIZ
Definition: udp.h:4
#define PACKLEN
Definition: net.h:50
struct network NetData
Definition: net.c:6
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
void * memset(void *, const int, int32)
指定のByteブロックに対して、同じ値をNバイト分書き込む。
Definition: memset.c:13
pri16 resume(pid32)
プロセスを休止状態(サスペンド)からREADY状態に遷移させる。
Definition: resume.c:20
#define NETPRIO
Definition: net.h:4
pid32 create(void *, uint32, pri16, char *, uint32,...)
関数の実行を開始するプロセスを作成する。
Definition: create.c:55
void panic(char *)
Panic状態に陥った旨のメッセージを表示し、全てのプロセスを停止させる。
Definition: panic.c:12
uint32 netportseed
Definition: net.c:8
#define ETH_ADDR_LEN
Definition: ether.h:10
int32 iqtail
次の空きスロットのインデックス。
Definition: ip.h:35
void arp_init(void)
Definition: arp.c:11
#define ETHER0
Definition: conf.h:34
#define NULLCH
NULL文字(NULL終端)
Definition: kernel.h:70
bpid32 netbufpool
Definition: net.c:7
process ipout(void)
Definition: ip.c:356
Here is the call graph for this function:
Here is the caller graph for this function:

◆ netin()

process netin ( void  )

Definition at line 76 of file net.c.

References arp_in(), ETH_ARP, ETH_IP, ETH_IPv6, eth_ntoh(), ETHER0, freebuf(), getbuf(), ip_in(), netbufpool, PACKLEN, panic(), read(), and SYSERR.

Referenced by net_init().

77 {
78  struct netpacket *pkt; /* Ptr to current packet */
79  int32 retval; /* Return value from read */
80 
81  /* Do forever: read a packet from the network and process */
82 
83  while(1) {
84 
85  /* Allocate a buffer */
86 
87  pkt = (struct netpacket *)getbuf(netbufpool);
88 
89  /* Obtain next packet that arrives */
90 
91  retval = read(ETHER0, (char *)pkt, PACKLEN);
92  if(retval == SYSERR) {
93  panic("Cannot read from Ethernet\n");
94  }
95 
96  /* Convert Ethernet Type to host order */
97 
98  eth_ntoh(pkt);
99 
100  /* Demultiplex on Ethernet type */
101 
102  switch (pkt->net_ethtype) {
103 
104  case ETH_ARP: /* Handle ARP */
105  arp_in((struct arppacket *)pkt);
106  continue;
107 
108  case ETH_IP: /* Handle IP */
109  ip_in(pkt);
110  continue;
111 
112  case ETH_IPv6: /* Handle IPv6 */
113  freebuf((char *)pkt);
114  continue;
115 
116  default: /* Ignore all other incoming packets */
117  freebuf((char *)pkt);
118  continue;
119  }
120  }
121 }
void arp_in(struct arppacket *)
Definition: arp.c:158
void ip_in(struct netpacket *)
Definition: ip.c:13
uint16 net_ethtype
Definition: net.h:19
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
syscall read(did32, char *, uint32)
Definition: read.c:9
#define ETH_IPv6
Definition: net.h:11
void eth_ntoh(struct netpacket *pktptr)
Definition: net.c:139
#define PACKLEN
Definition: net.h:50
IP&Ethernet用のARPパケットフォーマット
Definition: arp.h:39
#define ETH_ARP
Definition: net.h:9
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
char * getbuf(bpid32)
事前に確保されたバッファプールからバッファを取得する。
Definition: getbuf.c:19
Definition: net.h:16
void panic(char *)
Panic状態に陥った旨のメッセージを表示し、全てのプロセスを停止させる。
Definition: panic.c:12
#define ETH_IP
Definition: net.h:10
syscall freebuf(char *)
バッファプールから取得したバッファを解放する。
Definition: freebuf.c:19
#define ETHER0
Definition: conf.h:34
bpid32 netbufpool
Definition: net.c:7
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ netbufpool

bpid32 netbufpool

Definition at line 7 of file net.c.

Referenced by icmp_mkpkt(), net_init(), netin(), udp_send(), and udp_sendto().

◆ NetData

struct network NetData

◆ netportseed

uint32 netportseed

Definition at line 8 of file net.c.

Referenced by getport(), and net_init().