2 * Copyright (c) 2016 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #ifndef __STC_PLUGIN_PCAP_H__
18 #define __STC_PLUGIN_PCAP_H__
29 #include <arpa/inet.h>
30 #include <net/ethernet.h>
31 #include <net/if_arp.h>
32 #include <netinet/ether.h>
33 #include <netinet/ip.h>
34 #include <netinet/ip6.h>
35 #include <netinet/ip_icmp.h>
36 #include <netinet/tcp.h>
37 #include <netinet/udp.h>
39 #include "stc-error.h"
40 #include "stc-manager.h"
42 #define BUFF_SIZE_IP 16
43 #define BUFF_SIZE_IP6 46
44 #define BUFF_SIZE_HOST 32
45 #define BUFF_SIZE_ID 64
46 #define BUFF_SIZE_TIME 64
47 #define BUFF_SIZE_NAME 256
49 #define PORT_FTP_DATA 20
50 #define PORT_FTP_CTL 21
53 #define PORT_BOOTP_S 67
54 #define PORT_BOOTP_C 68
57 #define PORT_HTTPS 443
58 #define PORT_SMTP_MSG 587
62 #define ARP_RREQUEST 3
65 #define BOOTP_REQUEST 1
68 #define BOOTP_CHADDR_LEN 16
69 #define BOOTP_SNAME_LEN 64
70 #define BOOTP_FILE_LEN 128
71 #define BOOTP_MOPTION_LEN 60
73 #define BOOTP_MAGIC_DHCP 0x63825363
75 #define DHCP_TAG_SUBNET_MASK 1
76 #define DHCP_TAG_ROUTER 3
77 #define DHCP_TAG_DNS 6
78 #define DHCP_TAG_HOST_NAME 12
79 #define DHCP_TAG_REQUESTED_IP 50
80 #define DHCP_TAG_IP_LEASE_TIME 51
81 #define DHCP_TAG_MSG_TYPE 53
82 #define DHCP_TAG_SERVER_ID 54
83 #define DHCP_TAG_MSG_SIZE 57
84 #define DHCP_TAG_CLIENT_ID 61
85 #define DHCP_TAG_END 255
87 #define DHCP_MSG_TYPE_DISCOVER 1
88 #define DHCP_MSG_TYPE_OFFER 2
89 #define DHCP_MSG_TYPE_REQUEST 3
90 #define DHCP_MSG_TYPE_DECLINE 4
91 #define DHCP_MSG_TYPE_ACK 5
92 #define DHCP_MSG_TYPE_NAK 6
93 #define DHCP_MSG_TYPE_RELEASE 7
94 #define DHCP_MSG_TYPE_INFORM 8
96 #define DHCP_CLIENT_ID_ETHERNET 1
97 #define DHCP_CLIENT_ID_IEEE802 2
98 #define DHCP_CLIENT_ID_ARCNET 7
99 #define DHCP_CLIENT_ID_LOCALTALK 11
100 #define DHCP_CLIENT_ID_LOCALNET 12
101 #define DHCP_CLIENT_ID_SMDS 14
102 #define DHCP_CLIENT_ID_FRAMERELAY 15
103 #define DHCP_CLIENT_ID_ATM1 16
104 #define DHCP_CLIENT_ID_HDLC 17
105 #define DHCP_CLIENT_ID_FIBRECHANNEL 18
106 #define DHCP_CLIENT_ID_ATM2 19
107 #define DHCP_CLIENT_ID_SERIALLINE 20
109 #define NTP_STRATUM_UNSPECIFIED 0
110 #define NTP_STRATUM_PRIM_REF 1
111 #define NTP_STRATUM_INFO_QUERY 62
112 #define NTP_STRATUM_INFO_REPLY 63
114 #define NTP_JAN_1970 2208988800U /* 1970 - 1900 in seconds */
116 #define DNS_QTYPE_A 1
117 #define DNS_QTYPE_CNAME 5
118 #define DNS_QTYPE_AAAA 28
120 #define DNS_QCLASS_IN 1
121 #define DNS_QCLASS_CHAOS 3
122 #define DNS_QCLASS_HS 4
123 #define DNS_QCLASS_ANY 255
137 uint16_t authorityRR;
138 uint16_t additionalRR;
155 uint8_t op; /* packet opcode type */
156 uint8_t htype; /* hardware addr type */
157 uint8_t hlen; /* hardware addr length */
158 uint8_t hops; /* gateway hops */
159 uint32_t xid; /* transaction ID */
160 uint16_t secs; /* seconds since boot began */
161 uint16_t flags; /* flags */
162 struct in_addr ciaddr; /* client IP address */
163 struct in_addr yiaddr; /* 'your' IP address */
164 struct in_addr siaddr; /* server IP address */
165 struct in_addr giaddr; /* gateway(relay agent) IP address */
166 uint8_t chaddr[BOOTP_CHADDR_LEN]; /* client hardware address */
167 uint8_t sname[BOOTP_SNAME_LEN]; /* server host name */
168 uint8_t file[BOOTP_FILE_LEN]; /* boot file name */
169 uint32_t magic; /* must be 0x63825363 (network order) */
170 uint8_t moption[BOOTP_MOPTION_LEN];
184 uint8_t flags; /* Mode, version and leap indicator */
185 uint8_t stratum; /* Stratum details */
186 uint8_t poll; /* Maximum interval in log2 seconds */
187 uint8_t precision; /* Clock precision in log2 seconds */
188 ntp_short_t rootdelay; /* Root delay */
189 ntp_short_t rootdisp; /* Root dispersion */
190 uint32_t refid; /* Reference ID */
191 ntp_long_t reftime; /* Reference timestamp */
192 ntp_long_t orgtime; /* Origin timestamp */
193 ntp_long_t rectime; /* Receive timestamp */
194 ntp_long_t xmttime; /* Transmit timestamp */
197 typedef struct ether_header eth_t;
198 typedef struct ip ip_t;
199 typedef struct ip6_hdr ip6_t;
200 typedef struct arphdr arp_t;
201 typedef struct icmphdr icmp_t;
202 typedef struct tcphdr tcp_t;
203 typedef struct udphdr udp_t;
205 #define SIZE_ETHER_HEADER sizeof(eth_t)
206 #define SIZE_IP_HEADER sizeof(ip_t)
207 #define SIZE_ARP_HEADER sizeof(arp_t)
208 #define SIZE_ICMP_HEADER sizeof(icmp_t)
209 #define SIZE_TCP_HEADER sizeof(tcp_t)
210 #define SIZE_UDP_HEADER sizeof(udp_t)
211 #define SIZE_DNS_HEADER sizeof(dns_t)
213 #define IS_SRC_OR_DST_PORT(p) (source == (p) || dest == (p))
216 int (*initialize_plugin) (void);
217 int (*deinitialize_plugin) (void);
218 int (*lookup_dev) (void);
219 int (*lookup_net) (void);
220 int (*find_alldevs) (void);
221 int (*register_loop_pcap) (const char *ifname, int group);
222 int (*unregister_loop_pcap) (const char *ifname, int group);
225 #endif /* __STC_PLUGIN_PCAP_H__ */