Add qemu 2.4.0
[kvmfornfv.git] / qemu / roms / SLOF / clients / net-snk / app / netlib / ipv4.h
1 /******************************************************************************
2  * Copyright (c) 2004, 2008 IBM Corporation
3  * All rights reserved.
4  * This program and the accompanying materials
5  * are made available under the terms of the BSD License
6  * which accompanies this distribution, and is available at
7  * http://www.opensource.org/licenses/bsd-license.php
8  *
9  * Contributors:
10  *     IBM Corporation - initial implementation
11  *****************************************************************************/
12
13
14 #ifndef _IPV4_H_
15 #define _IPV4_H_
16
17 #include <stdint.h>
18
19 #define IPTYPE_ICMP         1
20
21 /** \struct iphdr
22  *  A header for IP-packets.
23  *  For more information see RFC 791.
24  */
25 struct iphdr {
26         uint8_t ip_hlv;      /**< Header length and version of the header      */
27         uint8_t ip_tos;      /**< Type of Service                              */
28         uint16_t ip_len;     /**< Length in octets, inlc. this header and data */
29         uint16_t ip_id;      /**< ID is used to aid in assembling framents     */
30         uint16_t ip_off;     /**< Info about fragmentation (control, offset)   */
31         uint8_t ip_ttl;      /**< Time to Live                                 */
32         uint8_t ip_p;        /**< Next level protocol type                     */
33         uint16_t ip_sum;     /**< Header checksum                              */
34         uint32_t ip_src;     /**< Source IP address                            */
35         uint32_t ip_dst;     /**< Destination IP address                       */
36 };
37 typedef struct iphdr ipv4_hdr_t;
38
39 /* ICMP Error Codes */
40 #define ICMP_NET_UNREACHABLE 0
41 #define ICMP_HOST_UNREACHABLE 1
42 #define ICMP_PROTOCOL_UNREACHABLE 2
43 #define ICMP_PORT_UNREACHABLE 3
44 #define ICMP_FRAGMENTATION_NEEDED 4
45 #define ICMP_SOURCE_ROUTE_FAILED 5
46
47 /** \struct arphdr
48  *  A header for ARP-messages, retains info about HW and proto addresses.
49  *  For more information see RFC 826.
50  */
51 struct arphdr {
52         uint16_t hw_type;    /**< HW address space (1 for Ethernet)            */
53         uint16_t proto_type; /**< Protocol address space                       */
54         uint8_t hw_len;      /**< Byte length of each HW address               */
55         uint8_t proto_len;   /**< Byte length of each proto address            */
56         uint16_t opcode;     /**< Identifies is it request (1) or reply (2)    */
57         uint8_t src_mac[6];  /**< HW address of sender of this packet          */
58         uint32_t src_ip;     /**< Proto address of sender of this packet       */
59         uint8_t dest_mac[6]; /**< HW address of target of this packet          */
60         uint32_t dest_ip;    /**< Proto address of target of this packet       */
61 } __attribute((packed));
62
63 /*>>>>>>>>>>>>> Initialization of the IPv4 network layer. <<<<<<<<<<<<<*/
64 extern void     set_ipv4_address(uint32_t own_ip);
65 extern uint32_t get_ipv4_address(void);
66 extern void     set_ipv4_multicast(uint32_t multicast_ip);
67 extern uint32_t get_ipv4_multicast(void);
68 extern void     set_ipv4_router(uint32_t router_ip);
69 extern uint32_t get_ipv4_router(void);
70 extern void     set_ipv4_netmask(uint32_t subnet_mask);
71 extern uint32_t get_ipv4_netmask(void);
72
73 extern int   (*send_ip) (int fd, void *, int);
74
75 /* fills ip header */
76 extern void fill_iphdr(uint8_t * packet, uint16_t packetsize,
77                        uint8_t ip_proto, uint32_t ip_src, uint32_t ip_dst);
78
79 /* Send a IPv4 packet. Adding the Ethernet-Header and resolving the
80  * MAC address is done transparent in the background if necessary.
81  */
82 extern int send_ipv4(int fd, void* buffer, int len);
83
84 /* Sends an ICMP Echo request to destination IPv4 address */
85 extern void ping_ipv4(int fd, uint32_t _ping_dst_ip);
86
87 /* Returns host IPv4 address that we are waiting for a response */
88 extern uint32_t pong_ipv4(void);
89
90 /* Handles IPv4-packets that are detected by receive_ether. */
91 extern int8_t handle_ipv4(int fd, uint8_t * packet, int32_t packetsize);
92
93 /* Handles ARP-packets that are detected by receive_ether. */
94 extern int8_t handle_arp(int fd, uint8_t * packet, int32_t packetsize);
95
96 #endif