Moves resource requests to procdata (XCC)
[akaros.git] / kern / include / net.h
1 /* Copyright (c) 2010 The Regents of the University of California
2  * Barret Rhoden <brho@cs.berkeley.edu>
3  * See LICENSE for details.
4  *
5  * Arch independent networking infrastructure */
6
7 #ifndef ROS_KERN_NET_H
8 #define ROS_KERN_NET_H
9
10 #include <bits/netinet.h>
11 #include <stdio.h>
12
13 /* A few other useful standard defines.  Note the IP header can change size. */
14 #define ETH_HDR_SZ 14
15 #define UDP_HDR_SZ 8
16 #define IP_ETH_TYPE 0x0800
17
18 /* ROS defaults: */
19 #define DEFAULT_TTL 64
20
21 /* Don't forget the bytes are in network order */
22 struct ethernet_hdr {
23         uint8_t                                         dst_mac[6];
24         uint8_t                                         src_mac[6];
25         uint16_t                                        eth_type;
26         /* might be an optional 802.1q tag here */
27 };
28
29 /* For the bit-enumerated fields, note that you need to read "backwards" through
30  * the byte (first bits in memory are the "LSB" of the byte).  Can't seem to be
31  * able to do it with flags/fragments (3/13 bits each...). */
32 struct ip_hdr {
33         unsigned                                        hdr_len : 4;
34         unsigned                                        version : 4;
35         uint8_t                                         tos;
36         uint16_t                                        packet_len;
37         uint16_t                                        id;
38         uint16_t                                        flags_frags;
39         uint8_t                                         ttl;
40         uint8_t                                         protocol;
41         uint16_t                                        checksum;
42         uint32_t                                        src_addr;
43         uint32_t                                        dst_addr;
44         /* Options could be here (depends on the hdr length) */
45 } __attribute__((packed));
46
47 struct udp_hdr {
48         uint16_t                                        src_port;
49         uint16_t                                        dst_port;
50         uint16_t                                        length;
51         uint16_t                                        checksum;
52 };
53
54 uint16_t __ip_checksum(void *buf, unsigned int len, uint32_t sum);
55 uint16_t ip_checksum(struct ip_hdr *ip_hdr);
56 uint16_t udp_checksum(struct ip_hdr *ip_hdr, struct udp_hdr *udp_hdr);
57
58 // TODO: Move this to a better location
59 void dumppacket(unsigned char *buff, size_t len);
60 #endif /* ROS_KERN_NET_H */