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 <pcap/nflog.h>
30 #include <arpa/inet.h>
31 #include <net/ethernet.h>
32 #include <net/if_arp.h>
33 #include <netinet/ether.h>
34 #include <netinet/ip.h>
35 #include <netinet/ip6.h>
36 #include <netinet/ip_icmp.h>
37 #include <netinet/tcp.h>
38 #include <netinet/udp.h>
40 #include "stc-error.h"
41 #include "stc-manager.h"
43 #define BUFF_SIZE_IP 16
44 #define BUFF_SIZE_IP6 46
45 #define BUFF_SIZE_HOST 32
46 #define BUFF_SIZE_ID 64
47 #define BUFF_SIZE_TIME 64
48 #define BUFF_SIZE_NAME 256
50 #define PORT_FTP_DATA 20
51 #define PORT_FTP_CTL 21
54 #define PORT_BOOTP_S 67
55 #define PORT_BOOTP_C 68
58 #define PORT_HTTPS 443
59 #define PORT_SMTP_MSG 587
63 #define ARP_RREQUEST 3
66 #define BOOTP_REQUEST 1
69 #define BOOTP_CHADDR_LEN 16
70 #define BOOTP_SNAME_LEN 64
71 #define BOOTP_FILE_LEN 128
72 #define BOOTP_MOPTION_LEN 60
74 #define BOOTP_MAGIC_DHCP 0x63825363
76 #define DHCP_TAG_SUBNET_MASK 1
77 #define DHCP_TAG_ROUTER 3
78 #define DHCP_TAG_DNS 6
79 #define DHCP_TAG_HOST_NAME 12
80 #define DHCP_TAG_REQUESTED_IP 50
81 #define DHCP_TAG_IP_LEASE_TIME 51
82 #define DHCP_TAG_MSG_TYPE 53
83 #define DHCP_TAG_SERVER_ID 54
84 #define DHCP_TAG_MSG_SIZE 57
85 #define DHCP_TAG_CLIENT_ID 61
86 #define DHCP_TAG_END 255
88 #define DHCP_MSG_TYPE_DISCOVER 1
89 #define DHCP_MSG_TYPE_OFFER 2
90 #define DHCP_MSG_TYPE_REQUEST 3
91 #define DHCP_MSG_TYPE_DECLINE 4
92 #define DHCP_MSG_TYPE_ACK 5
93 #define DHCP_MSG_TYPE_NAK 6
94 #define DHCP_MSG_TYPE_RELEASE 7
95 #define DHCP_MSG_TYPE_INFORM 8
97 #define DHCP_CLIENT_ID_ETHERNET 1
98 #define DHCP_CLIENT_ID_IEEE802 2
99 #define DHCP_CLIENT_ID_ARCNET 7
100 #define DHCP_CLIENT_ID_LOCALTALK 11
101 #define DHCP_CLIENT_ID_LOCALNET 12
102 #define DHCP_CLIENT_ID_SMDS 14
103 #define DHCP_CLIENT_ID_FRAMERELAY 15
104 #define DHCP_CLIENT_ID_ATM1 16
105 #define DHCP_CLIENT_ID_HDLC 17
106 #define DHCP_CLIENT_ID_FIBRECHANNEL 18
107 #define DHCP_CLIENT_ID_ATM2 19
108 #define DHCP_CLIENT_ID_SERIALLINE 20
110 #define NTP_STRATUM_UNSPECIFIED 0
111 #define NTP_STRATUM_PRIM_REF 1
112 #define NTP_STRATUM_INFO_QUERY 62
113 #define NTP_STRATUM_INFO_REPLY 63
115 #define NTP_JAN_1970 2208988800U /* 1970 - 1900 in seconds */
117 #define DNS_QTYPE_A 1
118 #define DNS_QTYPE_CNAME 5
119 #define DNS_QTYPE_AAAA 28
121 #define DNS_QCLASS_IN 1
122 #define DNS_QCLASS_CHAOS 3
123 #define DNS_QCLASS_HS 4
124 #define DNS_QCLASS_ANY 255
140 uint16_t authorityRR;
141 uint16_t additionalRR;
158 uint8_t op; /* packet opcode type */
159 uint8_t htype; /* hardware addr type */
160 uint8_t hlen; /* hardware addr length */
161 uint8_t hops; /* gateway hops */
162 uint32_t xid; /* transaction ID */
163 uint16_t secs; /* seconds since boot began */
164 uint16_t flags; /* flags */
165 struct in_addr ciaddr; /* client IP address */
166 struct in_addr yiaddr; /* 'your' IP address */
167 struct in_addr siaddr; /* server IP address */
168 struct in_addr giaddr; /* gateway(relay agent) IP address */
169 uint8_t chaddr[BOOTP_CHADDR_LEN]; /* client hardware address */
170 uint8_t sname[BOOTP_SNAME_LEN]; /* server host name */
171 uint8_t file[BOOTP_FILE_LEN]; /* boot file name */
172 uint32_t magic; /* must be 0x63825363 (network order) */
173 uint8_t moption[BOOTP_MOPTION_LEN];
187 uint8_t flags; /* Mode, version and leap indicator */
188 uint8_t stratum; /* Stratum details */
189 uint8_t poll; /* Maximum interval in log2 seconds */
190 uint8_t precision; /* Clock precision in log2 seconds */
191 ntp_short_t rootdelay; /* Root delay */
192 ntp_short_t rootdisp; /* Root dispersion */
193 uint32_t refid; /* Reference ID */
194 ntp_long_t reftime; /* Reference timestamp */
195 ntp_long_t orgtime; /* Origin timestamp */
196 ntp_long_t rectime; /* Receive timestamp */
197 ntp_long_t xmttime; /* Transmit timestamp */
200 typedef struct ether_header eth_t;
201 typedef struct ip ip_t;
202 typedef struct ip6_hdr ip6_t;
203 typedef struct arphdr arp_t;
204 typedef struct icmphdr icmp_t;
205 typedef struct tcphdr tcp_t;
206 typedef struct udphdr udp_t;
208 #define SIZE_ETHER_HEADER sizeof(eth_t)
209 #define SIZE_IP_HEADER sizeof(ip_t)
210 #define SIZE_ARP_HEADER sizeof(arp_t)
211 #define SIZE_ICMP_HEADER sizeof(icmp_t)
212 #define SIZE_TCP_HEADER sizeof(tcp_t)
213 #define SIZE_UDP_HEADER sizeof(udp_t)
214 #define SIZE_DNS_HEADER sizeof(dns_t)
216 #define SIZE_NFLOG_HDR sizeof(nflog_hdr_t)
217 #define SIZE_NFLOG_TLV sizeof(nflog_tlv_t)
219 #define IS_SRC_OR_DST_PORT(p) (source == (p) || dest == (p))
222 int (*initialize_plugin) (void);
223 int (*deinitialize_plugin) (void);
224 int (*lookup_dev) (void);
225 int (*lookup_net) (void);
226 int (*find_all_devs) (GVariantBuilder *builder);
227 int (*register_loop) (const char *ifname, int group);
228 int (*unregister_loop) (const char *ifname, int group);
229 int (*get_all_loop) (GVariantBuilder *builder);
232 #endif /* __STC_PLUGIN_PCAP_H__ */