Codebase list suricata / f88938a
Update upstream source from tag 'upstream/5.0.3' Update to upstream version '5.0.3' with Debian dir 5f4b2658b43e4a8b2049bd26ea4928751f2a5795 Sascha Steinbiss 4 years ago
361 changed file(s) with 5355 addition(s) and 5237 deletion(s). Raw diff Collapse all Expand all
0 5.0.3 -- 2020-04-28
1
2 Feature #3481: GRE ERSPAN Type 1 Support
3 Feature #3613: Teredo port configuration
4 Feature #3673: datasets: add 'dataset-remove' unix command
5 Bug #3240: Dataset hash-size or prealloc invalid value logging
6 Bug #3241: Dataset reputation invalid value logging
7 Bug #3342: Suricata 5.0 crashes while parsing SMB data
8 Bug #3450: signature with sticky buffer with subsequent pcre check in a different buffer loads but will never match
9 Bug #3491: Backport 5 BUG_ON(strcasecmp(str, "any") in DetectAddressParseString
10 Bug #3507: rule parsing: memory leaks
11 Bug #3526: 5.0.x Kerberos vulnerable to TCP splitting evasion
12 Bug #3534: Skip over ERF_TYPE_META records
13 Bug #3552: file logging: complete files sometimes marked 'TRUNCATED'
14 Bug #3571: rust: smb compile warnings
15 Bug #3573: TCP Fast Open - Bypass of stateless alerts
16 Bug #3574: Behavior for tcp fastopen
17 Bug #3576: Segfault when facing malformed SNMP rules
18 Bug #3577: SIP: Input not parsed when header values contain trailing spaces
19 Bug #3580: Faulty signature with two threshold keywords does not generate an error and never match
20 Bug #3582: random failures on sip and http-evader suricata-verify tests
21 Bug #3585: htp: asan issue
22 Bug #3592: Segfault on SMTP TLS
23 Bug #3598: rules: memory leaks in pktvar keyword
24 Bug #3600: rules: bad address block leads to stack exhaustion
25 Bug #3602: rules: crash on 'internal'-only keywords
26 Bug #3604: rules: missing 'consumption' of transforms before pkt_data would lead to crash
27 Bug #3606: rules: minor memory leak involving pcre_get_substring
28 Bug #3609: ssl/tls: ASAN issue in SSLv3ParseHandshakeType
29 Bug #3610: defrag: asan issue
30 Bug #3612: rules/bsize: memory issue during parsing
31 Bug #3614: build-info and configure wrongly display libnss status
32 Bug #3644: Invalid memory read on malformed rule with Lua script
33 Bug #3646: rules: memory leaks on failed rules
34 Bug #3649: CIDR Parsing Issue
35 Bug #3651: FTP response buffering against TCP stream
36 Bug #3653: Recursion stack-overflow in parsing YAML configuration
37 Bug #3660: Multiple DetectEngineReload and bad insertion into linked list lead to buffer overflow
38 Bug #3665: FTP: Incorrect ftp_memuse calculation.
39 Bug #3667: Signature with an IP range creates one IPOnlyCIDRItem by signe IP address
40 Bug #3669: Rules reload with Napatech can hang Suricata UNIX manager process
41 Bug #3672: coverity: data directory handling issues
42 Bug #3674: Protocol detection evasion by packet splitting
43 Optimization #3406: filestore rules are loaded without warning when filestore is not enabled
44 Task #3478: libhtp 0.5.33
45 Task #3514: SMTP should place restraints on variable length items (e.g., filenames)
46 Documentation #3543: doc: add ipv4.hdr and ipv6.hdr
47
048 5.0.2 -- 2020-02-13
149
250 Bug #2993: Suricata 5.0.0beta1 memory allocation of 4294966034 bytes failed
00 #! /bin/sh
11 # Guess values for system-dependent variables and create Makefiles.
2 # Generated by GNU Autoconf 2.69 for suricata 5.0.2.
2 # Generated by GNU Autoconf 2.69 for suricata 5.0.3.
33 #
44 #
55 # Copyright (C) 1992-1996, 1998-2012 Free Software Foundation, Inc.
642642 # Identity of this package.
643643 PACKAGE_NAME='suricata'
644644 PACKAGE_TARNAME='suricata'
645 PACKAGE_VERSION='5.0.2'
646 PACKAGE_STRING='suricata 5.0.2'
645 PACKAGE_VERSION='5.0.3'
646 PACKAGE_STRING='suricata 5.0.3'
647647 PACKAGE_BUGREPORT=''
648648 PACKAGE_URL=''
649649
16141614 # Omit some internal or obsolete options to make the list less imposing.
16151615 # This message is too long to be a string in the A/UX 3.1 sh.
16161616 cat <<_ACEOF
1617 \`configure' configures suricata 5.0.2 to adapt to many kinds of systems.
1617 \`configure' configures suricata 5.0.3 to adapt to many kinds of systems.
16181618
16191619 Usage: $0 [OPTION]... [VAR=VALUE]...
16201620
16851685
16861686 if test -n "$ac_init_help"; then
16871687 case $ac_init_help in
1688 short | recursive ) echo "Configuration of suricata 5.0.2:";;
1688 short | recursive ) echo "Configuration of suricata 5.0.3:";;
16891689 esac
16901690 cat <<\_ACEOF
16911691
19361936 test -n "$ac_init_help" && exit $ac_status
19371937 if $ac_init_version; then
19381938 cat <<\_ACEOF
1939 suricata configure 5.0.2
1939 suricata configure 5.0.3
19401940 generated by GNU Autoconf 2.69
19411941
19421942 Copyright (C) 2012 Free Software Foundation, Inc.
24012401 This file contains any messages produced by compilers while
24022402 running configure, to aid debugging if configure makes a mistake.
24032403
2404 It was created by suricata $as_me 5.0.2, which was
2404 It was created by suricata $as_me 5.0.3, which was
24052405 generated by GNU Autoconf 2.69. Invocation command line was
24062406
24072407 $ $0 $@
32683268
32693269 # Define the identity of the package.
32703270 PACKAGE='suricata'
3271 VERSION='5.0.2'
3271 VERSION='5.0.3'
32723272
32733273
32743274 cat >>confdefs.h <<_ACEOF
1996919969 # report actual input values of CONFIG_FILES etc. instead of their
1997019970 # values after options handling.
1997119971 ac_log="
19972 This file was extended by suricata $as_me 5.0.2, which was
19972 This file was extended by suricata $as_me 5.0.3, which was
1997319973 generated by GNU Autoconf 2.69. Invocation command line was
1997419974
1997519975 CONFIG_FILES = $CONFIG_FILES
2003520035 cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
2003620036 ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`"
2003720037 ac_cs_version="\\
20038 suricata config.status 5.0.2
20038 suricata config.status 5.0.3
2003920039 configured by $0, generated by GNU Autoconf 2.69,
2004020040 with options \\"\$ac_cs_config\\"
2004120041
2193721937 pkg_cv_LIBHTPMINVERSION_CFLAGS="$LIBHTPMINVERSION_CFLAGS"
2193821938 elif test -n "$PKG_CONFIG"; then
2193921939 if test -n "$PKG_CONFIG" && \
21940 { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"htp >= 0.5.32\""; } >&5
21941 ($PKG_CONFIG --exists --print-errors "htp >= 0.5.32") 2>&5
21940 { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"htp >= 0.5.33\""; } >&5
21941 ($PKG_CONFIG --exists --print-errors "htp >= 0.5.33") 2>&5
2194221942 ac_status=$?
2194321943 $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
2194421944 test $ac_status = 0; }; then
21945 pkg_cv_LIBHTPMINVERSION_CFLAGS=`$PKG_CONFIG --cflags "htp >= 0.5.32" 2>/dev/null`
21945 pkg_cv_LIBHTPMINVERSION_CFLAGS=`$PKG_CONFIG --cflags "htp >= 0.5.33" 2>/dev/null`
2194621946 test "x$?" != "x0" && pkg_failed=yes
2194721947 else
2194821948 pkg_failed=yes
2195421954 pkg_cv_LIBHTPMINVERSION_LIBS="$LIBHTPMINVERSION_LIBS"
2195521955 elif test -n "$PKG_CONFIG"; then
2195621956 if test -n "$PKG_CONFIG" && \
21957 { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"htp >= 0.5.32\""; } >&5
21958 ($PKG_CONFIG --exists --print-errors "htp >= 0.5.32") 2>&5
21957 { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"htp >= 0.5.33\""; } >&5
21958 ($PKG_CONFIG --exists --print-errors "htp >= 0.5.33") 2>&5
2195921959 ac_status=$?
2196021960 $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
2196121961 test $ac_status = 0; }; then
21962 pkg_cv_LIBHTPMINVERSION_LIBS=`$PKG_CONFIG --libs "htp >= 0.5.32" 2>/dev/null`
21962 pkg_cv_LIBHTPMINVERSION_LIBS=`$PKG_CONFIG --libs "htp >= 0.5.33" 2>/dev/null`
2196321963 test "x$?" != "x0" && pkg_failed=yes
2196421964 else
2196521965 pkg_failed=yes
2198021980 _pkg_short_errors_supported=no
2198121981 fi
2198221982 if test $_pkg_short_errors_supported = yes; then
21983 LIBHTPMINVERSION_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "htp >= 0.5.32" 2>&1`
21983 LIBHTPMINVERSION_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "htp >= 0.5.33" 2>&1`
2198421984 else
21985 LIBHTPMINVERSION_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "htp >= 0.5.32" 2>&1`
21985 LIBHTPMINVERSION_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "htp >= 0.5.33" 2>&1`
2198621986 fi
2198721987 # Put the nasty error message in config.log where it belongs
2198821988 echo "$LIBHTPMINVERSION_PKG_ERRORS" >&5
2207322073 fi
2207422074 if test "$libhtp_devver_found" = "no"; then
2207522075 echo
22076 echo " ERROR! libhtp was found but it is neither >= 0.5.32, nor the dev 0.5.X"
22076 echo " ERROR! libhtp was found but it is neither >= 0.5.33, nor the dev 0.5.X"
2207722077 echo
2207822078 exit 1
2207922079 fi
2304423044 echo " Fedora: dnf install nspr-devel"
2304523045 echo " CentOS/RHEL: yum install nspr-devel"
2304623046 echo
23047 enable_nspr="no"
2304723048 fi
2304823049 fi
2304923050
2322723228 echo " Fedora: dnf install nss-devel"
2322823229 echo " CentOS/RHEL: yum install nss-devel"
2322923230 echo
23231 enable_nss="no"
2323023232 fi
2323123233 fi
2323223234
2820428206 # report actual input values of CONFIG_FILES etc. instead of their
2820528207 # values after options handling.
2820628208 ac_log="
28207 This file was extended by suricata $as_me 5.0.2, which was
28209 This file was extended by suricata $as_me 5.0.3, which was
2820828210 generated by GNU Autoconf 2.69. Invocation command line was
2820928211
2821028212 CONFIG_FILES = $CONFIG_FILES
2827028272 cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
2827128273 ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`"
2827228274 ac_cs_version="\\
28273 suricata config.status 5.0.2
28275 suricata config.status 5.0.3
2827428276 configured by $0, generated by GNU Autoconf 2.69,
2827528277 with options \\"\$ac_cs_config\\"
2827628278
0 AC_INIT([suricata],[5.0.2])
0 AC_INIT([suricata],[5.0.3])
11 m4_ifndef([AM_SILENT_RULES], [m4_define([AM_SILENT_RULES],[])])AM_SILENT_RULES([yes])
22 AC_CONFIG_HEADERS([config.h])
33 AC_CONFIG_SRCDIR([src/suricata.c])
15971597 echo
15981598 exit 1
15991599 fi
1600 PKG_CHECK_MODULES(LIBHTPMINVERSION, [htp >= 0.5.32],[libhtp_minver_found="yes"],[libhtp_minver_found="no"])
1600 PKG_CHECK_MODULES(LIBHTPMINVERSION, [htp >= 0.5.33],[libhtp_minver_found="yes"],[libhtp_minver_found="no"])
16011601 if test "$libhtp_minver_found" = "no"; then
16021602 PKG_CHECK_MODULES(LIBHTPDEVVERSION, [htp = 0.5.X],[libhtp_devver_found="yes"],[libhtp_devver_found="no"])
16031603 if test "$libhtp_devver_found" = "no"; then
16041604 echo
1605 echo " ERROR! libhtp was found but it is neither >= 0.5.32, nor the dev 0.5.X"
1605 echo " ERROR! libhtp was found but it is neither >= 0.5.33, nor the dev 0.5.X"
16061606 echo
16071607 exit 1
16081608 fi
18181818 echo " Fedora: dnf install nspr-devel"
18191819 echo " CentOS/RHEL: yum install nspr-devel"
18201820 echo
1821 enable_nspr="no"
18211822 fi
18221823 fi
18231824
18701871 echo " Fedora: dnf install nss-devel"
18711872 echo " CentOS/RHEL: yum install nss-devel"
18721873 echo
1874 enable_nss="no"
18731875 fi
18741876 fi
18751877
23252325 # it will sometimes detect non-teredo as teredo.
23262326 teredo:
23272327 enabled: true
2328
2328 # ports to look for Teredo. Max 4 ports. If no ports are given, or
2329 # the value is set to 'any', Teredo detection runs on _all_ UDP packets.
2330 ports: $TEREDO_PORTS # syntax: '[3544, 1234]'
2331
2332 Using this default configuration, Teredo detection will run on UDP port
2333 3544. If the `ports` parameter is missing, or set to `any`, all ports will be
2334 inspected for possible presence of Teredo.
23292335
23302336 Advanced Options
23312337 ----------------
1919 mpm-algo: <ac|hs|ac-bs|ac-ks>
2020 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2121
22 Controls the pattern matcher algorithm. AC (``Aho–Corasick ``) is the default.
22 Controls the pattern matcher algorithm. AC (``Aho–Corasick``) is the default.
2323 On supported platforms, :doc:`hyperscan` is the best option. On commodity
2424 hardware if Hyperscan is not available the suggested setting is
25 ``mpm-algo: ac-ks`` (``Aho–Corasick `` Ken Steele variant) as it performs better than
25 ``mpm-algo: ac-ks`` (``Aho–Corasick`` Ken Steele variant) as it performs better than
2626 ``mpm-algo: ac``
2727
2828 detect.profile: <low|medium|high|custom>
109109 The named variant of that example would be::
110110
111111 ip_proto:PIM
112
113 ipv4.hdr
114 ^^^^^^^^
115
116 Sticky buffer to match on the whole IPv4 header.
117
118 Example rule:
119
120 .. container:: example-rule
121
122 alert ip any any -> any any (:example-rule-emphasis:`ipv4.hdr; content:"|3A|"; offset:9; depth:1;` sid:1234; rev:5;)
123
124 This example looks if byte 9 of IPv4 header has value 3A.
125 That means that the IPv4 protocol is ICMPv6.
126
127 ipv6.hdr
128 ^^^^^^^^
129
130 Sticky buffer to match on the whole IPv6 header.
112131
113132 id
114133 ^^
5858 http.header Sticky Buffer Both
5959 http.header.raw Sticky Buffer Both
6060 http.cookie Sticky Buffer Both
61 http.server_body Sticky Buffer Response
61 http.response_body Sticky Buffer Response
6262 http.server Sticky Buffer Response
6363 http.location Sticky Buffer Response
6464 file_data Sticky Buffer Response
303303 Format::
304304
305305 byte_test:<num of bytes>, [!]<operator>, <test value>, <offset> [,relative] \
306 [,<endian>][, string, <num type>][, dce][, bitmask <bitmask value>];
306 [,<endian>][, string, <num type>][, dce];
307307
308308
309309 +----------------+------------------------------------------------------------------------------+
336336 +----------------+------------------------------------------------------------------------------+
337337 | [dce] | Allow the DCE module determine the byte order |
338338 +----------------+------------------------------------------------------------------------------+
339 | [bitmask] | Applies the AND operator on the bytes converted |
340 +----------------+------------------------------------------------------------------------------+
341339
342340
343341 Example::
375373
376374 byte_jump:<num of bytes>, <offset> [, relative][, multiplier <mult_value>] \
377375 [, <endian>][, string, <num_type>][, align][, from_beginning][, from_end] \
378 [, post_offset <value>][, dce][, bitmask <value>];
376 [, post_offset <value>][, dce];
379377
380378 +-----------------------+-----------------------------------------------------------------------+
381379 | <num of bytes> | The number of bytes selected from the packet to be converted |
406404 | | jump an additional number of bytes specified by <value> |
407405 +-----------------------+-----------------------------------------------------------------------+
408406 | [dce] | Allow the DCE module determine the byte order |
409 +-----------------------+-----------------------------------------------------------------------+
410 | [bitmask] <value> | The AND operator will be applied by <value> and the |
411 | | converted bytes, then jump operation is performed |
412407 +-----------------------+-----------------------------------------------------------------------+
413408
414409 Example::
00 .\" Man page generated from reStructuredText.
11 .
2 .TH "SURICATA" "1" "Feb 13, 2020" "5.0.2" "Suricata"
2 .TH "SURICATA" "1" "Apr 28, 2020" "5.0.3" "Suricata"
33 .SH NAME
44 suricata \- Suricata
55 .
435435 maintainer-clean-generic:
436436 @echo "This command is intended for maintainers to use"
437437 @echo "it deletes files that may require special tools to rebuild."
438 @HAVE_PYTHON_DISTUTILS_FALSE@uninstall-local:
439 @HAVE_PYTHON_FALSE@uninstall-local:
440438 @HAVE_PYTHON_DISTUTILS_FALSE@distclean-local:
441439 @HAVE_PYTHON_FALSE@distclean-local:
442440 @HAVE_PYTHON_DISTUTILS_FALSE@clean-local:
443441 @HAVE_PYTHON_FALSE@clean-local:
444442 @HAVE_PYTHON_DISTUTILS_FALSE@install-exec-local:
445443 @HAVE_PYTHON_FALSE@install-exec-local:
444 @HAVE_PYTHON_DISTUTILS_FALSE@uninstall-local:
445 @HAVE_PYTHON_FALSE@uninstall-local:
446446 clean: clean-am
447447
448448 clean-am: clean-generic clean-libtool clean-local mostlyclean-am
179179 "required": 1,
180180 },
181181 ],
182 "dataset-remove": [
183 {
184 "name": "setname",
185 "required": 1,
186 },
187 {
188 "name": "settype",
189 "required": 1,
190 },
191 {
192 "name": "datavalue",
193 "required": 1,
194 },
195 ],
182196 }
106106 "memcap-set",
107107 "memcap-show",
108108 "dataset-add",
109 "dataset-remove",
109110 ]
110111 self.cmd_list = self.basic_commands + self.fn_commands
111112 self.sck_path = sck_path
2828
2929 alert smtp any any -> any any (msg:"SURICATA SMTP duplicate fields"; flow:established,to_server; app-layer-event:smtp.duplicate_fields; flowint:smtp.anomaly.count,+,1; classtype:protocol-command-decode; sid:2220018; rev:1;)
3030 alert smtp any any -> any any (msg:"SURICATA SMTP unparsable content"; flow:established,to_server; app-layer-event:smtp.unparsable_content; flowint:smtp.anomaly.count,+,1; classtype:protocol-command-decode; sid:2220019; rev:1;)
31 # next sid 2220020
31 alert smtp any any -> any any (msg:"SURICATA SMTP filename truncated"; flow:established,to_server; app-layer-event:smtp.mime_long_filename; flowint:smtp.anomaly.count,+,1; classtype:protocol-command-decode; sid:2220020; rev:1;)
32 # next sid 2220021
526526 input_len: u32,
527527 _data: *const std::os::raw::c_void,
528528 _flags: u8) -> i32 {
529 if input_len < 4 { return -1; }
530529 let buf = build_slice!(input,input_len as usize);
531530 let state = cast_pointer!(state,KRB5State);
532531
554553 state.record_ts = record as usize;
555554 cur_i = rem;
556555 },
556 Err(nom::Err::Incomplete(_)) => {
557 state.defrag_buf_ts.extend_from_slice(cur_i);
558 return 0;
559 }
557560 _ => {
558561 SCLogDebug!("rs_krb5_parse_request_tcp: reading record mark failed!");
559562 return 1;
584587 input_len: u32,
585588 _data: *const std::os::raw::c_void,
586589 _flags: u8) -> i32 {
587 if input_len < 4 { return -1; }
588590 let buf = build_slice!(input,input_len as usize);
589591 let state = cast_pointer!(state,KRB5State);
590592
612614 state.record_tc = record as usize;
613615 cur_i = rem;
614616 },
617 Err(nom::Err::Incomplete(_)) => {
618 state.defrag_buf_tc.extend_from_slice(cur_i);
619 return 0;
620 }
615621 _ => {
616622 SCLogNotice!("rs_krb5_parse_response_tcp: reading record mark failed!");
617623 return 1;
10921092 },
10931093 0 => {
10941094 SCLogDebug!("incomplete, queue and retry with the next block (input {}). Looped {} times.", cur_i.len(), cnt);
1095 self.tcp_buffer_tc.extend_from_slice(cur_i);
1095 self.tcp_buffer_ts.extend_from_slice(cur_i);
10961096 return 0;
10971097 },
10981098 -1 => {
176176
177177 fn parse_header_value(buf: &[u8]) -> IResult<&[u8], &[u8]> {
178178 let mut end_pos = 0;
179 let mut trail_spaces = 0;
179180 let mut idx = 0;
180181 while idx < buf.len() {
181182 match buf[idx] {
190191 continue;
191192 }
192193 _ => {
193 return Ok((&buf[end_pos..], &buf[..end_pos]));
194 return Ok((&buf[(end_pos + trail_spaces)..], &buf[..end_pos]));
194195 }
195196 }
196197 }
197 b' ' | b'\t' | b'\r' => {}
198 b' ' | b'\t' => {
199 trail_spaces += 1;
200 }
201 b'\r' => {}
198202 b => {
203 trail_spaces = 0;
199204 if !is_header_value(b) {
200205 return Err(Err::Incomplete(Needed::Size(1)));
201206 }
235240 }
236241
237242 #[test]
243 fn test_parse_request_trail_space_header() {
244 let buf: &[u8] = "REGISTER sip:sip.cybercity.dk SIP/2.0\r\n\
245 From: <sip:voi18063@sip.cybercity.dk>;tag=903df0a\r\n\
246 To: <sip:voi18063@sip.cybercity.dk>\r\n\
247 Content-Length: 0 \r\n\
248 \r\n"
249 .as_bytes();
250
251 match sip_parse_request(buf) {
252 Ok((_, req)) => {
253 assert_eq!(req.method, "REGISTER");
254 assert_eq!(req.path, "sip:sip.cybercity.dk");
255 assert_eq!(req.version, "SIP/2.0");
256 assert_eq!(req.headers["Content-Length"], "0");
257 }
258 _ => {
259 assert!(false);
260 }
261 }
262 }
263
264 #[test]
238265 fn test_parse_response() {
239266 let buf: &[u8] = "SIP/2.0 401 Unauthorized\r\n\
240267 \r\n"
150150 true
151151 },
152152 1 => { // LT
153 (them < us)
153 them < us
154154 },
155155 2 => { // GT
156 (them > us)
156 them > us
157157 },
158158 3 => { // EQ
159 (them == us)
159 them == us
160160 },
161161 4 => { // NE
162 (them != us)
162 them != us
163163 },
164164 _ => {
165165 panic!("called with invalid op {}", op);
704704
705705 // don't include tree id
706706 pub fn compare(&self, hdr: &SMBCommonHdr) -> bool {
707 (self.rec_type == hdr.rec_type && self.ssn_id == hdr.ssn_id &&
708 self.msg_id == hdr.msg_id)
707 self.rec_type == hdr.rec_type && self.ssn_id == hdr.ssn_id &&
708 self.msg_id == hdr.msg_id
709709 }
710710 }
711711
0 {"files":{"CONTRIBUTING.md":"cc340197d05fd8f069dfda6347b97d3da92c8f260c75ac78fb6970f08dba7638","Cargo.toml":"ed3453ae907b85221c1c628d3bb3edd72719be5874a2373ead3f57564f938d18","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"6485b8ed310d3f0340bf1ad1f47645069ce4069dcc6bb46c7d5c6faf41de1fdb","README.md":"3d4ffed8a5f477b249d4e9684937b9b01b78994ded690d9712c1dbf13a8a1b31","build.rs":"ab351d7171b14f8032948e843841ebe8518ed95eb1abf0b1e689700c7cef4bf5","rustfmt.toml":"8a654d5787585ca8f2c20580737336fc327f411a07b0dbd4870adf6e9bdf624f","src/cloudabi/aarch64.rs":"b8550bf1fd7344972aa4db29441486f39f31482d0327534981dbb75959c29114","src/cloudabi/arm.rs":"c197e2781c2839808bd6fcef219a29705b27b992d3ef920e9cf6ac96e2022bbf","src/cloudabi/mod.rs":"7b36bc7429863346f11a395dbbc200a38b789066ee9aefeac808ecefda9a1a88","src/cloudabi/x86.rs":"33eb97f272d2201f3838ae74d444583c7de8f67856852ca375293b20bbd05636","src/cloudabi/x86_64.rs":"400d85d4fe39e26cf2e6ece9ee31c75fe9e88c4bcf4d836ca9f765c05c9c5be3","src/fixed_width_ints.rs":"34c60f12ec5eeb90f13ec3b954427532111c2446e69617616a97aefc1086a9f1","src/fuchsia/aarch64.rs":"378776a9e40766154a54c94c2a7b4675b5c302a38e6e42da99e67bfbaee60e56","src/fuchsia/align.rs":"ae1cf8f011a99737eabeb14ffff768e60f13b13363d7646744dbb0f443dab3d6","src/fuchsia/mod.rs":"8ab46872899b06f46b54bfa39cce3bd7e8a43abe871d9ea821dba1c16a3348d7","src/fuchsia/no_align.rs":"303f3f1b255e0088b5715094353cf00476131d8e94e6aebb3f469557771c8b8a","src/fuchsia/x86_64.rs":"93a3632b5cf67d2a6bcb7dc0a558605252d5fe689e0f38d8aa2ec5852255ac87","src/hermit/aarch64.rs":"86048676e335944c37a63d0083d0f368ae10ceccefeed9debb3bbe08777fc682","src/hermit/mod.rs":"aeda183662787a44c4bd26645cea76f31bf5f7c63d4d59118118c360705fb9eb","src/hermit/x86_64.rs":"ab832b7524e5fb15c49ff7431165ab1a37dc4667ae0b58e8306f4c539bfa110c","src/lib.rs":"1397a0db2d265c5777d4a405b4a92e875bc308449be8daae341c3eeabe82d72e","src/macros.rs":"f75e6eb90c38c35292ee3664f8e0c65723703cf36cb04ebb88ac509006ac872a","src/sgx.rs":"16a95cdefc81c5ee00d8353a60db363c4cc3e0f75abcd5d0144723f2a306ed1b","src/switch.rs":"9da3dd39b3de45a7928789926e8572d00e1e11a39e6f7289a1349aadce90edba","src/unix/align.rs":"2cdc7c826ef7ae61f5171c5ae8c445a743d86f1a7f2d9d7e4ceeec56d6874f65","src/unix/bsd/apple/b32/align.rs":"ec833a747866fe19ca2d9b4d3c9ff0385faba5edf4bd0d15fa68884c40b0e26c","src/unix/bsd/apple/b32/mod.rs":"6a4ce300da0d2b0db04b18548286603ffe4b47d679a41cf60f1902895894aa1f","src/unix/bsd/apple/b64/align.rs":"ec833a747866fe19ca2d9b4d3c9ff0385faba5edf4bd0d15fa68884c40b0e26c","src/unix/bsd/apple/b64/mod.rs":"76e172191d70e7ea7ca194aaa2d002e50db5724bf24526c3be5028cfd2085897","src/unix/bsd/apple/mod.rs":"665972cfeb4a71da514c86718e3075d15d13d181be45d4ec5de2b45c1ab73f0c","src/unix/bsd/freebsdlike/dragonfly/errno.rs":"ae5e8e6b0f610ec015dfcc2928609037d7ea7b94570c72bcc5bdd588424c6259","src/unix/bsd/freebsdlike/dragonfly/mod.rs":"dbf5e940cae86f38e103134746c5b865342f04fb3009afbc88fb06dbeb41340e","src/unix/bsd/freebsdlike/freebsd/aarch64.rs":"e528191e42977fa4c226d8850c47d3e526e951cca46ea9a4a87af40221f79d63","src/unix/bsd/freebsdlike/freebsd/arm.rs":"10fe01bc6269b47da72d1e9f8bdae2fcc7d4f332540e8ce1756e1f58d506bf8c","src/unix/bsd/freebsdlike/freebsd/freebsd11/mod.rs":"3d96c3bbd507688099ace8650ea2934cd7d85650d2e3a0981c6f916597edd09d","src/unix/bsd/freebsdlike/freebsd/freebsd11/x86_64.rs":"9808d152c1196aa647f1b0f0cf84dac8c930da7d7f897a44975545e3d9d17681","src/unix/bsd/freebsdlike/freebsd/freebsd12/mod.rs":"ceb4d5bd386f13bbf11499e12b5d4c377bd78ecca06fd65b0d08a6b25fba5ca4","src/unix/bsd/freebsdlike/freebsd/freebsd12/x86_64.rs":"61cbe45f8499bedb168106b686d4f8239472f25c7553b069eec2afe197ff2df6","src/unix/bsd/freebsdlike/freebsd/mod.rs":"82f01098b820ef0f0450ddadfd2c3009182a4c2427df0150900fad0f2e96429b","src/unix/bsd/freebsdlike/freebsd/powerpc64.rs":"125457305b14309cbad4c46fd2fbd54e2f96d37adfec6c89ae9ed8cedfa015bc","src/unix/bsd/freebsdlike/freebsd/x86.rs":"4e0813f01a017dc148262d7c40dfadb964eb7eb6138dc2b0b83d0b51dbe4d467","src/unix/bsd/freebsdlike/freebsd/x86_64/align.rs":"7169d07a9fd4716f7512719aec9fda5d8bed306dc0720ffc1b21696c9951e3c6","src/unix/bsd/freebsdlike/freebsd/x86_64/mod.rs":"fcf38f59ac1e8f90d5a26c6a434b6874972955404cb8cc33c17b1a583e3b3014","src/unix/bsd/freebsdlike/mod.rs":"2e0f5a0f768748a48caf05552956158c066db64ef59b935439f3a9e51ed1b93c","src/unix/bsd/mod.rs":"d8cf315174e6d97d87b44253fc4e4ef2570a495df8eec71f7571359c756ad039","src/unix/bsd/netbsdlike/mod.rs":"100b5fac3769b32be3cc7ea686cfd2a85fb2a55f154781a7ce44d65b163e0959","src/unix/bsd/netbsdlike/netbsd/aarch64.rs":"b38fc046f9a40fea28bd26328b96629f4d5d63d7524936bd6af1865d401a8716","src/unix/bsd/netbsdlike/netbsd/arm.rs":"58cdbb70b0d6f536551f0f3bb3725d2d75c4690db12c26c034e7d6ec4a924452","src/unix/bsd/netbsdlike/netbsd/mod.rs":"a50f20e60eb24e13c10425876771d3d6537c755fca558980e4ad45eab70d23f9","src/unix/bsd/netbsdlike/netbsd/powerpc.rs":"ee7ff5d89d0ed22f531237b5059aa669df93a3b5c489fa641465ace8d405bf41","src/unix/bsd/netbsdlike/netbsd/sparc64.rs":"9489f4b3e4566f43bb12dfb92238960613dac7f6a45cc13068a8d152b902d7d9","src/unix/bsd/netbsdlike/netbsd/x86.rs":"20692320e36bfe028d1a34d16fe12ca77aa909cb02bda167376f98f1a09aefe7","src/unix/bsd/netbsdlike/netbsd/x86_64.rs":"135509edeaf3fb3f102d89d51ff1a8f82323497336a8dc7e1f0f23b5c2434b73","src/unix/bsd/netbsdlike/openbsd/aarch64.rs":"1dd5449dd1fd3d51e30ffdeeaece91d0aaf05c710e0ac699fecc5461cfa2c28e","src/unix/bsd/netbsdlike/openbsd/mod.rs":"9b90e73d4f6139436dd93e76ce584c48698c97d892ea7ff57b8b3aad354609d3","src/unix/bsd/netbsdlike/openbsd/sparc64.rs":"d04fd287afbaa2c5df9d48c94e8374a532a3ba491b424ddf018270c7312f4085","src/unix/bsd/netbsdlike/openbsd/x86.rs":"6f7f5c4fde2a2259eb547890cbd86570cea04ef85347d7569e94e679448bec87","src/unix/bsd/netbsdlike/openbsd/x86_64.rs":"e59b7fd65f68f8e857eec39e0c03bac1d3af6ddc26c9ba58494336b83659bb9b","src/unix/haiku/b32.rs":"69ae47fc52c6880e85416b4744500d5655c9ec6131cb737f3b649fceaadce15a","src/unix/haiku/b64.rs":"73e64db09275a8da8d50a13cce2cfa2b136036ddf3a930d2939f337fc995900b","src/unix/haiku/mod.rs":"acd18f665908abcddc7e0a217708238d602f3ca827a3a46cd3bd8c7cd8a8d8b5","src/unix/hermit/aarch64.rs":"86048676e335944c37a63d0083d0f368ae10ceccefeed9debb3bbe08777fc682","src/unix/hermit/mod.rs":"878e02b4b3ceafdfce3746efadb621ec1baacfe93e385556c6e505bae5c3eaaf","src/unix/hermit/x86_64.rs":"ab832b7524e5fb15c49ff7431165ab1a37dc4667ae0b58e8306f4c539bfa110c","src/unix/linux_like/android/b32/arm.rs":"3625a32c7e58cfe683a53486fbe3d42d4e28f00bea31e19cb46ed2bb0b6a140b","src/unix/linux_like/android/b32/mod.rs":"c997e59bc7a5abe0f37dd87fcc206651dcb2c9837c3f4c2437f9d7944a30717c","src/unix/linux_like/android/b32/x86/align.rs":"812914e4241df82e32b12375ca3374615dc3a4bdd4cf31f0423c5815320c0dab","src/unix/linux_like/android/b32/x86/mod.rs":"edc810399ce9db38c1042c653f05d7f3571f711fa2c16917e8b543df01f065a5","src/unix/linux_like/android/b64/aarch64/align.rs":"0bf138f84e5327d8339bcd4adf071a6832b516445e597552c82bbd881095e3a8","src/unix/linux_like/android/b64/aarch64/mod.rs":"d832328045ed4d65e06ecd072cbe32336a5023664ad85e3961cb1bde8e9d69ba","src/unix/linux_like/android/b64/mod.rs":"2577fa47de16e819569b4d02aeb5f30e8367d85b169fdcc1789f0b404ad6b957","src/unix/linux_like/android/b64/x86_64/align.rs":"7169d07a9fd4716f7512719aec9fda5d8bed306dc0720ffc1b21696c9951e3c6","src/unix/linux_like/android/b64/x86_64/mod.rs":"c6eff774c053f7c8e7a895906ad23e7f835e7349260b40f0ee1689e4d1139ec8","src/unix/linux_like/android/mod.rs":"36866cd3766d899e7557b80f6049af632f7fe7cdcbd62d9edf267b0234acd584","src/unix/linux_like/emscripten/align.rs":"3f40c9cd6ba8b49b4129b53ae43ae8590dfdf21ecc7d20c306d35faf1b470872","src/unix/linux_like/emscripten/mod.rs":"62037212af196240b6469d5cd41ddc81b18d379e346e78e77d6e467f4a4ca47e","src/unix/linux_like/emscripten/no_align.rs":"0128e4aa721a9902754828b61b5ec7d8a86619983ed1e0544a85d35b1051fad6","src/unix/linux_like/linux/align.rs":"15957efd9b772280eb28447849f3aad38fff0c5d65a02566a7ebfba2e7107437","src/unix/linux_like/linux/gnu/align.rs":"e4a3c27fe20a57b8d612c34cb05bc70646edb5cec7251957315afa53a7b9f936","src/unix/linux_like/linux/gnu/b32/arm/align.rs":"3fed009dc9af3cc81be7087da9d2d7d1f39845e4497e290259c5cdbae25f039d","src/unix/linux_like/linux/gnu/b32/arm/mod.rs":"48bea857c59cd3f45c78fb737e048c37174d58d06d20b21c91928f373510ba19","src/unix/linux_like/linux/gnu/b32/mips/align.rs":"429fb5e005cb7143602d430098b6ebfb7d360685b194f333dfd587472ae954ee","src/unix/linux_like/linux/gnu/b32/mips/mod.rs":"e2d2e51fea73210d9705b7eaa37de8baa7152b71ae3a10a316c277345c529b5c","src/unix/linux_like/linux/gnu/b32/mod.rs":"c65adabb73b2b145a9311e0c2abd4075bf1b763b7bea5b26fbd938199e462f37","src/unix/linux_like/linux/gnu/b32/powerpc.rs":"ba9f549679f66ba15e007a5ded4fe9d10d2e9283a5ce95e6bdfb110089bf15f6","src/unix/linux_like/linux/gnu/b32/sparc/align.rs":"21adbed27df73e2d1ed934aaf733a643003d7baf2bde9c48ea440895bcca6d41","src/unix/linux_like/linux/gnu/b32/sparc/mod.rs":"690357fa2a9a9bf895c59d44d73842e7ee2e5de4decb803b61ec1c9491f32fc0","src/unix/linux_like/linux/gnu/b32/x86/align.rs":"e4bafdc4a519a7922a81b37a62bbfd1177a2f620890eef8f1fbc47162e9eb413","src/unix/linux_like/linux/gnu/b32/x86/mod.rs":"403dc6de6fb22d1eefdbe5e3e4977fd972c15335c3d9d5a394f17c5c1b35a205","src/unix/linux_like/linux/gnu/b64/aarch64/align.rs":"0bf138f84e5327d8339bcd4adf071a6832b516445e597552c82bbd881095e3a8","src/unix/linux_like/linux/gnu/b64/aarch64/mod.rs":"72779fa53260d2e72d01a8cf387da0948cd93072b8b31937d51d3b6c25a44f03","src/unix/linux_like/linux/gnu/b64/mips64/align.rs":"7169d07a9fd4716f7512719aec9fda5d8bed306dc0720ffc1b21696c9951e3c6","src/unix/linux_like/linux/gnu/b64/mips64/mod.rs":"44261e37fd6b3ff5cb091a5c973faa75b157bac91a9eac9d9cb78bf34f6c2a2f","src/unix/linux_like/linux/gnu/b64/mod.rs":"b90d87f76bff37707a1725551fe45d70d0c106e01b1dbbcd5f60460e0a19b4c3","src/unix/linux_like/linux/gnu/b64/powerpc64/align.rs":"e29c4868bbecfa4a6cd8a2ad06193f3bbc78a468cc1dc9df83f002f1268130d9","src/unix/linux_like/linux/gnu/b64/powerpc64/mod.rs":"fc4d6613805fdedfff9455d736819a146f5403354a26c902b8c82003b2452629","src/unix/linux_like/linux/gnu/b64/riscv64/mod.rs":"4a5dada65294246696b8114accb38d003e66b1b1c165a49abb41073bab504d82","src/unix/linux_like/linux/gnu/b64/s390x.rs":"f796526968527985a0bbb89eb4f7347a193eb515932504aa32712ca2f07fa4a1","src/unix/linux_like/linux/gnu/b64/sparc64/align.rs":"e29c4868bbecfa4a6cd8a2ad06193f3bbc78a468cc1dc9df83f002f1268130d9","src/unix/linux_like/linux/gnu/b64/sparc64/mod.rs":"239dd7dfa45c078adc0d188dca8e54a9cef1814f1c331bed4eacb87fd7578615","src/unix/linux_like/linux/gnu/b64/x86_64/align.rs":"7169d07a9fd4716f7512719aec9fda5d8bed306dc0720ffc1b21696c9951e3c6","src/unix/linux_like/linux/gnu/b64/x86_64/mod.rs":"33d9c3c191591d50df619c1bd8913ba06559cf924023d626fdc71c4ba893c299","src/unix/linux_like/linux/gnu/b64/x86_64/not_x32.rs":"c1862036556262f076eda2008470b8a351b9c371d70664f54387c46890e8cd18","src/unix/linux_like/linux/gnu/b64/x86_64/x32.rs":"30f88d0fa9e7807ee4cbe89fd274061f810099567d5e68fa829277d7d27ba708","src/unix/linux_like/linux/gnu/mod.rs":"220fcb634cf7653344e4202d131bd86477c5d357b30b28ae85f5663e7ab32896","src/unix/linux_like/linux/gnu/no_align.rs":"9cd223135de75315840ff9c3fd5441ba1cb632b96b5c85a76f8316c86653db25","src/unix/linux_like/linux/mod.rs":"e3b0b9d48b0290283a9f45bffbcfdfc4221c6541eee7893d84dc429b60c41b36","src/unix/linux_like/linux/musl/b32/arm/align.rs":"3e8ac052c1043764776b54c93ba4260e061df998631737a897d9d47d54f7b80c","src/unix/linux_like/linux/musl/b32/arm/mod.rs":"2a57708c5c2976896697ea497be32e0d03573fe44e940df8ddcd4cb06350212c","src/unix/linux_like/linux/musl/b32/hexagon.rs":"e945250ac42713836cae8e4820fc395d374535fce332dbd3ef68109c392290a0","src/unix/linux_like/linux/musl/b32/mips/align.rs":"429fb5e005cb7143602d430098b6ebfb7d360685b194f333dfd587472ae954ee","src/unix/linux_like/linux/musl/b32/mips/mod.rs":"eb65de7aeefed797129c9521785eaa99cdac0644efd826fc6efbab5afc760bf2","src/unix/linux_like/linux/musl/b32/mod.rs":"011c23053388aaacf9aaa17c92b2a918d0fa054410bb1640e61cc4e6d00b0b75","src/unix/linux_like/linux/musl/b32/powerpc.rs":"e3bb421df570b8b154d89969c5a045573c369c2b043ebd93b1d1d2211684dca5","src/unix/linux_like/linux/musl/b32/x86/align.rs":"08e77fbd7435d7dec2ff56932433bece3f02e47ce810f89004a275a86d39cbe1","src/unix/linux_like/linux/musl/b32/x86/mod.rs":"4698f7c107451e7db247e75ade30095b634cb0bfec9605e273975e75c1907420","src/unix/linux_like/linux/musl/b64/aarch64/align.rs":"0bf138f84e5327d8339bcd4adf071a6832b516445e597552c82bbd881095e3a8","src/unix/linux_like/linux/musl/b64/aarch64/mod.rs":"81c4be3f230a60263b57e1d1766420d620e50d8cca04d5a75f48a2a5fe30622e","src/unix/linux_like/linux/musl/b64/mips64.rs":"e8206d97833a50b980aa36a42b02e6197d903a1db4f4314a53b7289308c28bdd","src/unix/linux_like/linux/musl/b64/mod.rs":"317d1cb47ccc87cb7f8ed677bab799fa6eb1b8fd7fbd57d1896005644e02a010","src/unix/linux_like/linux/musl/b64/powerpc64.rs":"9b3faba7fa4f3a660e744ec7bdb71a759ac7d4d78a51b3374d004d5494f8332a","src/unix/linux_like/linux/musl/b64/x86_64/align.rs":"7169d07a9fd4716f7512719aec9fda5d8bed306dc0720ffc1b21696c9951e3c6","src/unix/linux_like/linux/musl/b64/x86_64/mod.rs":"f317c46a2fe4e91e0aaabcaad9bd7535e9d286f0d41caa77bc1d706e37e6a762","src/unix/linux_like/linux/musl/mod.rs":"786c8b5bd7eaabc072351bf83063a4449c7a6bde563962bde800d3eb5c4f6f0f","src/unix/linux_like/linux/no_align.rs":"b94d6612cb8cb1eea947afc825cf8acaddc7f14835a15d2a6e691765de975fcd","src/unix/linux_like/mod.rs":"2dec8d58e9f7afc9b1f81515b05b6799def02e677cdbc08bea283c83e6cbddc7","src/unix/mod.rs":"a9f4dbf822ff2ed420a0ecddee9f531b528bf97fc7896011e63d191d18039ec2","src/unix/newlib/aarch64/mod.rs":"934754e14de392703fd380e0a443fd19a85a405d6c9310d9f855288dd8e76343","src/unix/newlib/align.rs":"28aaf87fafbc6b312622719d472d8cf65f9e5467d15339df5f73e66d8502b28a","src/unix/newlib/arm/mod.rs":"69756a6ba4b75d8cdeae1843bd6d079c42c94e3e61e6e09f169bd20cebec8b0e","src/unix/newlib/mod.rs":"fc2a6cef4ab8f19f16d5ef5d18e206a5514c5ae39091b8d69c7cc1229a3c1f7f","src/unix/newlib/no_align.rs":"7123dcec13604a11b7765c380ff3a4d0da19c39f4b03919de7857723c0cf1502","src/unix/no_align.rs":"c06e95373b9088266e0b14bba0954eef95f93fb2b01d951855e382d22de78e53","src/unix/redox/mod.rs":"4ae29abc41e72723171d434a034374b499dfb6b6fd32e910e7ade88dfecc7601","src/unix/solarish/compat.rs":"cf4ee4cf0d7d45b253b01d1cf823d7f007e3e71aeb5cd8ffe77ef3d722255e68","src/unix/solarish/mod.rs":"cd266cee38f25fe9ed896ba88ddd3530eca352c4d260671fb63d315890bc49e6","src/unix/uclibc/align.rs":"a8540e1cce5913a45bc8d7422b79e86c0b12740e8a679478e0e4d863a31f8cc1","src/unix/uclibc/arm/align.rs":"e4a3c27fe20a57b8d612c34cb05bc70646edb5cec7251957315afa53a7b9f936","src/unix/uclibc/arm/mod.rs":"d67dd46bc6f417169fc6a23832bde7ccdafc5d1bcb08b10debdd82edaf75d529","src/unix/uclibc/arm/no_align.rs":"9cd223135de75315840ff9c3fd5441ba1cb632b96b5c85a76f8316c86653db25","src/unix/uclibc/mips/mips32/align.rs":"e4a3c27fe20a57b8d612c34cb05bc70646edb5cec7251957315afa53a7b9f936","src/unix/uclibc/mips/mips32/mod.rs":"a045ebc6619f540adf670b88a987abd2d6e42e440a552e8cfe9f8c77f397e873","src/unix/uclibc/mips/mips32/no_align.rs":"9cd223135de75315840ff9c3fd5441ba1cb632b96b5c85a76f8316c86653db25","src/unix/uclibc/mips/mips64/align.rs":"a7bdcb18a37a2d91e64d5fad83ea3edc78f5412adb28f77ab077dbb26dd08b2d","src/unix/uclibc/mips/mips64/mod.rs":"e3085ba56cfbc528d7c3c55065880603238c333b6047ef51c58177508a487fcd","src/unix/uclibc/mips/mips64/no_align.rs":"4a18e3875698c85229599225ac3401a2a40da87e77b2ad4ef47c6fcd5a24ed30","src/unix/uclibc/mips/mod.rs":"1054d0bfeb506b3346b9a4148564beced8a22da0d9c9a612101f6237756795fb","src/unix/uclibc/mod.rs":"4c20de4d16a0a3efd67a9fd742f5146b77cfb7c24a18fac8728085ad5f52618e","src/unix/uclibc/no_align.rs":"3f28637046524618adaa1012e26cb7ffe94b9396e6b518cccdc69d59f274d709","src/unix/uclibc/x86_64/align.rs":"c44ee7782b74733bee5659dfd7eb32d5901c17c99cb540b1a08291859f6238c6","src/unix/uclibc/x86_64/l4re.rs":"bb31053d6403091e11f95ac2203982f279f8b984a19adf30796878c45fdd8c25","src/unix/uclibc/x86_64/mod.rs":"df78de7e0234192c0559b9820c0034a24d72a0820d361f9aad05a9eac36e80ff","src/unix/uclibc/x86_64/no_align.rs":"b308f7b110caf7405b57186882cfc4804caae49a8287f8ab612ec8548467f2f4","src/unix/uclibc/x86_64/other.rs":"42c3f71e58cabba373f6a55a623f3c31b85049eb64824c09c2b082b3b2d6a0a8","src/vxworks/aarch64.rs":"98f0afdc511cd02557e506c21fed6737585490a1dce7a9d4941d08c437762b99","src/vxworks/arm.rs":"acb7968ce99fe3f4abdf39d98f8133d21a4fba435b8ef7084777cb181d788e88","src/vxworks/mod.rs":"b62f34937aa6943a7348ec69cb338fa04cddba200f108f2a5a61e4b0a6fae252","src/vxworks/powerpc.rs":"acb7968ce99fe3f4abdf39d98f8133d21a4fba435b8ef7084777cb181d788e88","src/vxworks/powerpc64.rs":"98f0afdc511cd02557e506c21fed6737585490a1dce7a9d4941d08c437762b99","src/vxworks/x86.rs":"552f007f38317620b23889cb7c49d1d115841252439060122f52f434fbc6e5ba","src/vxworks/x86_64.rs":"018d92be3ad628a129eff9f2f5dfbc0883d8b8e5f2fa917b900a7f98ed6b514a","src/wasi.rs":"f1995eee58f872de81197983b5683fe83dc396e16344db0fe52b3d63d061a5e4","src/windows/gnu/align.rs":"b2c13ec1b9f3b39a75c452c80c951dff9d0215e31d77e883b4502afb31794647","src/windows/gnu/mod.rs":"dc8e2f8d32280394d2bc386f804ce1c71f751590cfeed7db9220e231acc766e3","src/windows/mod.rs":"591ab70bf20a8871b33f27c1975acc7304cb11018d84355002dc6463c5a91cbf","src/windows/msvc.rs":"2c2bfce66027d88021e7289139ebf5b0db258a7b6443f18872c84dbd4ef57131","tests/const_fn.rs":"cb75a1f0864f926aebe79118fc34d51a0d1ade2c20a394e7774c7e545f21f1f4"},"package":"d515b1f41455adea1313a4a2ac8a8a477634fbae63cc6100e3aebb207ce61558"}
0 {"files":{"CONTRIBUTING.md":"cc340197d05fd8f069dfda6347b97d3da92c8f260c75ac78fb6970f08dba7638","Cargo.toml":"9ff1f347e82f3559ad2df0b531f79a701f3769cbb0abb194c64980497afdbc69","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"a8d47ff51ca256f56a8932dba07660672dbfe3004257ca8de708aac1415937a1","README.md":"69f85e8acfa71ff6e1f3807985e04d19eefe88bbd90192e4b42515336eb93b4a","build.rs":"ab351d7171b14f8032948e843841ebe8518ed95eb1abf0b1e689700c7cef4bf5","rustfmt.toml":"8a654d5787585ca8f2c20580737336fc327f411a07b0dbd4870adf6e9bdf624f","src/cloudabi/aarch64.rs":"b8550bf1fd7344972aa4db29441486f39f31482d0327534981dbb75959c29114","src/cloudabi/arm.rs":"c197e2781c2839808bd6fcef219a29705b27b992d3ef920e9cf6ac96e2022bbf","src/cloudabi/mod.rs":"d5d4488e8c0b8227f516fe13810f550a2a72af3bdfe769200ad8687c8755bdf6","src/cloudabi/x86.rs":"33eb97f272d2201f3838ae74d444583c7de8f67856852ca375293b20bbd05636","src/cloudabi/x86_64.rs":"400d85d4fe39e26cf2e6ece9ee31c75fe9e88c4bcf4d836ca9f765c05c9c5be3","src/fixed_width_ints.rs":"34c60f12ec5eeb90f13ec3b954427532111c2446e69617616a97aefc1086a9f1","src/fuchsia/aarch64.rs":"378776a9e40766154a54c94c2a7b4675b5c302a38e6e42da99e67bfbaee60e56","src/fuchsia/align.rs":"ae1cf8f011a99737eabeb14ffff768e60f13b13363d7646744dbb0f443dab3d6","src/fuchsia/mod.rs":"3d669cc3355c42f6581f88af354cd99514f93fda843c2c893619b0bb77df85c5","src/fuchsia/no_align.rs":"303f3f1b255e0088b5715094353cf00476131d8e94e6aebb3f469557771c8b8a","src/fuchsia/x86_64.rs":"93a3632b5cf67d2a6bcb7dc0a558605252d5fe689e0f38d8aa2ec5852255ac87","src/hermit/aarch64.rs":"86048676e335944c37a63d0083d0f368ae10ceccefeed9debb3bbe08777fc682","src/hermit/mod.rs":"d3bfce41e4463d4be8020a2d063c9bfa8b665f45f1cc6cbf3163f5d01e7cb21f","src/hermit/x86_64.rs":"ab832b7524e5fb15c49ff7431165ab1a37dc4667ae0b58e8306f4c539bfa110c","src/lib.rs":"948cd72de09f84e07976e6b0f9bfe16e2ea33ee6c7c56ae82cb0aeef9c5bf6f3","src/macros.rs":"f75e6eb90c38c35292ee3664f8e0c65723703cf36cb04ebb88ac509006ac872a","src/sgx.rs":"16a95cdefc81c5ee00d8353a60db363c4cc3e0f75abcd5d0144723f2a306ed1b","src/switch.rs":"9da3dd39b3de45a7928789926e8572d00e1e11a39e6f7289a1349aadce90edba","src/unix/align.rs":"2cdc7c826ef7ae61f5171c5ae8c445a743d86f1a7f2d9d7e4ceeec56d6874f65","src/unix/bsd/apple/b32/align.rs":"ec833a747866fe19ca2d9b4d3c9ff0385faba5edf4bd0d15fa68884c40b0e26c","src/unix/bsd/apple/b32/mod.rs":"6a4ce300da0d2b0db04b18548286603ffe4b47d679a41cf60f1902895894aa1f","src/unix/bsd/apple/b64/align.rs":"ec833a747866fe19ca2d9b4d3c9ff0385faba5edf4bd0d15fa68884c40b0e26c","src/unix/bsd/apple/b64/mod.rs":"81254d89be1febc5bb20e787d014a624950d56e2e14973df5bbebfdabc95ae20","src/unix/bsd/apple/mod.rs":"e3d93cd2a8f926d75464911893edd06be4035b42be076da39da32c87b5a7d3ff","src/unix/bsd/freebsdlike/dragonfly/errno.rs":"ae5e8e6b0f610ec015dfcc2928609037d7ea7b94570c72bcc5bdd588424c6259","src/unix/bsd/freebsdlike/dragonfly/mod.rs":"1f6b04504ae77ce84b461910979ea640176e051bf2616c01d37cf9fc94c6fc17","src/unix/bsd/freebsdlike/freebsd/aarch64.rs":"e528191e42977fa4c226d8850c47d3e526e951cca46ea9a4a87af40221f79d63","src/unix/bsd/freebsdlike/freebsd/arm.rs":"10fe01bc6269b47da72d1e9f8bdae2fcc7d4f332540e8ce1756e1f58d506bf8c","src/unix/bsd/freebsdlike/freebsd/freebsd11/mod.rs":"3d96c3bbd507688099ace8650ea2934cd7d85650d2e3a0981c6f916597edd09d","src/unix/bsd/freebsdlike/freebsd/freebsd11/x86_64.rs":"9808d152c1196aa647f1b0f0cf84dac8c930da7d7f897a44975545e3d9d17681","src/unix/bsd/freebsdlike/freebsd/freebsd12/mod.rs":"ceb4d5bd386f13bbf11499e12b5d4c377bd78ecca06fd65b0d08a6b25fba5ca4","src/unix/bsd/freebsdlike/freebsd/freebsd12/x86_64.rs":"61cbe45f8499bedb168106b686d4f8239472f25c7553b069eec2afe197ff2df6","src/unix/bsd/freebsdlike/freebsd/mod.rs":"e915c297192ddc82f439d659c6be20047fdf6b62d435f5aad383e1b3d4540a68","src/unix/bsd/freebsdlike/freebsd/powerpc64.rs":"125457305b14309cbad4c46fd2fbd54e2f96d37adfec6c89ae9ed8cedfa015bc","src/unix/bsd/freebsdlike/freebsd/x86.rs":"4e0813f01a017dc148262d7c40dfadb964eb7eb6138dc2b0b83d0b51dbe4d467","src/unix/bsd/freebsdlike/freebsd/x86_64/align.rs":"7169d07a9fd4716f7512719aec9fda5d8bed306dc0720ffc1b21696c9951e3c6","src/unix/bsd/freebsdlike/freebsd/x86_64/mod.rs":"fcf38f59ac1e8f90d5a26c6a434b6874972955404cb8cc33c17b1a583e3b3014","src/unix/bsd/freebsdlike/mod.rs":"792d9f12c06e1ab8af0b0a653c0120ad7b030b354e06e1558bacf85b2f11bf15","src/unix/bsd/mod.rs":"d2a7832495d72837c3f1032e4c5514c343526bcdfedc16edad3659d42bbb4310","src/unix/bsd/netbsdlike/mod.rs":"b5b027a2d6bbec9e679ad2f802855383fc180e587352a24f33264c9a07205324","src/unix/bsd/netbsdlike/netbsd/aarch64.rs":"b38fc046f9a40fea28bd26328b96629f4d5d63d7524936bd6af1865d401a8716","src/unix/bsd/netbsdlike/netbsd/arm.rs":"58cdbb70b0d6f536551f0f3bb3725d2d75c4690db12c26c034e7d6ec4a924452","src/unix/bsd/netbsdlike/netbsd/mod.rs":"53bbafec7c565e5fd3cbf1f20f88f591161aaad500698942ad2c70551eca66c0","src/unix/bsd/netbsdlike/netbsd/powerpc.rs":"ee7ff5d89d0ed22f531237b5059aa669df93a3b5c489fa641465ace8d405bf41","src/unix/bsd/netbsdlike/netbsd/sparc64.rs":"9489f4b3e4566f43bb12dfb92238960613dac7f6a45cc13068a8d152b902d7d9","src/unix/bsd/netbsdlike/netbsd/x86.rs":"20692320e36bfe028d1a34d16fe12ca77aa909cb02bda167376f98f1a09aefe7","src/unix/bsd/netbsdlike/netbsd/x86_64.rs":"135509edeaf3fb3f102d89d51ff1a8f82323497336a8dc7e1f0f23b5c2434b73","src/unix/bsd/netbsdlike/openbsd/aarch64.rs":"1dd5449dd1fd3d51e30ffdeeaece91d0aaf05c710e0ac699fecc5461cfa2c28e","src/unix/bsd/netbsdlike/openbsd/mod.rs":"19a34ee831e0ba712d9aee082f3879ecc317ca22f2094ea3b31bd3ede7a85e5f","src/unix/bsd/netbsdlike/openbsd/sparc64.rs":"d04fd287afbaa2c5df9d48c94e8374a532a3ba491b424ddf018270c7312f4085","src/unix/bsd/netbsdlike/openbsd/x86.rs":"6f7f5c4fde2a2259eb547890cbd86570cea04ef85347d7569e94e679448bec87","src/unix/bsd/netbsdlike/openbsd/x86_64.rs":"e59b7fd65f68f8e857eec39e0c03bac1d3af6ddc26c9ba58494336b83659bb9b","src/unix/haiku/b32.rs":"69ae47fc52c6880e85416b4744500d5655c9ec6131cb737f3b649fceaadce15a","src/unix/haiku/b64.rs":"73e64db09275a8da8d50a13cce2cfa2b136036ddf3a930d2939f337fc995900b","src/unix/haiku/mod.rs":"9deb172b4b2a6583e194023b23821e329246cc283d00bfb54f0c5d3e2fa46754","src/unix/hermit/aarch64.rs":"86048676e335944c37a63d0083d0f368ae10ceccefeed9debb3bbe08777fc682","src/unix/hermit/mod.rs":"2d594ccba381d7c49e934c646d2e164169603151aca3cdb1099213b25e4170fd","src/unix/hermit/x86_64.rs":"ab832b7524e5fb15c49ff7431165ab1a37dc4667ae0b58e8306f4c539bfa110c","src/unix/linux_like/android/b32/arm.rs":"155994121906903a2e0afad895f0b3b7546f6e54d6305a3336ce2c4dfafbfdfa","src/unix/linux_like/android/b32/mod.rs":"0325adf3364fed7157fff5b24fabe1b36d806c39ee04ec82dd29a606d28f91f6","src/unix/linux_like/android/b32/x86/align.rs":"812914e4241df82e32b12375ca3374615dc3a4bdd4cf31f0423c5815320c0dab","src/unix/linux_like/android/b32/x86/mod.rs":"5b1e9fcd77ca5f939acb7fb5f5da12f305b0377698d8b8989feb236e26360aa0","src/unix/linux_like/android/b64/aarch64/align.rs":"0bf138f84e5327d8339bcd4adf071a6832b516445e597552c82bbd881095e3a8","src/unix/linux_like/android/b64/aarch64/mod.rs":"d832328045ed4d65e06ecd072cbe32336a5023664ad85e3961cb1bde8e9d69ba","src/unix/linux_like/android/b64/mod.rs":"6a71abfcbbcdae60c916de41cd4688d5f25bdbca83d1d9df49decd56ad726a06","src/unix/linux_like/android/b64/x86_64/align.rs":"7169d07a9fd4716f7512719aec9fda5d8bed306dc0720ffc1b21696c9951e3c6","src/unix/linux_like/android/b64/x86_64/mod.rs":"e84176d838e663d351450bad218715db1fafbb531e47ea0e262cbb45829dae89","src/unix/linux_like/android/mod.rs":"6cf285a7e7c2ec2901f476a747edeb16d75f05db7d406ea94b36a966cd773e1b","src/unix/linux_like/emscripten/align.rs":"86c95cbed7a7161b1f23ee06843e7b0e2340ad92b2cb86fe2a8ef3e0e8c36216","src/unix/linux_like/emscripten/mod.rs":"5e38462076cb4e338150bf5349b7354e91770021bd4b2ee13f62fc1c56797acd","src/unix/linux_like/emscripten/no_align.rs":"0128e4aa721a9902754828b61b5ec7d8a86619983ed1e0544a85d35b1051fad6","src/unix/linux_like/linux/align.rs":"dde648468764a5deef5566b8016290150acf50ee6a0f8c0678cb2078658bc2fa","src/unix/linux_like/linux/gnu/align.rs":"e4a3c27fe20a57b8d612c34cb05bc70646edb5cec7251957315afa53a7b9f936","src/unix/linux_like/linux/gnu/b32/arm/align.rs":"3fed009dc9af3cc81be7087da9d2d7d1f39845e4497e290259c5cdbae25f039d","src/unix/linux_like/linux/gnu/b32/arm/mod.rs":"6d9ba242111c7be8173b7a7b8cf8c863ba23d839edc9d026c0fd37a4b64460b4","src/unix/linux_like/linux/gnu/b32/mips/align.rs":"429fb5e005cb7143602d430098b6ebfb7d360685b194f333dfd587472ae954ee","src/unix/linux_like/linux/gnu/b32/mips/mod.rs":"e2d2e51fea73210d9705b7eaa37de8baa7152b71ae3a10a316c277345c529b5c","src/unix/linux_like/linux/gnu/b32/mod.rs":"f2496ac78c0e77012ed6ad7ca5d9a9de5938241a2483772dd6ebfe00d626304e","src/unix/linux_like/linux/gnu/b32/powerpc.rs":"39aae80d2c4ffa845592e16c0a6c910017de19e2b15c1e507c4df10e79ce3e38","src/unix/linux_like/linux/gnu/b32/sparc/align.rs":"21adbed27df73e2d1ed934aaf733a643003d7baf2bde9c48ea440895bcca6d41","src/unix/linux_like/linux/gnu/b32/sparc/mod.rs":"3b4dd40b288788740d2b030171b21f9d0b076ce26d88e0ff62f5d87f09e7c787","src/unix/linux_like/linux/gnu/b32/x86/align.rs":"e4bafdc4a519a7922a81b37a62bbfd1177a2f620890eef8f1fbc47162e9eb413","src/unix/linux_like/linux/gnu/b32/x86/mod.rs":"95181685042e4a5c59906c71bcc241ef60888f43c3934f8b334852cfaeb4023a","src/unix/linux_like/linux/gnu/b64/aarch64/align.rs":"2179c3b1608fa4bf68840482bfc2b2fa3ee2faf6fcae3770f9e505cddca35c7b","src/unix/linux_like/linux/gnu/b64/aarch64/mod.rs":"b9c242d2c17eb0fa45dab9922e380d1a05ac340aab7e020aec904d12ee95c439","src/unix/linux_like/linux/gnu/b64/mips64/align.rs":"7169d07a9fd4716f7512719aec9fda5d8bed306dc0720ffc1b21696c9951e3c6","src/unix/linux_like/linux/gnu/b64/mips64/mod.rs":"2fc9fe21d67759f605e19eae0ee43b17152f2657df46b9d3b06ddacef017046a","src/unix/linux_like/linux/gnu/b64/mod.rs":"b90d87f76bff37707a1725551fe45d70d0c106e01b1dbbcd5f60460e0a19b4c3","src/unix/linux_like/linux/gnu/b64/powerpc64/align.rs":"e29c4868bbecfa4a6cd8a2ad06193f3bbc78a468cc1dc9df83f002f1268130d9","src/unix/linux_like/linux/gnu/b64/powerpc64/mod.rs":"d067111c001807765c849542b0fa0df1ead07ec47bf7eb50b80eb9357273f154","src/unix/linux_like/linux/gnu/b64/riscv64/mod.rs":"432d1f7e12f245e790ebe85066423b0af26f4e090c8309fa6de5aebff90a7e87","src/unix/linux_like/linux/gnu/b64/s390x.rs":"c007d3238d70a006d1b20978e9e80f8408325167c338b451dc4d0c7b724b3e19","src/unix/linux_like/linux/gnu/b64/sparc64/align.rs":"e29c4868bbecfa4a6cd8a2ad06193f3bbc78a468cc1dc9df83f002f1268130d9","src/unix/linux_like/linux/gnu/b64/sparc64/mod.rs":"cdc4873f4ee7666975177a459a3de6e9fd6a42bdffbb878a78fbc4ee63d49703","src/unix/linux_like/linux/gnu/b64/x86_64/align.rs":"7169d07a9fd4716f7512719aec9fda5d8bed306dc0720ffc1b21696c9951e3c6","src/unix/linux_like/linux/gnu/b64/x86_64/mod.rs":"8d6842b039d0b39d1cc3fe2e26d03a608592c6b3107a0966138b6ee322bd560c","src/unix/linux_like/linux/gnu/b64/x86_64/not_x32.rs":"c1862036556262f076eda2008470b8a351b9c371d70664f54387c46890e8cd18","src/unix/linux_like/linux/gnu/b64/x86_64/x32.rs":"30f88d0fa9e7807ee4cbe89fd274061f810099567d5e68fa829277d7d27ba708","src/unix/linux_like/linux/gnu/mod.rs":"b6f4336133100c083731feb764501779c73c8f75500cc7217e3bea69754390ff","src/unix/linux_like/linux/gnu/no_align.rs":"9cd223135de75315840ff9c3fd5441ba1cb632b96b5c85a76f8316c86653db25","src/unix/linux_like/linux/mod.rs":"b59c947b2525a842c9174f6ca3945ac7b7d9235fd80874afa0d03635ed3b75fa","src/unix/linux_like/linux/musl/b32/arm/align.rs":"3e8ac052c1043764776b54c93ba4260e061df998631737a897d9d47d54f7b80c","src/unix/linux_like/linux/musl/b32/arm/mod.rs":"45062a178b382ab17341a69d027b5c83325c4e79fecf45729ba9c47b1bcdc3da","src/unix/linux_like/linux/musl/b32/hexagon.rs":"0102bdb9f5b7c049e43da9a6b4d1d7313c9a569b7394bed1e354557569a8d6a9","src/unix/linux_like/linux/musl/b32/mips/align.rs":"429fb5e005cb7143602d430098b6ebfb7d360685b194f333dfd587472ae954ee","src/unix/linux_like/linux/musl/b32/mips/mod.rs":"9eb0e4953be5afaa0b9e3ac54c85ed40583cfb8cc0b03264b9bc8f763a8f3254","src/unix/linux_like/linux/musl/b32/mod.rs":"8ede3985e6243882814ce91e8ce543e7edbafc0cee5932816072b6f14207a671","src/unix/linux_like/linux/musl/b32/powerpc.rs":"cf286cbf4d2076aaa82662ace2b5c333480410fa59af5cb4542d59f04da84b31","src/unix/linux_like/linux/musl/b32/x86/align.rs":"08e77fbd7435d7dec2ff56932433bece3f02e47ce810f89004a275a86d39cbe1","src/unix/linux_like/linux/musl/b32/x86/mod.rs":"9c3b6e98e7710d6c877a4e31726d36416115a58f53fc469bb173b7fe660b39e5","src/unix/linux_like/linux/musl/b64/aarch64/align.rs":"0bf138f84e5327d8339bcd4adf071a6832b516445e597552c82bbd881095e3a8","src/unix/linux_like/linux/musl/b64/aarch64/mod.rs":"7b3fb85a869e00aae3f6af9c36f82f9c70bf8c2b9cccbd931b923602846ea42c","src/unix/linux_like/linux/musl/b64/mips64.rs":"9d0158ac7a913222d0a62239ec043aa1aee73522a7a1e0e191d0642dde35c083","src/unix/linux_like/linux/musl/b64/mod.rs":"8b76e92a1505ad785d4aa0b7739e0b93647a1e81910949b49cedb6c88468be9c","src/unix/linux_like/linux/musl/b64/powerpc64.rs":"ed9b879bb9cdc526ad83815875edeb4cad4e8829086dfba2578277c265336229","src/unix/linux_like/linux/musl/b64/x86_64/align.rs":"7169d07a9fd4716f7512719aec9fda5d8bed306dc0720ffc1b21696c9951e3c6","src/unix/linux_like/linux/musl/b64/x86_64/mod.rs":"cfeb109c732ac6bc7d2be44069d3652e917a0509b8b545270b756ff2d52e27e8","src/unix/linux_like/linux/musl/mod.rs":"ae800408b895f70f0c9b601081b0c0be2fc5dd98c29c2f5422ab2755a96abd7d","src/unix/linux_like/linux/no_align.rs":"c81ccd1942295d423b43a55b4aa19633c2096fb93bb381a6a29acb93e85aab07","src/unix/linux_like/mod.rs":"8165f05ab3c802672bc39ad06ce7d54e760c738af7bed9316dfadc0bb5136e5b","src/unix/mod.rs":"281eb0dfca1bbb7606315904fe27b11dea6550d4a41b2467431531da8f8fba89","src/unix/newlib/aarch64/mod.rs":"934754e14de392703fd380e0a443fd19a85a405d6c9310d9f855288dd8e76343","src/unix/newlib/align.rs":"28aaf87fafbc6b312622719d472d8cf65f9e5467d15339df5f73e66d8502b28a","src/unix/newlib/arm/mod.rs":"69756a6ba4b75d8cdeae1843bd6d079c42c94e3e61e6e09f169bd20cebec8b0e","src/unix/newlib/mod.rs":"5a7c4feb405f7306ac550e90dc9c458adcb69e2d9aef7ca14398610ba0f9f73a","src/unix/newlib/no_align.rs":"7123dcec13604a11b7765c380ff3a4d0da19c39f4b03919de7857723c0cf1502","src/unix/no_align.rs":"c06e95373b9088266e0b14bba0954eef95f93fb2b01d951855e382d22de78e53","src/unix/redox/mod.rs":"c7bef60afd0137f01027f2c76cda993378a4f9db46483670337be5661a833da1","src/unix/solarish/compat.rs":"d62a5d3b5bd6adc998cb9bb817a622ef9ec666235bb237bd0f13f8e6a94de576","src/unix/solarish/illumos.rs":"98774e3cc1140e2dafa737488b53c720dd34e5d8681d34faca729dd4e242f1d9","src/unix/solarish/mod.rs":"721e1609f429b472bc05c9284e15d6e73b39bbc5f79fff46690642342ed4c1cb","src/unix/solarish/solaris.rs":"6d2dad7087c477efc64e4723b70bc08ed301ff92bf9bcf896c475af96d32662a","src/unix/uclibc/align.rs":"a8540e1cce5913a45bc8d7422b79e86c0b12740e8a679478e0e4d863a31f8cc1","src/unix/uclibc/arm/align.rs":"e4a3c27fe20a57b8d612c34cb05bc70646edb5cec7251957315afa53a7b9f936","src/unix/uclibc/arm/mod.rs":"d67dd46bc6f417169fc6a23832bde7ccdafc5d1bcb08b10debdd82edaf75d529","src/unix/uclibc/arm/no_align.rs":"9cd223135de75315840ff9c3fd5441ba1cb632b96b5c85a76f8316c86653db25","src/unix/uclibc/mips/mips32/align.rs":"e4a3c27fe20a57b8d612c34cb05bc70646edb5cec7251957315afa53a7b9f936","src/unix/uclibc/mips/mips32/mod.rs":"a045ebc6619f540adf670b88a987abd2d6e42e440a552e8cfe9f8c77f397e873","src/unix/uclibc/mips/mips32/no_align.rs":"9cd223135de75315840ff9c3fd5441ba1cb632b96b5c85a76f8316c86653db25","src/unix/uclibc/mips/mips64/align.rs":"a7bdcb18a37a2d91e64d5fad83ea3edc78f5412adb28f77ab077dbb26dd08b2d","src/unix/uclibc/mips/mips64/mod.rs":"e3085ba56cfbc528d7c3c55065880603238c333b6047ef51c58177508a487fcd","src/unix/uclibc/mips/mips64/no_align.rs":"4a18e3875698c85229599225ac3401a2a40da87e77b2ad4ef47c6fcd5a24ed30","src/unix/uclibc/mips/mod.rs":"1054d0bfeb506b3346b9a4148564beced8a22da0d9c9a612101f6237756795fb","src/unix/uclibc/mod.rs":"f480afbb9fccf71755cbe4f39b553a99a963eafcaab339380a9f3b7c3a588b57","src/unix/uclibc/no_align.rs":"3f28637046524618adaa1012e26cb7ffe94b9396e6b518cccdc69d59f274d709","src/unix/uclibc/x86_64/align.rs":"4e34cebb7955e9c98ae2f310be6f8ed16a861fc3817c08543867554aeec9524e","src/unix/uclibc/x86_64/l4re.rs":"bb31053d6403091e11f95ac2203982f279f8b984a19adf30796878c45fdd8c25","src/unix/uclibc/x86_64/mod.rs":"188fbaf06a8e23cac72718b1ef7eb4bd98bdfd946aa708151f3f7e3553b65876","src/unix/uclibc/x86_64/no_align.rs":"2ccc0107a6007c70dc49e656095b64a352ca5d8f9f3e65c1dba634effbc15636","src/unix/uclibc/x86_64/other.rs":"42c3f71e58cabba373f6a55a623f3c31b85049eb64824c09c2b082b3b2d6a0a8","src/vxworks/aarch64.rs":"98f0afdc511cd02557e506c21fed6737585490a1dce7a9d4941d08c437762b99","src/vxworks/arm.rs":"acb7968ce99fe3f4abdf39d98f8133d21a4fba435b8ef7084777cb181d788e88","src/vxworks/mod.rs":"79077f518d234baf6cb76cb742153d174b3ddd43c6eda9238ebb053e08f9f9c7","src/vxworks/powerpc.rs":"acb7968ce99fe3f4abdf39d98f8133d21a4fba435b8ef7084777cb181d788e88","src/vxworks/powerpc64.rs":"98f0afdc511cd02557e506c21fed6737585490a1dce7a9d4941d08c437762b99","src/vxworks/x86.rs":"552f007f38317620b23889cb7c49d1d115841252439060122f52f434fbc6e5ba","src/vxworks/x86_64.rs":"018d92be3ad628a129eff9f2f5dfbc0883d8b8e5f2fa917b900a7f98ed6b514a","src/wasi.rs":"3948fd2fe7458dfc5163f522da285e4bf4d7c714a6449e8bc89edca6bca54c9a","src/windows/gnu/align.rs":"b2c13ec1b9f3b39a75c452c80c951dff9d0215e31d77e883b4502afb31794647","src/windows/gnu/mod.rs":"c7ab9793baaa3b6854d25fdf44266b7953533009e4fa722ca717b71d3e5d2c9d","src/windows/mod.rs":"35e279d4bcf2f8d76f856f7b11fe7cc030000b0e35f4f1de714b2116cf614187","src/windows/msvc.rs":"2c2bfce66027d88021e7289139ebf5b0db258a7b6443f18872c84dbd4ef57131","tests/const_fn.rs":"cb75a1f0864f926aebe79118fc34d51a0d1ade2c20a394e7774c7e545f21f1f4","triagebot.toml":"a135e10c777cd13459559bdf74fb704c1379af7c9b0f70bc49fa6f5a837daa81"},"package":"99e85c08494b21a9054e7fe1374a732aeadaff3980b6990b94bfd3a70f690005"}
1111
1212 [package]
1313 name = "libc"
14 version = "0.2.66"
14 version = "0.2.69"
1515 authors = ["The Rust Project Developers"]
1616 build = "build.rs"
1717 exclude = ["/ci/*", "/azure-pipelines.yml"]
3535 rustc-dep-of-std = ["align", "rustc-std-workspace-core"]
3636 std = []
3737 use_std = ["std"]
38 [badges.appveyor]
39 project_name = "rust-lang-libs/libc"
38 [badges.azure-devops]
39 pipeline = "rust-lang.libc%20(1)"
40 project = "rust-lang2/libc"
41
42 [badges.cirrus-ci]
43 branch = "master"
4044 repository = "rust-lang/libc"
41
42 [badges.travis-ci]
43 repository = "rust-lang/libc"
0 Copyright (c) 2014 The Rust Project Developers
0 Copyright (c) 2014-2020 The Rust Project Developers
11
22 Permission is hereby granted, free of charge, to any
33 person obtaining a copy of this software and associated
9393 for inclusion in `libc` by you, as defined in the Apache-2.0 license, shall be
9494 dual licensed as above, without any additional terms or conditions.
9595
96 [Azure Status]: https://dev.azure.com/rust-lang2/libc/_apis/build/status/rust-lang.libc?branchName=master
96 [Azure Status]: https://dev.azure.com/rust-lang2/libc/_apis/build/status/rust-lang.libc%20(1)?branchName=master
9797 [Azure]: https://dev.azure.com/rust-lang2/libc/_build/latest?definitionId=1&branchName=master
9898 [Cirrus CI]: https://cirrus-ci.com/github/rust-lang/libc
9999 [Cirrus CI Status]: https://api.cirrus-ci.com/github/rust-lang/libc.svg
119119 }
120120 }
121121 #[cfg_attr(feature = "extra_traits", derive(Debug))]
122 pub enum fpos_t {} // TODO: fill this out with a struct
122 pub enum fpos_t {} // FIXME: fill this out with a struct
123123 impl ::Copy for fpos_t {}
124124 impl ::Clone for fpos_t {
125125 fn clone(&self) -> fpos_t {
258258 ) -> ::size_t;
259259
260260 pub fn memchr(cx: *const c_void, c: c_int, n: size_t) -> *mut c_void;
261 pub fn wmemchr(cx: *const wchar_t, c: wchar_t, n: size_t) -> *mut wchar_t;
261262 pub fn memcmp(cx: *const c_void, ct: *const c_void, n: size_t) -> c_int;
262263 pub fn memcpy(
263264 dest: *mut c_void,
108108 }
109109
110110 #[cfg_attr(feature = "extra_traits", derive(Debug))]
111 pub enum fpos64_t {} // TODO: fill this out with a struct
111 pub enum fpos64_t {} // FIXME: fill this out with a struct
112112 impl ::Copy for fpos64_t {}
113113 impl ::Clone for fpos64_t {
114114 fn clone(&self) -> fpos64_t {
14151415 pub const F_SEAL_GROW: ::c_int = 0x0004;
14161416 pub const F_SEAL_WRITE: ::c_int = 0x0008;
14171417
1418 // TODO(#235): Include file sealing fcntls once we have a way to verify them.
1418 // FIXME(#235): Include file sealing fcntls once we have a way to verify them.
14191419
14201420 pub const SIGTRAP: ::c_int = 5;
14211421
14321432 pub const CLOCK_BOOTTIME: ::clockid_t = 7;
14331433 pub const CLOCK_REALTIME_ALARM: ::clockid_t = 8;
14341434 pub const CLOCK_BOOTTIME_ALARM: ::clockid_t = 9;
1435 // TODO(#247) Someday our Travis shall have glibc 2.21 (released in Sep
1436 // 2014.) See also musl/mod.rs
1437 // pub const CLOCK_SGI_CYCLE: ::clockid_t = 10;
1438 // pub const CLOCK_TAI: ::clockid_t = 11;
1435 pub const CLOCK_SGI_CYCLE: ::clockid_t = 10;
1436 pub const CLOCK_TAI: ::clockid_t = 11;
14391437 pub const TIMER_ABSTIME: ::c_int = 1;
14401438
14411439 pub const RLIMIT_CPU: ::c_int = 0;
15081506 pub const LC_MONETARY: ::c_int = 4;
15091507 pub const LC_MESSAGES: ::c_int = 5;
15101508 pub const LC_ALL: ::c_int = 6;
1511 pub const LC_CTYPE_MASK: ::c_int = (1 << LC_CTYPE);
1512 pub const LC_NUMERIC_MASK: ::c_int = (1 << LC_NUMERIC);
1513 pub const LC_TIME_MASK: ::c_int = (1 << LC_TIME);
1514 pub const LC_COLLATE_MASK: ::c_int = (1 << LC_COLLATE);
1515 pub const LC_MONETARY_MASK: ::c_int = (1 << LC_MONETARY);
1516 pub const LC_MESSAGES_MASK: ::c_int = (1 << LC_MESSAGES);
1509 pub const LC_CTYPE_MASK: ::c_int = 1 << LC_CTYPE;
1510 pub const LC_NUMERIC_MASK: ::c_int = 1 << LC_NUMERIC;
1511 pub const LC_TIME_MASK: ::c_int = 1 << LC_TIME;
1512 pub const LC_COLLATE_MASK: ::c_int = 1 << LC_COLLATE;
1513 pub const LC_MONETARY_MASK: ::c_int = 1 << LC_MONETARY;
1514 pub const LC_MESSAGES_MASK: ::c_int = 1 << LC_MESSAGES;
15171515 // LC_ALL_MASK defined per platform
15181516
15191517 pub const MAP_FILE: ::c_int = 0x0000;
19671965 pub const AT_FDCWD: ::c_int = -100;
19681966 pub const AT_SYMLINK_NOFOLLOW: ::c_int = 0x100;
19691967 pub const AT_REMOVEDIR: ::c_int = 0x200;
1968 pub const AT_EACCESS: ::c_int = 0x200;
19701969 pub const AT_SYMLINK_FOLLOW: ::c_int = 0x400;
19711970 pub const AT_NO_AUTOMOUNT: ::c_int = 0x800;
19721971 pub const AT_EMPTY_PATH: ::c_int = 0x1000;
26902689 pub const O_PATH: ::c_int = 0x00400000;
26912690 pub const O_EXEC: ::c_int = O_PATH;
26922691 pub const O_SEARCH: ::c_int = O_PATH;
2693 pub const O_ACCMODE: ::c_int = (03 | O_SEARCH);
2692 pub const O_ACCMODE: ::c_int = 03 | O_SEARCH;
26942693 pub const O_NDELAY: ::c_int = O_NONBLOCK;
26952694 pub const NI_MAXHOST: ::socklen_t = 255;
26962695 pub const PTHREAD_STACK_MIN: ::size_t = 2048;
27712770
27722771 pub const RTLD_GLOBAL: ::c_int = 0x100;
27732772 pub const RTLD_NOLOAD: ::c_int = 0x4;
2774
2775 // TODO(#247) Temporarily musl-specific (available since musl 0.9.12 / Linux
2776 // kernel 3.10). See also notbsd/mod.rs
2777 pub const CLOCK_SGI_CYCLE: ::clockid_t = 10;
2778 pub const CLOCK_TAI: ::clockid_t = 11;
27792773
27802774 pub const MCL_CURRENT: ::c_int = 0x0001;
27812775 pub const MCL_FUTURE: ::c_int = 0x0002;
28922886 pub const O_EXCL: ::c_int = 0x00020000;
28932887 pub const O_NOCTTY: ::c_int = 0x00000200;
28942888 pub const O_NONBLOCK: ::c_int = 0x00000010;
2895 pub const O_SYNC: ::c_int = (0x00000040 | O_DSYNC);
2889 pub const O_SYNC: ::c_int = 0x00000040 | O_DSYNC;
28962890 pub const O_RSYNC: ::c_int = O_SYNC;
28972891 pub const O_DSYNC: ::c_int = 0x00000020;
28982892
32723266 }
32733267 }
32743268 #[cfg_attr(feature = "extra_traits", derive(Debug))]
3275 pub enum fpos_t {} // TODO: fill this out with a struct
3269 pub enum fpos_t {} // FIXME: fill this out with a struct
32763270 impl ::Copy for fpos_t {}
32773271 impl ::Clone for fpos_t {
32783272 fn clone(&self) -> fpos_t {
34003394 ) -> ::size_t;
34013395
34023396 pub fn memchr(cx: *const c_void, c: c_int, n: size_t) -> *mut c_void;
3397 pub fn wmemchr(cx: *const wchar_t, c: wchar_t, n: size_t) -> *mut wchar_t;
34033398 pub fn memcmp(cx: *const c_void, ct: *const c_void, n: size_t) -> c_int;
34043399 pub fn memcpy(
34053400 dest: *mut c_void,
0 // Copyright 2018 The Rust Project Developers. See the COPYRIGHT
1 // file at the top-level directory of this distribution and at
2 // http://rust-lang.org/COPYRIGHT.
3 //
4 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7 // option. This file may not be copied, modified, or distributed
8 // except according to those terms.
9
100 // libc port for HermitCore (https://hermitcore.org)
111 //
122 // Ported by Colin Fink <colin.finck@rwth-aachen.de>
0 // Copyright 2012-2015 The Rust Project Developers. See the COPYRIGHT
1 // file at the top-level directory of this distribution and at
2 // http://rust-lang.org/COPYRIGHT.
3 //
4 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7 // option. This file may not be copied, modified, or distributed
8 // except according to those terms.
90 //! libc - Raw FFI bindings to platforms' system libraries
101 //!
112 //! [Documentation for other platforms][pd].
134 //! [pd]: https://rust-lang.github.io/libc/#platform-specific-documentation
145 #![crate_name = "libc"]
156 #![crate_type = "rlib"]
16 #![cfg_attr(libc_deny_warnings, deny(warnings))]
7 // FIXME: Remove this and redundant_semicolon once renamed lint reaches stable.
8 #![allow(renamed_and_removed_lints)]
179 #![allow(
1810 bad_style,
1911 overflowing_literals,
2012 improper_ctypes,
2113 unknown_lints,
22 redundant_semicolon
14 redundant_semicolon,
15 redundant_semicolons
2316 )]
17 #![cfg_attr(libc_deny_warnings, deny(warnings))]
2418 // Attributes needed when building as part of the standard library
2519 #![cfg_attr(
2620 feature = "rustc-dep-of-std",
22 pub type c_long = i64;
33 pub type c_ulong = u64;
44 pub type boolean_t = ::c_uint;
5 pub type mcontext_t = *mut __darwin_mcontext64;
56
67 s! {
78 pub struct timeval32 {
4748 pub bh_datalen: u32,
4849 pub bh_hdrlen: ::c_ushort,
4950 }
51
52 pub struct ucontext_t {
53 pub uc_onstack: ::c_int,
54 pub uc_sigmask: ::sigset_t,
55 pub uc_stack: ::stack_t,
56 pub uc_link: *mut ::ucontext_t,
57 pub uc_mcsize: usize,
58 pub uc_mcontext: mcontext_t,
59 }
60
61 pub struct __darwin_mcontext64 {
62 pub __es: __darwin_x86_exception_state64,
63 pub __ss: __darwin_x86_thread_state64,
64 pub __fs: __darwin_x86_float_state64,
65 }
66
67 pub struct __darwin_x86_exception_state64 {
68 pub __trapno: u16,
69 pub __cpu: u16,
70 pub __err: u32,
71 pub __faultvaddr: u64,
72 }
73
74 pub struct __darwin_x86_thread_state64 {
75 pub __rax: u64,
76 pub __rbx: u64,
77 pub __rcx: u64,
78 pub __rdx: u64,
79 pub __rdi: u64,
80 pub __rsi: u64,
81 pub __rbp: u64,
82 pub __rsp: u64,
83 pub __r8: u64,
84 pub __r9: u64,
85 pub __r10: u64,
86 pub __r11: u64,
87 pub __r12: u64,
88 pub __r13: u64,
89 pub __r14: u64,
90 pub __r15: u64,
91 pub __rip: u64,
92 pub __rflags: u64,
93 pub __cs: u64,
94 pub __fs: u64,
95 pub __gs: u64,
96 }
97
98 pub struct __darwin_x86_float_state64 {
99 pub __fpu_reserved: [::c_int; 2],
100 __fpu_fcw: ::c_short,
101 __fpu_fsw: ::c_short,
102 pub __fpu_ftw: u8,
103 pub __fpu_rsrv1: u8,
104 pub __fpu_fop: u16,
105 pub __fpu_ip: u32,
106 pub __fpu_cs: u16,
107 pub __fpu_rsrv2: u16,
108 pub __fpu_dp: u32,
109 pub __fpu_ds: u16,
110 pub __fpu_rsrv3: u16,
111 pub __fpu_mxcsr: u32,
112 pub __fpu_mxcsrmask: u32,
113 pub __fpu_stmm0: __darwin_mmst_reg,
114 pub __fpu_stmm1: __darwin_mmst_reg,
115 pub __fpu_stmm2: __darwin_mmst_reg,
116 pub __fpu_stmm3: __darwin_mmst_reg,
117 pub __fpu_stmm4: __darwin_mmst_reg,
118 pub __fpu_stmm5: __darwin_mmst_reg,
119 pub __fpu_stmm6: __darwin_mmst_reg,
120 pub __fpu_stmm7: __darwin_mmst_reg,
121 pub __fpu_xmm0: __darwin_xmm_reg,
122 pub __fpu_xmm1: __darwin_xmm_reg,
123 pub __fpu_xmm2: __darwin_xmm_reg,
124 pub __fpu_xmm3: __darwin_xmm_reg,
125 pub __fpu_xmm4: __darwin_xmm_reg,
126 pub __fpu_xmm5: __darwin_xmm_reg,
127 pub __fpu_xmm6: __darwin_xmm_reg,
128 pub __fpu_xmm7: __darwin_xmm_reg,
129 pub __fpu_xmm8: __darwin_xmm_reg,
130 pub __fpu_xmm9: __darwin_xmm_reg,
131 pub __fpu_xmm10: __darwin_xmm_reg,
132 pub __fpu_xmm11: __darwin_xmm_reg,
133 pub __fpu_xmm12: __darwin_xmm_reg,
134 pub __fpu_xmm13: __darwin_xmm_reg,
135 pub __fpu_xmm14: __darwin_xmm_reg,
136 pub __fpu_xmm15: __darwin_xmm_reg,
137 // this field is actually [u8; 96], but defining it with a bigger type
138 // allows us to auto-implement traits for it since the length of the
139 // array is less than 32
140 __fpu_rsrv4: [u32; 24],
141 pub __fpu_reserved1: ::c_int,
142 }
143
144 pub struct __darwin_mmst_reg {
145 pub __mmst_reg: [::c_char; 10],
146 pub __mmst_rsrv: [::c_char; 6],
147 }
148
149 pub struct __darwin_xmm_reg {
150 pub __xmm_reg: [::c_char; 16],
151 }
50152 }
51153
52154 s_no_extra_traits! {
3030 pub type key_t = ::c_int;
3131 pub type shmatt_t = ::c_ushort;
3232
33 pub type sae_associd_t = u32;
34 pub type sae_connid_t = u32;
35
3336 deprecated_mach! {
3437 pub type vm_prot_t = ::c_int;
3538 pub type vm_size_t = ::uintptr_t;
491494
492495 pub struct in_addr {
493496 pub s_addr: ::in_addr_t,
497 }
498
499 // sys/socket.h
500
501 pub struct sa_endpoints_t {
502 pub sae_srcif: ::c_uint, // optional source interface
503 pub sae_srcaddr: *const ::sockaddr, // optional source address
504 pub sae_srcaddrlen: ::socklen_t, // size of source address
505 pub sae_dstaddr: *const ::sockaddr, // destination address
506 pub sae_dstaddrlen: ::socklen_t, // size of destination address
507 }
508
509 pub struct timex {
510 pub modes: ::c_uint,
511 pub offset: ::c_long,
512 pub freq: ::c_long,
513 pub maxerror: ::c_long,
514 pub esterror: ::c_long,
515 pub status: ::c_int,
516 pub constant: ::c_long,
517 pub precision: ::c_long,
518 pub tolerance: ::c_long,
519 pub ppsfreq: ::c_long,
520 pub jitter: ::c_long,
521 pub shift: ::c_int,
522 pub stabil: ::c_long,
523 pub jitcnt: ::c_long,
524 pub calcnt: ::c_long,
525 pub errcnt: ::c_long,
526 pub stbcnt: ::c_long,
527 }
528
529 pub struct ntptimeval {
530 pub time: ::timespec,
531 pub maxerror: ::c_long,
532 pub esterror: ::c_long,
533 pub tai: ::c_long,
534 pub time_state: ::c_int,
494535 }
495536 }
496537
12381279 pub const SIGNATURE: ::c_short = 10;
12391280 pub const SHUTDOWN_TIME: ::c_short = 11;
12401281
1241 pub const LC_COLLATE_MASK: ::c_int = (1 << 0);
1242 pub const LC_CTYPE_MASK: ::c_int = (1 << 1);
1243 pub const LC_MESSAGES_MASK: ::c_int = (1 << 2);
1244 pub const LC_MONETARY_MASK: ::c_int = (1 << 3);
1245 pub const LC_NUMERIC_MASK: ::c_int = (1 << 4);
1246 pub const LC_TIME_MASK: ::c_int = (1 << 5);
1282 pub const LC_COLLATE_MASK: ::c_int = 1 << 0;
1283 pub const LC_CTYPE_MASK: ::c_int = 1 << 1;
1284 pub const LC_MESSAGES_MASK: ::c_int = 1 << 2;
1285 pub const LC_MONETARY_MASK: ::c_int = 1 << 3;
1286 pub const LC_NUMERIC_MASK: ::c_int = 1 << 4;
1287 pub const LC_TIME_MASK: ::c_int = 1 << 5;
12471288 pub const LC_ALL_MASK: ::c_int = LC_COLLATE_MASK
12481289 | LC_CTYPE_MASK
12491290 | LC_MESSAGES_MASK
22152256 pub const TCP_NOPUSH: ::c_int = 4;
22162257 pub const TCP_NOOPT: ::c_int = 8;
22172258 pub const TCP_KEEPALIVE: ::c_int = 0x10;
2259 /// Enable/Disable TCP Fastopen on this socket
2260 pub const TCP_FASTOPEN: ::c_int = 0x105;
22182261
22192262 pub const SOL_LOCAL: ::c_int = 0;
22202263
23022345 pub const SHUT_RD: ::c_int = 0;
23032346 pub const SHUT_WR: ::c_int = 1;
23042347 pub const SHUT_RDWR: ::c_int = 2;
2348
2349 pub const SAE_ASSOCID_ANY: ::sae_associd_t = 0;
2350 /// ((sae_associd_t)(-1ULL))
2351 pub const SAE_ASSOCID_ALL: ::sae_associd_t = 0xffffffff;
2352
2353 pub const SAE_CONNID_ANY: ::sae_connid_t = 0;
2354 /// ((sae_connid_t)(-1ULL))
2355 pub const SAE_CONNID_ALL: ::sae_connid_t = 0xffffffff;
2356
2357 // connectx() flag parameters
2358
2359 /// resume connect() on read/write
2360 pub const CONNECT_RESUME_ON_READ_WRITE: ::c_uint = 0x1;
2361 /// data is idempotent
2362 pub const CONNECT_DATA_IDEMPOTENT: ::c_uint = 0x2;
2363 /// data includes security that replaces the TFO-cookie
2364 pub const CONNECT_DATA_AUTHENTICATED: ::c_uint = 0x4;
23052365
23062366 pub const LOCK_SH: ::c_int = 1;
23072367 pub const LOCK_EX: ::c_int = 2;
24372497 __opaque: [0; __PTHREAD_RWLOCK_SIZE__],
24382498 };
24392499
2500 pub const MINSIGSTKSZ: ::size_t = 32768;
24402501 pub const SIGSTKSZ: ::size_t = 131072;
24412502
24422503 pub const FD_SETSIZE: usize = 1024;
29753036 // sizeof(i32)
29763037 pub const BPF_ALIGNMENT: ::c_int = 4;
29773038
3039 // sys/mount.h
3040 pub const MNT_RDONLY: ::c_int = 0x00000001;
3041 pub const MNT_SYNCHRONOUS: ::c_int = 0x00000002;
3042 pub const MNT_NOEXEC: ::c_int = 0x00000004;
3043 pub const MNT_NOSUID: ::c_int = 0x00000008;
3044 pub const MNT_NODEV: ::c_int = 0x00000010;
3045 pub const MNT_UNION: ::c_int = 0x00000020;
3046 pub const MNT_ASYNC: ::c_int = 0x00000040;
3047 pub const MNT_CPROTECT: ::c_int = 0x00000080;
3048
3049 // NFS export related mount flags.
3050 pub const MNT_EXPORTED: ::c_int = 0x00000100;
3051
3052 // MAC labeled / "quarantined" flag
3053 pub const MNT_QUARANTINE: ::c_int = 0x00000400;
3054
3055 // Flags set by internal operations.
3056 pub const MNT_LOCAL: ::c_int = 0x00001000;
3057 pub const MNT_QUOTA: ::c_int = 0x00002000;
3058 pub const MNT_ROOTFS: ::c_int = 0x00004000;
3059 pub const MNT_DOVOLFS: ::c_int = 0x00008000;
3060
3061 pub const MNT_DONTBROWSE: ::c_int = 0x00100000;
3062 pub const MNT_IGNORE_OWNERSHIP: ::c_int = 0x00200000;
3063 pub const MNT_AUTOMOUNTED: ::c_int = 0x00400000;
3064 pub const MNT_JOURNALED: ::c_int = 0x00800000;
3065 pub const MNT_NOUSERXATTR: ::c_int = 0x01000000;
3066 pub const MNT_DEFWRITE: ::c_int = 0x02000000;
3067 pub const MNT_MULTILABEL: ::c_int = 0x04000000;
3068 pub const MNT_NOATIME: ::c_int = 0x10000000;
3069 pub const MNT_SNAPSHOT: ::c_int = 0x40000000;
3070
3071 // External filesystem command modifier flags.
3072 pub const MNT_UPDATE: ::c_int = 0x00010000;
3073 pub const MNT_NOBLOCK: ::c_int = 0x00020000;
3074 pub const MNT_RELOAD: ::c_int = 0x00040000;
3075
29783076 // sys/spawn.h:
29793077 pub const POSIX_SPAWN_RESETIDS: ::c_int = 0x01;
29803078 pub const POSIX_SPAWN_SETPGROUP: ::c_int = 0x02;
30293127 pub const SF_IMMUTABLE: ::c_uint = 0x00020000;
30303128 pub const SF_APPEND: ::c_uint = 0x00040000;
30313129 pub const UF_HIDDEN: ::c_uint = 0x00008000;
3130
3131 //<sys/timex.h>
3132 pub const NTP_API: ::c_int = 4;
3133 pub const MAXPHASE: ::c_long = 500000000;
3134 pub const MAXFREQ: ::c_long = 500000;
3135 pub const MINSEC: ::c_int = 256;
3136 pub const MAXSEC: ::c_int = 2048;
3137 pub const NANOSECOND: ::c_long = 1000000000;
3138 pub const SCALE_PPM: ::c_int = 65;
3139 pub const MAXTC: ::c_int = 10;
3140 pub const MOD_OFFSET: ::c_uint = 0x0001;
3141 pub const MOD_FREQUENCY: ::c_uint = 0x0002;
3142 pub const MOD_MAXERROR: ::c_uint = 0x0004;
3143 pub const MOD_ESTERROR: ::c_uint = 0x0008;
3144 pub const MOD_STATUS: ::c_uint = 0x0010;
3145 pub const MOD_TIMECONST: ::c_uint = 0x0020;
3146 pub const MOD_PPSMAX: ::c_uint = 0x0040;
3147 pub const MOD_TAI: ::c_uint = 0x0080;
3148 pub const MOD_MICRO: ::c_uint = 0x1000;
3149 pub const MOD_NANO: ::c_uint = 0x2000;
3150 pub const MOD_CLKB: ::c_uint = 0x4000;
3151 pub const MOD_CLKA: ::c_uint = 0x8000;
3152 pub const STA_PLL: ::c_int = 0x0001;
3153 pub const STA_PPSFREQ: ::c_int = 0x0002;
3154 pub const STA_PPSTIME: ::c_int = 0x0004;
3155 pub const STA_FLL: ::c_int = 0x0008;
3156 pub const STA_INS: ::c_int = 0x0010;
3157 pub const STA_DEL: ::c_int = 0x0020;
3158 pub const STA_UNSYNC: ::c_int = 0x0040;
3159 pub const STA_FREQHOLD: ::c_int = 0x0080;
3160 pub const STA_PPSSIGNAL: ::c_int = 0x0100;
3161 pub const STA_PPSJITTER: ::c_int = 0x0200;
3162 pub const STA_PPSWANDER: ::c_int = 0x0400;
3163 pub const STA_PPSERROR: ::c_int = 0x0800;
3164 pub const STA_CLOCKERR: ::c_int = 0x1000;
3165 pub const STA_NANO: ::c_int = 0x2000;
3166 pub const STA_MODE: ::c_int = 0x4000;
3167 pub const STA_CLK: ::c_int = 0x8000;
3168 pub const STA_RONLY: ::c_int = STA_PPSSIGNAL
3169 | STA_PPSJITTER
3170 | STA_PPSWANDER
3171 | STA_PPSERROR
3172 | STA_CLOCKERR
3173 | STA_NANO
3174 | STA_MODE
3175 | STA_CLK;
3176 pub const TIME_OK: ::c_int = 0;
3177 pub const TIME_INS: ::c_int = 1;
3178 pub const TIME_DEL: ::c_int = 2;
3179 pub const TIME_OOP: ::c_int = 3;
3180 pub const TIME_WAIT: ::c_int = 4;
3181 pub const TIME_ERROR: ::c_int = 5;
30323182
30333183 cfg_if! {
30343184 if #[cfg(libc_const_size_of)] {
35273677 newfd: ::c_int,
35283678 ) -> ::c_int;
35293679 pub fn uname(buf: *mut ::utsname) -> ::c_int;
3680
3681 pub fn connectx(
3682 socket: ::c_int,
3683 endpoints: *const sa_endpoints_t,
3684 associd: sae_associd_t,
3685 flags: ::c_uint,
3686 iov: *const ::iovec,
3687 iovcnt: ::c_uint,
3688 len: *mut ::size_t,
3689 connid: *mut sae_connid_t,
3690 ) -> ::c_int;
3691 pub fn disconnectx(
3692 socket: ::c_int,
3693 associd: sae_associd_t,
3694 connid: sae_connid_t,
3695 ) -> ::c_int;
3696
3697 pub fn ntp_adjtime(buf: *mut timex) -> ::c_int;
3698 pub fn ntp_gettime(buf: *mut ntptimeval) -> ::c_int;
35303699 }
35313700
35323701 cfg_if! {
955955 pub const UTX_DB_WTMPX: ::c_uint = 1;
956956 pub const UTX_DB_LASTLOG: ::c_uint = 2;
957957
958 pub const LC_COLLATE_MASK: ::c_int = (1 << 0);
959 pub const LC_CTYPE_MASK: ::c_int = (1 << 1);
960 pub const LC_MONETARY_MASK: ::c_int = (1 << 2);
961 pub const LC_NUMERIC_MASK: ::c_int = (1 << 3);
962 pub const LC_TIME_MASK: ::c_int = (1 << 4);
963 pub const LC_MESSAGES_MASK: ::c_int = (1 << 5);
958 pub const LC_COLLATE_MASK: ::c_int = 1 << 0;
959 pub const LC_CTYPE_MASK: ::c_int = 1 << 1;
960 pub const LC_MONETARY_MASK: ::c_int = 1 << 2;
961 pub const LC_NUMERIC_MASK: ::c_int = 1 << 3;
962 pub const LC_TIME_MASK: ::c_int = 1 << 4;
963 pub const LC_MESSAGES_MASK: ::c_int = 1 << 5;
964964 pub const LC_ALL_MASK: ::c_int = LC_COLLATE_MASK
965965 | LC_CTYPE_MASK
966966 | LC_MESSAGES_MASK
10851085 pub fn statfs(path: *const ::c_char, buf: *mut statfs) -> ::c_int;
10861086 pub fn fstatfs(fd: ::c_int, buf: *mut statfs) -> ::c_int;
10871087 pub fn uname(buf: *mut ::utsname) -> ::c_int;
1088 pub fn memmem(
1089 haystack: *const ::c_void,
1090 haystacklen: ::size_t,
1091 needle: *const ::c_void,
1092 needlelen: ::size_t,
1093 ) -> *mut ::c_void;
10881094 }
10891095
10901096 cfg_if! {
10231023 pub const UTXDB_LASTLOGIN: ::c_int = 1;
10241024 pub const UTXDB_LOG: ::c_int = 2;
10251025
1026 pub const LC_COLLATE_MASK: ::c_int = (1 << 0);
1027 pub const LC_CTYPE_MASK: ::c_int = (1 << 1);
1028 pub const LC_MONETARY_MASK: ::c_int = (1 << 2);
1029 pub const LC_NUMERIC_MASK: ::c_int = (1 << 3);
1030 pub const LC_TIME_MASK: ::c_int = (1 << 4);
1031 pub const LC_MESSAGES_MASK: ::c_int = (1 << 5);
1026 pub const LC_COLLATE_MASK: ::c_int = 1 << 0;
1027 pub const LC_CTYPE_MASK: ::c_int = 1 << 1;
1028 pub const LC_MONETARY_MASK: ::c_int = 1 << 2;
1029 pub const LC_NUMERIC_MASK: ::c_int = 1 << 3;
1030 pub const LC_TIME_MASK: ::c_int = 1 << 4;
1031 pub const LC_MESSAGES_MASK: ::c_int = 1 << 5;
10321032 pub const LC_ALL_MASK: ::c_int = LC_COLLATE_MASK
10331033 | LC_CTYPE_MASK
10341034 | LC_MESSAGES_MASK
14341434 flags: ::c_int,
14351435 timeout: *const ::timespec,
14361436 ) -> ::ssize_t;
1437 pub fn memmem(
1438 haystack: *const ::c_void,
1439 haystacklen: ::size_t,
1440 needle: *const ::c_void,
1441 needlelen: ::size_t,
1442 ) -> *mut ::c_void;
14371443 }
14381444
14391445 #[link(name = "util")]
188188 pub ar_hln: u8,
189189 pub ar_pln: u8,
190190 pub ar_op: u16,
191 }
192
193 pub struct timex {
194 pub modes: ::c_uint,
195 pub offset: ::c_long,
196 pub freq: ::c_long,
197 pub maxerror: ::c_long,
198 pub esterror: ::c_long,
199 pub status: ::c_int,
200 pub constant: ::c_long,
201 pub precision: ::c_long,
202 pub tolerance: ::c_long,
203 pub ppsfreq: ::c_long,
204 pub jitter: ::c_long,
205 pub shift: ::c_int,
206 pub stabil: ::c_long,
207 pub jitcnt: ::c_long,
208 pub calcnt: ::c_long,
209 pub errcnt: ::c_long,
210 pub stbcnt: ::c_long,
211 }
212
213 pub struct ntptimeval {
214 pub time: ::timespec,
215 pub maxerror: ::c_long,
216 pub esterror: ::c_long,
217 pub tai: ::c_long,
218 pub time_state: ::c_int,
191219 }
192220 }
193221
11001128
11011129 pub const TIMER_ABSTIME: ::c_int = 1;
11021130
1131 //<sys/timex.h>
1132 pub const NTP_API: ::c_int = 4;
1133 pub const MAXPHASE: ::c_long = 500000000;
1134 pub const MAXFREQ: ::c_long = 500000;
1135 pub const MINSEC: ::c_int = 256;
1136 pub const MAXSEC: ::c_int = 2048;
1137 pub const NANOSECOND: ::c_long = 1000000000;
1138 pub const SCALE_PPM: ::c_int = 65;
1139 pub const MAXTC: ::c_int = 10;
1140 pub const MOD_OFFSET: ::c_uint = 0x0001;
1141 pub const MOD_FREQUENCY: ::c_uint = 0x0002;
1142 pub const MOD_MAXERROR: ::c_uint = 0x0004;
1143 pub const MOD_ESTERROR: ::c_uint = 0x0008;
1144 pub const MOD_STATUS: ::c_uint = 0x0010;
1145 pub const MOD_TIMECONST: ::c_uint = 0x0020;
1146 pub const MOD_PPSMAX: ::c_uint = 0x0040;
1147 pub const MOD_TAI: ::c_uint = 0x0080;
1148 pub const MOD_MICRO: ::c_uint = 0x1000;
1149 pub const MOD_NANO: ::c_uint = 0x2000;
1150 pub const MOD_CLKB: ::c_uint = 0x4000;
1151 pub const MOD_CLKA: ::c_uint = 0x8000;
1152 pub const STA_PLL: ::c_int = 0x0001;
1153 pub const STA_PPSFREQ: ::c_int = 0x0002;
1154 pub const STA_PPSTIME: ::c_int = 0x0004;
1155 pub const STA_FLL: ::c_int = 0x0008;
1156 pub const STA_INS: ::c_int = 0x0010;
1157 pub const STA_DEL: ::c_int = 0x0020;
1158 pub const STA_UNSYNC: ::c_int = 0x0040;
1159 pub const STA_FREQHOLD: ::c_int = 0x0080;
1160 pub const STA_PPSSIGNAL: ::c_int = 0x0100;
1161 pub const STA_PPSJITTER: ::c_int = 0x0200;
1162 pub const STA_PPSWANDER: ::c_int = 0x0400;
1163 pub const STA_PPSERROR: ::c_int = 0x0800;
1164 pub const STA_CLOCKERR: ::c_int = 0x1000;
1165 pub const STA_NANO: ::c_int = 0x2000;
1166 pub const STA_MODE: ::c_int = 0x4000;
1167 pub const STA_CLK: ::c_int = 0x8000;
1168 pub const STA_RONLY: ::c_int = STA_PPSSIGNAL
1169 | STA_PPSJITTER
1170 | STA_PPSWANDER
1171 | STA_PPSERROR
1172 | STA_CLOCKERR
1173 | STA_NANO
1174 | STA_MODE
1175 | STA_CLK;
1176 pub const TIME_OK: ::c_int = 0;
1177 pub const TIME_INS: ::c_int = 1;
1178 pub const TIME_DEL: ::c_int = 2;
1179 pub const TIME_OOP: ::c_int = 3;
1180 pub const TIME_WAIT: ::c_int = 4;
1181 pub const TIME_ERROR: ::c_int = 5;
1182
1183 pub const REG_ENOSYS: ::c_int = -1;
1184 pub const REG_ILLSEQ: ::c_int = 17;
1185
11031186 f! {
11041187 pub fn WIFCONTINUED(status: ::c_int) -> bool {
11051188 status == 0x13
11641247 buflen: ::size_t,
11651248 result: *mut *mut ::group,
11661249 ) -> ::c_int;
1167 #[cfg_attr(target_os = "netbsd", link_name = "__getpwent_r50")]
11681250 pub fn getpwent_r(
11691251 pwd: *mut ::passwd,
11701252 buf: *mut ::c_char,
14321514 times: *const ::timespec,
14331515 flag: ::c_int,
14341516 ) -> ::c_int;
1517
1518 pub fn ntp_adjtime(buf: *mut timex) -> ::c_int;
1519 pub fn ntp_gettime(buf: *mut ntptimeval) -> ::c_int;
14351520 }
14361521
14371522 #[link(name = "util")]
55 pub type sa_family_t = u8;
66 pub type pthread_t = ::uintptr_t;
77 pub type nfds_t = ::c_uint;
8 pub type regoff_t = off_t;
89
910 s! {
1011 pub struct sockaddr {
99100 pub struct if_nameindex {
100101 pub if_index: ::c_uint,
101102 pub if_name: *mut ::c_char,
103 }
104
105 pub struct regex_t {
106 __re_magic: ::c_int,
107 __re_nsub: ::size_t,
108 __re_endp: *const ::c_char,
109 __re_g: *mut ::c_void,
110 }
111
112 pub struct regmatch_t {
113 pub rm_so: regoff_t,
114 pub rm_eo: regoff_t,
102115 }
103116 }
104117
449462 pub const BIOCSHDRCMPLT: ::c_ulong = 0x80044275;
450463 pub const SIOCGIFADDR: ::c_ulong = 0xc0206921;
451464
465 pub const REG_BASIC: ::c_int = 0o0000;
466 pub const REG_EXTENDED: ::c_int = 0o0001;
467 pub const REG_ICASE: ::c_int = 0o0002;
468 pub const REG_NOSUB: ::c_int = 0o0004;
469 pub const REG_NEWLINE: ::c_int = 0o0010;
470 pub const REG_NOSPEC: ::c_int = 0o0020;
471 pub const REG_PEND: ::c_int = 0o0040;
472 pub const REG_DUMP: ::c_int = 0o0200;
473
474 pub const REG_NOMATCH: ::c_int = 1;
475 pub const REG_BADPAT: ::c_int = 2;
476 pub const REG_ECOLLATE: ::c_int = 3;
477 pub const REG_ECTYPE: ::c_int = 4;
478 pub const REG_EESCAPE: ::c_int = 5;
479 pub const REG_ESUBREG: ::c_int = 6;
480 pub const REG_EBRACK: ::c_int = 7;
481 pub const REG_EPAREN: ::c_int = 8;
482 pub const REG_EBRACE: ::c_int = 9;
483 pub const REG_BADBR: ::c_int = 10;
484 pub const REG_ERANGE: ::c_int = 11;
485 pub const REG_ESPACE: ::c_int = 12;
486 pub const REG_BADRPT: ::c_int = 13;
487 pub const REG_EMPTY: ::c_int = 14;
488 pub const REG_ASSERT: ::c_int = 15;
489 pub const REG_INVARG: ::c_int = 16;
490 pub const REG_ATOI: ::c_int = 255;
491 pub const REG_ITOA: ::c_int = 0o0400;
492
493 pub const REG_NOTBOL: ::c_int = 0o00001;
494 pub const REG_NOTEOL: ::c_int = 0o00002;
495 pub const REG_STARTEND: ::c_int = 0o00004;
496 pub const REG_TRACE: ::c_int = 0o00400;
497 pub const REG_LARGE: ::c_int = 0o01000;
498 pub const REG_BACKR: ::c_int = 0o02000;
499
452500 f! {
453501 pub fn CMSG_FIRSTHDR(mhdr: *const ::msghdr) -> *mut ::cmsghdr {
454502 if (*mhdr).msg_controllen as usize >= ::mem::size_of::<::cmsghdr>() {
685733 ) -> ::ssize_t;
686734
687735 pub fn sync();
688 #[cfg_attr(target_os = "solaris", link_name = "__posix_getgrgid_r")]
689736 pub fn getgrgid_r(
690737 gid: ::gid_t,
691738 grp: *mut ::group,
701748 pub fn sigaltstack(ss: *const stack_t, oss: *mut stack_t) -> ::c_int;
702749 pub fn sem_close(sem: *mut sem_t) -> ::c_int;
703750 pub fn getdtablesize() -> ::c_int;
704 #[cfg_attr(target_os = "solaris", link_name = "__posix_getgrnam_r")]
705751 pub fn getgrnam_r(
706752 name: *const ::c_char,
707753 grp: *mut ::group,
728774 pub fn pthread_kill(thread: ::pthread_t, sig: ::c_int) -> ::c_int;
729775 pub fn sem_unlink(name: *const ::c_char) -> ::c_int;
730776 #[cfg_attr(target_os = "netbsd", link_name = "__getpwnam_r50")]
731 #[cfg_attr(target_os = "solaris", link_name = "__posix_getpwnam_r")]
732777 pub fn getpwnam_r(
733778 name: *const ::c_char,
734779 pwd: *mut passwd,
737782 result: *mut *mut passwd,
738783 ) -> ::c_int;
739784 #[cfg_attr(target_os = "netbsd", link_name = "__getpwuid_r50")]
740 #[cfg_attr(target_os = "solaris", link_name = "__posix_getpwuid_r")]
741785 pub fn getpwuid_r(
742786 uid: ::uid_t,
743787 pwd: *mut passwd,
749793 all(target_os = "macos", target_arch = "x86"),
750794 link_name = "sigwait$UNIX2003"
751795 )]
752 #[cfg_attr(target_os = "solaris", link_name = "__posix_sigwait")]
753796 pub fn sigwait(set: *const sigset_t, sig: *mut ::c_int) -> ::c_int;
754797 pub fn pthread_atfork(
755798 prepare: ::Option<unsafe extern "C" fn()>,
775818 value: *mut ::c_void,
776819 ) -> ::c_int;
777820 pub fn acct(filename: *const ::c_char) -> ::c_int;
821 #[cfg_attr(
822 all(target_os = "macos", target_arch = "x86"),
823 link_name = "wait4$UNIX2003"
824 )]
825 #[cfg_attr(
826 all(target_os = "freebsd", any(freebsd12, freebsd11, freebsd10)),
827 link_name = "wait4@FBSD_1.0"
828 )]
829 pub fn wait4(
830 pid: ::pid_t,
831 status: *mut ::c_int,
832 options: ::c_int,
833 rusage: *mut ::rusage,
834 ) -> ::pid_t;
835
836 pub fn regcomp(
837 preg: *mut regex_t,
838 pattern: *const ::c_char,
839 cflags: ::c_int,
840 ) -> ::c_int;
841
842 pub fn regexec(
843 preg: *const regex_t,
844 input: *const ::c_char,
845 nmatch: ::size_t,
846 pmatch: *mut regmatch_t,
847 eflags: ::c_int,
848 ) -> ::c_int;
849
850 pub fn regerror(
851 errcode: ::c_int,
852 preg: *const regex_t,
853 errbuf: *mut ::c_char,
854 errbuf_size: ::size_t,
855 ) -> ::size_t;
856
857 pub fn regfree(preg: *mut regex_t);
778858 }
779859
780860 cfg_if! {
620620
621621 pub const TIMER_ABSTIME: ::c_int = 1;
622622
623 pub const REG_ENOSYS: ::c_int = 17;
624
623625 #[link(name = "util")]
624626 extern "C" {
625627 pub fn setgrent();
631633 ) -> ::c_int;
632634
633635 pub fn daemon(nochdir: ::c_int, noclose: ::c_int) -> ::c_int;
636 pub fn accept4(
637 s: ::c_int,
638 addr: *mut ::sockaddr,
639 addrlen: *mut ::socklen_t,
640 flags: ::c_int,
641 ) -> ::c_int;
634642 pub fn mincore(
635643 addr: *mut ::c_void,
636644 len: ::size_t,
311311 pub ll_host: [::c_char; UT_HOSTSIZE],
312312 pub ll_time: ::time_t
313313 }
314
315 pub struct timex {
316 pub modes: ::c_uint,
317 pub offset: ::c_long,
318 pub freq: ::c_long,
319 pub maxerror: ::c_long,
320 pub esterror: ::c_long,
321 pub status: ::c_int,
322 pub constant: ::c_long,
323 pub precision: ::c_long,
324 pub tolerance: ::c_long,
325 pub ppsfreq: ::c_long,
326 pub jitter: ::c_long,
327 pub shift: ::c_int,
328 pub stabil: ::c_long,
329 pub jitcnt: ::c_long,
330 pub calcnt: ::c_long,
331 pub errcnt: ::c_long,
332 pub stbcnt: ::c_long,
333 }
334
335 pub struct ntptimeval {
336 pub time: ::timespec,
337 pub maxerror: ::c_long,
338 pub esterror: ::c_long,
339 pub tai: ::c_long,
340 pub time_state: ::c_int,
341 }
342
314343 }
315344
316345 s_no_extra_traits! {
864893 pub const EXTATTR_NAMESPACE_USER: ::c_int = 1;
865894 pub const EXTATTR_NAMESPACE_SYSTEM: ::c_int = 2;
866895
867 pub const LC_COLLATE_MASK: ::c_int = (1 << ::LC_COLLATE);
868 pub const LC_CTYPE_MASK: ::c_int = (1 << ::LC_CTYPE);
869 pub const LC_MONETARY_MASK: ::c_int = (1 << ::LC_MONETARY);
870 pub const LC_NUMERIC_MASK: ::c_int = (1 << ::LC_NUMERIC);
871 pub const LC_TIME_MASK: ::c_int = (1 << ::LC_TIME);
872 pub const LC_MESSAGES_MASK: ::c_int = (1 << ::LC_MESSAGES);
896 pub const LC_COLLATE_MASK: ::c_int = 1 << ::LC_COLLATE;
897 pub const LC_CTYPE_MASK: ::c_int = 1 << ::LC_CTYPE;
898 pub const LC_MONETARY_MASK: ::c_int = 1 << ::LC_MONETARY;
899 pub const LC_NUMERIC_MASK: ::c_int = 1 << ::LC_NUMERIC;
900 pub const LC_TIME_MASK: ::c_int = 1 << ::LC_TIME;
901 pub const LC_MESSAGES_MASK: ::c_int = 1 << ::LC_MESSAGES;
873902 pub const LC_ALL_MASK: ::c_int = !0;
874903
875904 pub const ERA: ::nl_item = 52;
12311260 pub const BIOCSDLT: ::c_ulong = 0x80044278;
12321261 pub const BIOCGSEESENT: ::c_ulong = 0x40044276;
12331262 pub const BIOCSSEESENT: ::c_ulong = 0x80044277;
1263
1264 //<sys/timex.h>
1265 pub const NTP_API: ::c_int = 4;
1266 pub const MAXPHASE: ::c_long = 500000000;
1267 pub const MAXFREQ: ::c_long = 500000;
1268 pub const MINSEC: ::c_int = 256;
1269 pub const MAXSEC: ::c_int = 2048;
1270 pub const NANOSECOND: ::c_long = 1000000000;
1271 pub const SCALE_PPM: ::c_int = 65;
1272 pub const MAXTC: ::c_int = 10;
1273 pub const MOD_OFFSET: ::c_uint = 0x0001;
1274 pub const MOD_FREQUENCY: ::c_uint = 0x0002;
1275 pub const MOD_MAXERROR: ::c_uint = 0x0004;
1276 pub const MOD_ESTERROR: ::c_uint = 0x0008;
1277 pub const MOD_STATUS: ::c_uint = 0x0010;
1278 pub const MOD_TIMECONST: ::c_uint = 0x0020;
1279 pub const MOD_PPSMAX: ::c_uint = 0x0040;
1280 pub const MOD_TAI: ::c_uint = 0x0080;
1281 pub const MOD_MICRO: ::c_uint = 0x1000;
1282 pub const MOD_NANO: ::c_uint = 0x2000;
1283 pub const MOD_CLKB: ::c_uint = 0x4000;
1284 pub const MOD_CLKA: ::c_uint = 0x8000;
1285 pub const STA_PLL: ::c_int = 0x0001;
1286 pub const STA_PPSFREQ: ::c_int = 0x0002;
1287 pub const STA_PPSTIME: ::c_int = 0x0004;
1288 pub const STA_FLL: ::c_int = 0x0008;
1289 pub const STA_INS: ::c_int = 0x0010;
1290 pub const STA_DEL: ::c_int = 0x0020;
1291 pub const STA_UNSYNC: ::c_int = 0x0040;
1292 pub const STA_FREQHOLD: ::c_int = 0x0080;
1293 pub const STA_PPSSIGNAL: ::c_int = 0x0100;
1294 pub const STA_PPSJITTER: ::c_int = 0x0200;
1295 pub const STA_PPSWANDER: ::c_int = 0x0400;
1296 pub const STA_PPSERROR: ::c_int = 0x0800;
1297 pub const STA_CLOCKERR: ::c_int = 0x1000;
1298 pub const STA_NANO: ::c_int = 0x2000;
1299 pub const STA_MODE: ::c_int = 0x4000;
1300 pub const STA_CLK: ::c_int = 0x8000;
1301 pub const STA_RONLY: ::c_int = STA_PPSSIGNAL
1302 | STA_PPSJITTER
1303 | STA_PPSWANDER
1304 | STA_PPSERROR
1305 | STA_CLOCKERR
1306 | STA_NANO
1307 | STA_MODE
1308 | STA_CLK;
1309 pub const TIME_OK: ::c_int = 0;
1310 pub const TIME_INS: ::c_int = 1;
1311 pub const TIME_DEL: ::c_int = 2;
1312 pub const TIME_OOP: ::c_int = 3;
1313 pub const TIME_WAIT: ::c_int = 4;
1314 pub const TIME_ERROR: ::c_int = 5;
12341315
12351316 cfg_if! {
12361317 if #[cfg(any(target_arch = "sparc", target_arch = "sparc64",
16481729 }
16491730 }
16501731
1732 extern "C" {
1733 pub fn ntp_adjtime(buf: *mut timex) -> ::c_int;
1734 pub fn ntp_gettime(buf: *mut ntptimeval) -> ::c_int;
1735 }
1736
16511737 #[link(name = "rt")]
16521738 extern "C" {
16531739 pub fn aio_read(aiocbp: *mut aiocb) -> ::c_int;
18931979 ) -> ::c_int;
18941980
18951981 pub fn _lwp_self() -> lwpid_t;
1982 pub fn memmem(
1983 haystack: *const ::c_void,
1984 haystacklen: ::size_t,
1985 needle: *const ::c_void,
1986 needlelen: ::size_t,
1987 ) -> *mut ::c_void;
18961988 }
18971989
18981990 #[link(name = "util")]
13141314 pub const IFF_LINK2: ::c_int = 0x4000; // per link layer defined bit
13151315 pub const IFF_MULTICAST: ::c_int = 0x8000; // supports multicast
13161316
1317 pub const PTHREAD_STACK_MIN: ::size_t = (1_usize << _MAX_PAGE_SHIFT);
1318 pub const MINSIGSTKSZ: ::size_t = (3_usize << _MAX_PAGE_SHIFT);
1317 pub const PTHREAD_STACK_MIN: ::size_t = 1_usize << _MAX_PAGE_SHIFT;
1318 pub const MINSIGSTKSZ: ::size_t = 3_usize << _MAX_PAGE_SHIFT;
13191319 pub const SIGSTKSZ: ::size_t = MINSIGSTKSZ + (1_usize << _MAX_PAGE_SHIFT) * 4;
13201320
13211321 pub const PT_FIRSTMACH: ::c_int = 32;
13911391 pub fn settimeofday(
13921392 tp: *const ::timeval,
13931393 tz: *const ::timezone,
1394 ) -> ::c_int;
1395 pub fn accept4(
1396 s: ::c_int,
1397 addr: *mut ::sockaddr,
1398 addrlen: *mut ::socklen_t,
1399 flags: ::c_int,
14001394 ) -> ::c_int;
14011395 pub fn execvpe(
14021396 file: *const ::c_char,
14771471 addr: caddr_t,
14781472 data: ::c_int,
14791473 ) -> ::c_int;
1474 pub fn memmem(
1475 haystack: *const ::c_void,
1476 haystacklen: ::size_t,
1477 needle: *const ::c_void,
1478 needlelen: ::size_t,
1479 ) -> *mut ::c_void;
14801480 }
14811481
14821482 cfg_if! {
661661 pub const LC_TIME: ::c_int = 5;
662662 pub const LC_MESSAGES: ::c_int = 6;
663663
664 // TODO: Haiku does not have MAP_FILE, but libstd/os.rs requires it
664 // FIXME: Haiku does not have MAP_FILE, but libstd/os.rs requires it
665665 pub const MAP_FILE: ::c_int = 0x00;
666666 pub const MAP_SHARED: ::c_int = 0x01;
667667 pub const MAP_PRIVATE: ::c_int = 0x02;
993993 pub const PTHREAD_MUTEX_ERRORCHECK: ::c_int = 2;
994994 pub const PTHREAD_MUTEX_RECURSIVE: ::c_int = 3;
995995
996 pub const FIOCLEX: c_ulong = 0; // TODO: does not exist on Haiku!
996 pub const FIOCLEX: c_ulong = 0; // FIXME: does not exist on Haiku!
997997
998998 pub const RUSAGE_CHILDREN: ::c_int = -1;
999999
12371237 }
12381238
12391239 pub fn WEXITSTATUS(status: ::c_int) -> ::c_int {
1240 (status & 0xff)
1240 status & 0xff
12411241 }
12421242
12431243 pub fn WIFSIGNALED(status: ::c_int) -> bool {
12691269 extern "C" {
12701270 pub fn getrlimit(resource: ::c_int, rlim: *mut ::rlimit) -> ::c_int;
12711271 pub fn setrlimit(resource: ::c_int, rlim: *const ::rlimit) -> ::c_int;
1272 pub fn utimensat(
1273 fd: ::c_int,
1274 path: *const ::c_char,
1275 times: *const ::timespec,
1276 flag: ::c_int,
1277 ) -> ::c_int;
1278 pub fn futimens(fd: ::c_int, times: *const ::timespec) -> ::c_int;
12721279 pub fn strerror_r(
12731280 errnum: ::c_int,
12741281 buf: *mut c_char,
13931400 addrlen: *mut ::socklen_t,
13941401 ) -> ::ssize_t;
13951402 pub fn mkstemps(template: *mut ::c_char, suffixlen: ::c_int) -> ::c_int;
1396 pub fn futimes(fd: ::c_int, times: *const ::timeval) -> ::c_int;
13971403 pub fn lutimes(file: *const ::c_char, times: *const ::timeval) -> ::c_int;
13981404 pub fn nl_langinfo(item: ::nl_item) -> *mut ::c_char;
13991405
14291435 argv: *const *const ::c_char,
14301436 environment: *const *const ::c_char,
14311437 ) -> ::c_int;
1432 #[cfg_attr(target_os = "solaris", link_name = "__posix_getgrgid_r")]
14331438 pub fn getgrgid_r(
14341439 gid: ::gid_t,
14351440 grp: *mut ::group,
14371442 buflen: ::size_t,
14381443 result: *mut *mut ::group,
14391444 ) -> ::c_int;
1440 #[cfg_attr(
1441 all(target_os = "macos", target_arch = "x86"),
1442 link_name = "sigaltstack$UNIX2003"
1443 )]
1444 #[cfg_attr(target_os = "netbsd", link_name = "__sigaltstack14")]
14451445 pub fn sigaltstack(ss: *const stack_t, oss: *mut stack_t) -> ::c_int;
14461446 pub fn sem_close(sem: *mut sem_t) -> ::c_int;
14471447 pub fn getdtablesize() -> ::c_int;
1448 #[cfg_attr(target_os = "solaris", link_name = "__posix_getgrnam_r")]
14491448 pub fn getgrnam_r(
14501449 name: *const ::c_char,
14511450 grp: *mut ::group,
14531452 buflen: ::size_t,
14541453 result: *mut *mut ::group,
14551454 ) -> ::c_int;
1456 #[cfg_attr(
1457 all(target_os = "macos", target_arch = "x86"),
1458 link_name = "pthread_sigmask$UNIX2003"
1459 )]
14601455 pub fn pthread_sigmask(
14611456 how: ::c_int,
14621457 set: *const sigset_t,
14671462 pub fn pthread_kill(thread: ::pthread_t, sig: ::c_int) -> ::c_int;
14681463 pub fn sem_unlink(name: *const ::c_char) -> ::c_int;
14691464 pub fn daemon(nochdir: ::c_int, noclose: ::c_int) -> ::c_int;
1470 #[cfg_attr(target_os = "netbsd", link_name = "__getpwnam_r50")]
1471 #[cfg_attr(target_os = "solaris", link_name = "__posix_getpwnam_r")]
14721465 pub fn getpwnam_r(
14731466 name: *const ::c_char,
14741467 pwd: *mut passwd,
14761469 buflen: ::size_t,
14771470 result: *mut *mut passwd,
14781471 ) -> ::c_int;
1479 #[cfg_attr(target_os = "netbsd", link_name = "__getpwuid_r50")]
1480 #[cfg_attr(target_os = "solaris", link_name = "__posix_getpwuid_r")]
14811472 pub fn getpwuid_r(
14821473 uid: ::uid_t,
14831474 pwd: *mut passwd,
14851476 buflen: ::size_t,
14861477 result: *mut *mut passwd,
14871478 ) -> ::c_int;
1488 #[cfg_attr(
1489 all(target_os = "macos", target_arch = "x86"),
1490 link_name = "sigwait$UNIX2003"
1491 )]
1492 #[cfg_attr(target_os = "solaris", link_name = "__posix_sigwait")]
14931479 pub fn sigwait(set: *const sigset_t, sig: *mut ::c_int) -> ::c_int;
14941480 pub fn pthread_atfork(
14951481 prepare: ::Option<unsafe extern "C" fn()>,
14971483 child: ::Option<unsafe extern "C" fn()>,
14981484 ) -> ::c_int;
14991485 pub fn getgrgid(gid: ::gid_t) -> *mut ::group;
1500 #[cfg_attr(
1501 all(target_os = "macos", target_arch = "x86"),
1502 link_name = "popen$UNIX2003"
1503 )]
15041486 pub fn popen(command: *const c_char, mode: *const c_char) -> *mut ::FILE;
15051487 pub fn openpty(
15061488 amaster: *mut ::c_int,
0 // Copyright 2018 The Rust Project Developers. See the COPYRIGHT
1 // file at the top-level directory of this distribution and at
2 // http://rust-lang.org/COPYRIGHT.
3 //
4 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7 // option. This file may not be copied, modified, or distributed
8 // except according to those terms.
9
100 // liblibc port for HermitCore (https://hermitcore.org)
111 // HermitCore is a unikernel based on lwIP, newlib, and
122 // pthread-embedded.
00 pub type c_char = u8;
11 pub type wchar_t = u32;
2 pub type greg_t = i32;
3 pub type mcontext_t = sigcontext;
4
5 s! {
6 pub struct sigcontext {
7 pub trap_no: ::c_ulong,
8 pub error_code: ::c_ulong,
9 pub oldmask: ::c_ulong,
10 pub arm_r0: ::c_ulong,
11 pub arm_r1: ::c_ulong,
12 pub arm_r2: ::c_ulong,
13 pub arm_r3: ::c_ulong,
14 pub arm_r4: ::c_ulong,
15 pub arm_r5: ::c_ulong,
16 pub arm_r6: ::c_ulong,
17 pub arm_r7: ::c_ulong,
18 pub arm_r8: ::c_ulong,
19 pub arm_r9: ::c_ulong,
20 pub arm_r10: ::c_ulong,
21 pub arm_fp: ::c_ulong,
22 pub arm_ip: ::c_ulong,
23 pub arm_sp: ::c_ulong,
24 pub arm_lr: ::c_ulong,
25 pub arm_pc: ::c_ulong,
26 pub arm_cpsr: ::c_ulong,
27 pub fault_address: ::c_ulong,
28 }
29 }
30
31 cfg_if! {
32 if #[cfg(libc_union)] {
33 s_no_extra_traits! {
34 pub struct __c_anonymous_uc_sigmask_with_padding {
35 pub uc_sigmask: ::sigset_t,
36 /* Android has a wrong (smaller) sigset_t on x86. */
37 __padding_rt_sigset: u32,
38 }
39
40 pub union __c_anonymous_uc_sigmask {
41 uc_sigmask: __c_anonymous_uc_sigmask_with_padding,
42 uc_sigmask64: ::sigset64_t,
43 }
44
45 pub struct ucontext_t {
46 pub uc_flags: ::c_ulong,
47 pub uc_link: *mut ucontext_t,
48 pub uc_stack: ::stack_t,
49 pub uc_mcontext: mcontext_t,
50 pub uc_sigmask__c_anonymous_union: __c_anonymous_uc_sigmask,
51 /* The kernel adds extra padding after uc_sigmask to match
52 * glibc sigset_t on ARM. */
53 __padding: [c_char; 120],
54 __align: [::c_longlong; 0],
55 uc_regspace: [::c_ulong; 128],
56 }
57 }
58
59 cfg_if! {
60 if #[cfg(feature = "extra_traits")] {
61 impl PartialEq for __c_anonymous_uc_sigmask_with_padding {
62 fn eq(
63 &self, other: &__c_anonymous_uc_sigmask_with_padding
64 ) -> bool {
65 self.uc_sigmask == other.uc_sigmask
66 // Ignore padding
67 }
68 }
69 impl Eq for __c_anonymous_uc_sigmask_with_padding {}
70 impl ::fmt::Debug for __c_anonymous_uc_sigmask_with_padding {
71 fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
72 f.debug_struct("uc_sigmask_with_padding")
73 .field("uc_sigmask_with_padding", &self.uc_sigmask)
74 // Ignore padding
75 .finish()
76 }
77 }
78 impl ::hash::Hash for __c_anonymous_uc_sigmask_with_padding {
79 fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
80 self.uc_sigmask.hash(state)
81 // Ignore padding
82 }
83 }
84
85 impl PartialEq for __c_anonymous_uc_sigmask {
86 fn eq(&self, other: &__c_anonymous_uc_sigmask) -> bool {
87 unsafe { self.uc_sigmask == other.uc_sigmask }
88 }
89 }
90 impl Eq for __c_anonymous_uc_sigmask {}
91 impl ::fmt::Debug for __c_anonymous_uc_sigmask {
92 fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
93 f.debug_struct("uc_sigmask")
94 .field("uc_sigmask", unsafe { &self.uc_sigmask })
95 .finish()
96 }
97 }
98 impl ::hash::Hash for __c_anonymous_uc_sigmask {
99 fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
100 unsafe { self.uc_sigmask.hash(state) }
101 }
102 }
103
104 impl PartialEq for ucontext_t {
105 fn eq(&self, other: &Self) -> bool {
106 self.uc_flags == other.uc_flags
107 && self.uc_link == other.uc_link
108 && self.uc_stack == other.uc_stack
109 && self.uc_mcontext == other.uc_mcontext
110 && self.uc_sigmask__c_anonymous_union
111 == other.uc_sigmask__c_anonymous_union
112 && &self.uc_regspace[..] == &other.uc_regspace[..]
113 // Ignore padding field
114 }
115 }
116 impl Eq for ucontext_t {}
117 impl ::fmt::Debug for ucontext_t {
118 fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
119 f.debug_struct("ucontext_t")
120 .field("uc_flags", &self.uc_flags)
121 .field("uc_link", &self.uc_link)
122 .field("uc_stack", &self.uc_stack)
123 .field("uc_mcontext", &self.uc_mcontext)
124 .field(
125 "uc_sigmask__c_anonymous_union",
126 &self.uc_sigmask__c_anonymous_union
127 )
128 .field("uc_regspace", &&self.uc_regspace[..])
129 // Ignore padding field
130 .finish()
131 }
132 }
133 impl ::hash::Hash for ucontext_t {
134 fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
135 self.uc_flags.hash(state);
136 self.uc_link.hash(state);
137 self.uc_stack.hash(state);
138 self.uc_mcontext.hash(state);
139 self.uc_sigmask__c_anonymous_union.hash(state);
140 &self.uc_regspace[..].hash(state);
141 // Ignore padding field
142 }
143 }
144 }
145 }
146 }
147 }
2148
3149 pub const O_DIRECT: ::c_int = 0x10000;
4150 pub const O_DIRECTORY: ::c_int = 0x4000;
354500 pub const SYS_pkey_mprotect: ::c_long = 394;
355501 pub const SYS_pkey_alloc: ::c_long = 395;
356502 pub const SYS_pkey_free: ::c_long = 396;
503
504 // offsets in mcontext_t.gregs from sys/ucontext.h
505 pub const REG_R0: ::c_int = 0;
506 pub const REG_R1: ::c_int = 1;
507 pub const REG_R2: ::c_int = 2;
508 pub const REG_R3: ::c_int = 3;
509 pub const REG_R4: ::c_int = 4;
510 pub const REG_R5: ::c_int = 5;
511 pub const REG_R6: ::c_int = 6;
512 pub const REG_R7: ::c_int = 7;
513 pub const REG_R8: ::c_int = 8;
514 pub const REG_R9: ::c_int = 9;
515 pub const REG_R10: ::c_int = 10;
516 pub const REG_R11: ::c_int = 11;
517 pub const REG_R12: ::c_int = 12;
518 pub const REG_R13: ::c_int = 13;
519 pub const REG_R14: ::c_int = 14;
520 pub const REG_R15: ::c_int = 15;
521
522 pub const NGREG: ::c_int = 18;
160160 }
161161 }
162162
163 s_no_extra_traits! {
164 pub struct sigset64_t {
165 __bits: [::c_ulong; 2]
166 }
167 }
168
169 cfg_if! {
170 if #[cfg(feature = "extra_traits")] {
171 impl ::fmt::Debug for sigset64_t {
172 fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
173 f.debug_struct("sigset64_t")
174 .field("__bits", &self.__bits)
175 .finish()
176 }
177 }
178 }
179 }
180
163181 // These constants must be of the same type of sigaction.sa_flags
164182 pub const SA_NOCLDSTOP: ::c_int = 0x00000001;
165183 pub const SA_NOCLDWAIT: ::c_int = 0x00000002;
00 pub type c_char = i8;
11 pub type wchar_t = i32;
2 pub type greg_t = i32;
3
4 s! {
5 pub struct _libc_fpreg {
6 pub significand: [u16; 4],
7 pub exponent: u16,
8 }
9
10 pub struct _libc_fpstate {
11 pub cw: ::c_ulong,
12 pub sw: ::c_ulong,
13 pub tag: ::c_ulong,
14 pub ipoff: ::c_ulong,
15 pub cssel: ::c_ulong,
16 pub dataoff: ::c_ulong,
17 pub datasel: ::c_ulong,
18 pub _st: [_libc_fpreg; 8],
19 pub status: ::c_ulong,
20 }
21
22 pub struct mcontext_t {
23 pub gregs: [greg_t; 19],
24 pub fpregs: *mut _libc_fpstate,
25 pub oldmask: ::c_ulong,
26 pub cr2: ::c_ulong,
27 }
28 }
29
30 cfg_if! {
31 if #[cfg(libc_union)] {
32 s_no_extra_traits! {
33 pub struct __c_anonymous_uc_sigmask_with_padding {
34 pub uc_sigmask: ::sigset_t,
35 /* Android has a wrong (smaller) sigset_t on x86. */
36 __padding_rt_sigset: u32,
37 }
38
39 pub union __c_anonymous_uc_sigmask {
40 uc_sigmask: __c_anonymous_uc_sigmask_with_padding,
41 uc_sigmask64: ::sigset64_t,
42 }
43
44 pub struct ucontext_t {
45 pub uc_flags: ::c_ulong,
46 pub uc_link: *mut ucontext_t,
47 pub uc_stack: ::stack_t,
48 pub uc_mcontext: mcontext_t,
49 pub uc_sigmask__c_anonymous_union: __c_anonymous_uc_sigmask,
50 __padding_rt_sigset: u32,
51 __fpregs_mem: _libc_fpstate,
52 }
53 }
54
55 cfg_if! {
56 if #[cfg(feature = "extra_traits")] {
57 impl PartialEq for __c_anonymous_uc_sigmask_with_padding {
58 fn eq(
59 &self, other: &__c_anonymous_uc_sigmask_with_padding
60 ) -> bool {
61 self.uc_sigmask == other.uc_sigmask
62 // Ignore padding
63 }
64 }
65 impl Eq for __c_anonymous_uc_sigmask_with_padding {}
66 impl ::fmt::Debug for __c_anonymous_uc_sigmask_with_padding {
67 fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
68 f.debug_struct("uc_sigmask_with_padding")
69 .field("uc_sigmask_with_padding", &self.uc_sigmask)
70 // Ignore padding
71 .finish()
72 }
73 }
74 impl ::hash::Hash for __c_anonymous_uc_sigmask_with_padding {
75 fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
76 self.uc_sigmask.hash(state)
77 // Ignore padding
78 }
79 }
80
81 impl PartialEq for __c_anonymous_uc_sigmask {
82 fn eq(&self, other: &__c_anonymous_uc_sigmask) -> bool {
83 unsafe { self.uc_sigmask == other.uc_sigmask }
84 }
85 }
86 impl Eq for __c_anonymous_uc_sigmask {}
87 impl ::fmt::Debug for __c_anonymous_uc_sigmask {
88 fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
89 f.debug_struct("uc_sigmask")
90 .field("uc_sigmask", unsafe { &self.uc_sigmask })
91 .finish()
92 }
93 }
94 impl ::hash::Hash for __c_anonymous_uc_sigmask {
95 fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
96 unsafe { self.uc_sigmask.hash(state) }
97 }
98 }
99
100 impl PartialEq for ucontext_t {
101 fn eq(&self, other: &Self) -> bool {
102 self.uc_flags == other.uc_flags
103 && self.uc_link == other.uc_link
104 && self.uc_stack == other.uc_stack
105 && self.uc_mcontext == other.uc_mcontext
106 && self.uc_sigmask__c_anonymous_union
107 == other.uc_sigmask__c_anonymous_union
108 // Ignore padding field
109 }
110 }
111 impl Eq for ucontext_t {}
112 impl ::fmt::Debug for ucontext_t {
113 fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
114 f.debug_struct("ucontext_t")
115 .field("uc_flags", &self.uc_flags)
116 .field("uc_link", &self.uc_link)
117 .field("uc_stack", &self.uc_stack)
118 .field("uc_mcontext", &self.uc_mcontext)
119 .field(
120 "uc_sigmask__c_anonymous_union",
121 &self.uc_sigmask__c_anonymous_union
122 )
123 // Ignore padding field
124 .finish()
125 }
126 }
127 impl ::hash::Hash for ucontext_t {
128 fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
129 self.uc_flags.hash(state);
130 self.uc_link.hash(state);
131 self.uc_stack.hash(state);
132 self.uc_mcontext.hash(state);
133 self.uc_sigmask__c_anonymous_union.hash(state);
134 // Ignore padding field
135 }
136 }
137 }
138 }
139 }
140 }
2141
3142 pub const O_DIRECT: ::c_int = 0x4000;
4143 pub const O_DIRECTORY: ::c_int = 0x10000;
413552 pub const UESP: ::c_int = 15;
414553 pub const SS: ::c_int = 16;
415554
555 // offsets in mcontext_t.gregs from sys/ucontext.h
556 pub const REG_GS: ::c_int = 0;
557 pub const REG_FS: ::c_int = 1;
558 pub const REG_ES: ::c_int = 2;
559 pub const REG_DS: ::c_int = 3;
560 pub const REG_EDI: ::c_int = 4;
561 pub const REG_ESI: ::c_int = 5;
562 pub const REG_EBP: ::c_int = 6;
563 pub const REG_ESP: ::c_int = 7;
564 pub const REG_EBX: ::c_int = 8;
565 pub const REG_EDX: ::c_int = 9;
566 pub const REG_ECX: ::c_int = 10;
567 pub const REG_EAX: ::c_int = 11;
568 pub const REG_TRAPNO: ::c_int = 12;
569 pub const REG_ERR: ::c_int = 13;
570 pub const REG_EIP: ::c_int = 14;
571 pub const REG_CS: ::c_int = 15;
572 pub const REG_EFL: ::c_int = 16;
573 pub const REG_UESP: ::c_int = 17;
574 pub const REG_SS: ::c_int = 18;
575
416576 cfg_if! {
417577 if #[cfg(libc_align)] {
418578 mod align;
125125 attr: i32,
126126 __reserved: [::c_char; 36],
127127 }
128
129 pub struct sigset64_t {
130 __bits: [::c_ulong; 1]
131 }
128132 }
129133
130134 cfg_if! {
225229 self.pendingWriters.hash(state);
226230 self.attr.hash(state);
227231 self.__reserved.hash(state);
232 }
233 }
234
235 impl ::fmt::Debug for sigset64_t {
236 fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
237 f.debug_struct("sigset64_t")
238 .field("__bits", &self.__bits)
239 .finish()
228240 }
229241 }
230242 }
00 pub type c_char = i8;
11 pub type wchar_t = i32;
2 pub type greg_t = i64;
23
34 s! {
45 pub struct stat {
3940 pub st_ctime: ::c_long,
4041 pub st_ctime_nsec: ::c_long,
4142 __unused: [::c_long; 3],
43 }
44
45 pub struct _libc_xmmreg {
46 pub element: [u32; 4],
47 }
48 }
49
50 cfg_if! {
51 if #[cfg(libc_union)] {
52 s_no_extra_traits! {
53 pub union __c_anonymous_uc_sigmask {
54 uc_sigmask: ::sigset_t,
55 uc_sigmask64: ::sigset64_t,
56 }
57 }
58
59 cfg_if! {
60 if #[cfg(feature = "extra_traits")] {
61 impl PartialEq for __c_anonymous_uc_sigmask {
62 fn eq(&self, other: &__c_anonymous_uc_sigmask) -> bool {
63 unsafe { self.uc_sigmask == other.uc_sigmask }
64 }
65 }
66 impl Eq for __c_anonymous_uc_sigmask {}
67 impl ::fmt::Debug for __c_anonymous_uc_sigmask {
68 fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
69 f.debug_struct("uc_sigmask")
70 .field("uc_sigmask", unsafe { &self.uc_sigmask })
71 .finish()
72 }
73 }
74 impl ::hash::Hash for __c_anonymous_uc_sigmask {
75 fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
76 unsafe { self.uc_sigmask.hash(state) }
77 }
78 }
79 }
80 }
81 }
82 }
83
84 s_no_extra_traits! {
85 pub struct _libc_fpxreg {
86 pub significand: [u16; 4],
87 pub exponent: u16,
88 __padding: [u16; 3],
89 }
90
91 pub struct _libc_fpstate {
92 pub cwd: u16,
93 pub swd: u16,
94 pub ftw: u16,
95 pub fop: u16,
96 pub rip: u64,
97 pub rdp: u64,
98 pub mxcsr: u32,
99 pub mxcr_mask: u32,
100 pub _st: [_libc_fpxreg; 8],
101 pub _xmm: [_libc_xmmreg; 16],
102 __private: [u32; 24],
103 }
104
105 pub struct mcontext_t {
106 pub gregs: [greg_t; 23],
107 pub fpregs: *mut _libc_fpstate,
108 __private: [u64; 8],
109 }
110
111 pub struct ucontext_t {
112 pub uc_flags: ::c_ulong,
113 pub uc_link: *mut ucontext_t,
114 pub uc_stack: ::stack_t,
115 pub uc_mcontext: mcontext_t,
116 pub uc_sigmask64: __c_anonymous_uc_sigmask,
117 __fpregs_mem: _libc_fpstate,
118 }
119 }
120
121 cfg_if! {
122 if #[cfg(feature = "extra_traits")] {
123 impl PartialEq for _libc_fpxreg {
124 fn eq(&self, other: &Self) -> bool {
125 self.significand == other.significand
126 && self.exponent == other.exponent
127 // Ignore padding field
128 }
129 }
130 impl Eq for _libc_fpxreg {}
131 impl ::fmt::Debug for _libc_fpxreg {
132 fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
133 f.debug_struct("_libc_fpxreg")
134 .field("significand", &self.significand)
135 .field("exponent", &self.exponent)
136 // Ignore padding field
137 .finish()
138 }
139 }
140 impl ::hash::Hash for _libc_fpxreg {
141 fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
142 self.significand.hash(state);
143 self.exponent.hash(state);
144 // Ignore padding field
145 }
146 }
147
148 impl PartialEq for _libc_fpstate {
149 fn eq(&self, other: &Self) -> bool {
150 self.cwd == other.cwd
151 && self.swd == other.swd
152 && self.ftw == other.ftw
153 && self.fop == other.fop
154 && self.rip == other.rip
155 && self.rdp == other.rdp
156 && self.mxcsr == other.mxcsr
157 && self.mxcr_mask == other.mxcr_mask
158 && self._st == other._st
159 && self._xmm == other._xmm
160 // Ignore padding field
161 }
162 }
163 impl Eq for _libc_fpstate {}
164 impl ::fmt::Debug for _libc_fpstate {
165 fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
166 f.debug_struct("_libc_fpstate")
167 .field("cwd", &self.cwd)
168 .field("swd", &self.swd)
169 .field("ftw", &self.ftw)
170 .field("fop", &self.fop)
171 .field("rip", &self.rip)
172 .field("rdp", &self.rdp)
173 .field("mxcsr", &self.mxcsr)
174 .field("mxcr_mask", &self.mxcr_mask)
175 .field("_st", &self._st)
176 .field("_xmm", &self._xmm)
177 // Ignore padding field
178 .finish()
179 }
180 }
181 impl ::hash::Hash for _libc_fpstate {
182 fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
183 self.cwd.hash(state);
184 self.swd.hash(state);
185 self.ftw.hash(state);
186 self.fop.hash(state);
187 self.rip.hash(state);
188 self.rdp.hash(state);
189 self.mxcsr.hash(state);
190 self.mxcr_mask.hash(state);
191 self._st.hash(state);
192 self._xmm.hash(state);
193 // Ignore padding field
194 }
195 }
196
197 impl PartialEq for mcontext_t {
198 fn eq(&self, other: &Self) -> bool {
199 self.gregs == other.gregs
200 && self.fpregs == other.fpregs
201 // Ignore padding field
202 }
203 }
204 impl Eq for mcontext_t {}
205 impl ::fmt::Debug for mcontext_t {
206 fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
207 f.debug_struct("mcontext_t")
208 .field("gregs", &self.gregs)
209 .field("fpregs", &self.fpregs)
210 // Ignore padding field
211 .finish()
212 }
213 }
214 impl ::hash::Hash for mcontext_t {
215 fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
216 self.gregs.hash(state);
217 self.fpregs.hash(state);
218 // Ignore padding field
219 }
220 }
221
222 impl PartialEq for ucontext_t {
223 fn eq(&self, other: &Self) -> bool {
224 self.uc_flags == other.uc_flags
225 && self.uc_link == other.uc_link
226 && self.uc_stack == other.uc_stack
227 && self.uc_mcontext == other.uc_mcontext
228 && self.uc_sigmask64 == other.uc_sigmask64
229 // Ignore padding field
230 }
231 }
232 impl Eq for ucontext_t {}
233 impl ::fmt::Debug for ucontext_t {
234 fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
235 f.debug_struct("ucontext_t")
236 .field("uc_flags", &self.uc_flags)
237 .field("uc_link", &self.uc_link)
238 .field("uc_stack", &self.uc_stack)
239 .field("uc_mcontext", &self.uc_mcontext)
240 .field("uc_sigmask64", &self.uc_sigmask64)
241 // Ignore padding field
242 .finish()
243 }
244 }
245 impl ::hash::Hash for ucontext_t {
246 fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
247 self.uc_flags.hash(state);
248 self.uc_link.hash(state);
249 self.uc_stack.hash(state);
250 self.uc_mcontext.hash(state);
251 self.uc_sigmask64.hash(state);
252 // Ignore padding field
253 }
254 }
42255 }
43256 }
44257
418631 pub const FS: ::c_int = 25;
419632 pub const GS: ::c_int = 26;
420633
634 // offsets in mcontext_t.gregs from sys/ucontext.h
635 pub const REG_R8: ::c_int = 0;
636 pub const REG_R9: ::c_int = 1;
637 pub const REG_R10: ::c_int = 2;
638 pub const REG_R11: ::c_int = 3;
639 pub const REG_R12: ::c_int = 4;
640 pub const REG_R13: ::c_int = 5;
641 pub const REG_R14: ::c_int = 6;
642 pub const REG_R15: ::c_int = 7;
643 pub const REG_RDI: ::c_int = 8;
644 pub const REG_RSI: ::c_int = 9;
645 pub const REG_RBP: ::c_int = 10;
646 pub const REG_RBX: ::c_int = 11;
647 pub const REG_RDX: ::c_int = 12;
648 pub const REG_RAX: ::c_int = 13;
649 pub const REG_RCX: ::c_int = 14;
650 pub const REG_RSP: ::c_int = 15;
651 pub const REG_RIP: ::c_int = 16;
652 pub const REG_EFL: ::c_int = 17;
653 pub const REG_CSGSFS: ::c_int = 18;
654 pub const REG_ERR: ::c_int = 19;
655 pub const REG_TRAPNO: ::c_int = 20;
656 pub const REG_OLDMASK: ::c_int = 21;
657 pub const REG_CR2: ::c_int = 22;
658
421659 cfg_if! {
422660 if #[cfg(libc_align)] {
423661 mod align;
206206 pub mask: u32,
207207 pub cookie: u32,
208208 pub len: u32
209 }
210
211 pub struct sock_extended_err {
212 pub ee_errno: u32,
213 pub ee_origin: u8,
214 pub ee_type: u8,
215 pub ee_code: u8,
216 pub ee_pad: u8,
217 pub ee_info: u32,
218 pub ee_data: u32,
209219 }
210220 }
211221
830840 pub const LC_TELEPHONE: ::c_int = 10;
831841 pub const LC_MEASUREMENT: ::c_int = 11;
832842 pub const LC_IDENTIFICATION: ::c_int = 12;
833 pub const LC_PAPER_MASK: ::c_int = (1 << LC_PAPER);
834 pub const LC_NAME_MASK: ::c_int = (1 << LC_NAME);
835 pub const LC_ADDRESS_MASK: ::c_int = (1 << LC_ADDRESS);
836 pub const LC_TELEPHONE_MASK: ::c_int = (1 << LC_TELEPHONE);
837 pub const LC_MEASUREMENT_MASK: ::c_int = (1 << LC_MEASUREMENT);
838 pub const LC_IDENTIFICATION_MASK: ::c_int = (1 << LC_IDENTIFICATION);
843 pub const LC_PAPER_MASK: ::c_int = 1 << LC_PAPER;
844 pub const LC_NAME_MASK: ::c_int = 1 << LC_NAME;
845 pub const LC_ADDRESS_MASK: ::c_int = 1 << LC_ADDRESS;
846 pub const LC_TELEPHONE_MASK: ::c_int = 1 << LC_TELEPHONE;
847 pub const LC_MEASUREMENT_MASK: ::c_int = 1 << LC_MEASUREMENT;
848 pub const LC_IDENTIFICATION_MASK: ::c_int = 1 << LC_IDENTIFICATION;
839849 pub const LC_ALL_MASK: ::c_int = ::LC_CTYPE_MASK
840850 | ::LC_NUMERIC_MASK
841851 | ::LC_TIME_MASK
10961106 pub const F_RDLCK: ::c_int = 0;
10971107 pub const F_WRLCK: ::c_int = 1;
10981108 pub const F_UNLCK: ::c_int = 2;
1109 pub const F_OFD_GETLK: ::c_int = 36;
1110 pub const F_OFD_SETLK: ::c_int = 37;
1111 pub const F_OFD_SETLKW: ::c_int = 38;
10991112
11001113 pub const RLIMIT_CPU: ::c_int = 0;
11011114 pub const RLIMIT_FSIZE: ::c_int = 1;
11551168 pub const RTLD_NOLOAD: ::c_int = 0x4;
11561169
11571170 pub const SEM_FAILED: *mut sem_t = 0 as *mut sem_t;
1171
1172 pub const AI_PASSIVE: ::c_int = 0x00000001;
1173 pub const AI_CANONNAME: ::c_int = 0x00000002;
1174 pub const AI_NUMERICHOST: ::c_int = 0x00000004;
1175 pub const AI_NUMERICSERV: ::c_int = 0x00000008;
1176 pub const AI_MASK: ::c_int = AI_PASSIVE
1177 | AI_CANONNAME
1178 | AI_NUMERICHOST
1179 | AI_NUMERICSERV
1180 | AI_ADDRCONFIG;
1181 pub const AI_ALL: ::c_int = 0x00000100;
1182 pub const AI_V4MAPPED_CFG: ::c_int = 0x00000200;
1183 pub const AI_ADDRCONFIG: ::c_int = 0x00000400;
1184 pub const AI_V4MAPPED: ::c_int = 0x00000800;
1185 pub const AI_DEFAULT: ::c_int = AI_V4MAPPED_CFG | AI_ADDRCONFIG;
11581186
11591187 pub const LINUX_REBOOT_MAGIC1: ::c_int = 0xfee1dead;
11601188 pub const LINUX_REBOOT_MAGIC2: ::c_int = 672274793;
13951423 pub const NFULNL_CFG_F_SEQ_GLOBAL: ::c_int = 0x0002;
13961424 pub const NFULNL_CFG_F_CONNTRACK: ::c_int = 0x0004;
13971425
1426 // linux/netfilter/nfnetlink_log.h
1427 pub const NFQNL_MSG_PACKET: ::c_int = 0;
1428 pub const NFQNL_MSG_VERDICT: ::c_int = 1;
1429 pub const NFQNL_MSG_CONFIG: ::c_int = 2;
1430 pub const NFQNL_MSG_VERDICT_BATCH: ::c_int = 3;
1431
1432 pub const NFQA_UNSPEC: ::c_int = 0;
1433 pub const NFQA_PACKET_HDR: ::c_int = 1;
1434 pub const NFQA_VERDICT_HDR: ::c_int = 2;
1435 pub const NFQA_MARK: ::c_int = 3;
1436 pub const NFQA_TIMESTAMP: ::c_int = 4;
1437 pub const NFQA_IFINDEX_INDEV: ::c_int = 5;
1438 pub const NFQA_IFINDEX_OUTDEV: ::c_int = 6;
1439 pub const NFQA_IFINDEX_PHYSINDEV: ::c_int = 7;
1440 pub const NFQA_IFINDEX_PHYSOUTDEV: ::c_int = 8;
1441 pub const NFQA_HWADDR: ::c_int = 9;
1442 pub const NFQA_PAYLOAD: ::c_int = 10;
1443 pub const NFQA_CT: ::c_int = 11;
1444 pub const NFQA_CT_INFO: ::c_int = 12;
1445 pub const NFQA_CAP_LEN: ::c_int = 13;
1446 pub const NFQA_SKB_INFO: ::c_int = 14;
1447 pub const NFQA_EXP: ::c_int = 15;
1448 pub const NFQA_UID: ::c_int = 16;
1449 pub const NFQA_GID: ::c_int = 17;
1450 pub const NFQA_SECCTX: ::c_int = 18;
1451 /*
1452 FIXME: These are not yet available in musl sanitized kernel headers and
1453 make the tests fail. Enable them once musl has them.
1454
1455 See https://github.com/rust-lang/libc/pull/1628 for more details.
1456 pub const NFQA_VLAN: ::c_int = 19;
1457 pub const NFQA_L2HDR: ::c_int = 20;
1458
1459 pub const NFQA_VLAN_UNSPEC: ::c_int = 0;
1460 pub const NFQA_VLAN_PROTO: ::c_int = 1;
1461 pub const NFQA_VLAN_TCI: ::c_int = 2;
1462 */
1463
1464 pub const NFQNL_CFG_CMD_NONE: ::c_int = 0;
1465 pub const NFQNL_CFG_CMD_BIND: ::c_int = 1;
1466 pub const NFQNL_CFG_CMD_UNBIND: ::c_int = 2;
1467 pub const NFQNL_CFG_CMD_PF_BIND: ::c_int = 3;
1468 pub const NFQNL_CFG_CMD_PF_UNBIND: ::c_int = 4;
1469
1470 pub const NFQNL_COPY_NONE: ::c_int = 0;
1471 pub const NFQNL_COPY_META: ::c_int = 1;
1472 pub const NFQNL_COPY_PACKET: ::c_int = 2;
1473
1474 pub const NFQA_CFG_UNSPEC: ::c_int = 0;
1475 pub const NFQA_CFG_CMD: ::c_int = 1;
1476 pub const NFQA_CFG_PARAMS: ::c_int = 2;
1477 pub const NFQA_CFG_QUEUE_MAXLEN: ::c_int = 3;
1478 pub const NFQA_CFG_MASK: ::c_int = 4;
1479 pub const NFQA_CFG_FLAGS: ::c_int = 5;
1480
1481 pub const NFQA_CFG_F_FAIL_OPEN: ::c_int = 0x0001;
1482 pub const NFQA_CFG_F_CONNTRACK: ::c_int = 0x0002;
1483 pub const NFQA_CFG_F_GSO: ::c_int = 0x0004;
1484 pub const NFQA_CFG_F_UID_GID: ::c_int = 0x0008;
1485 pub const NFQA_CFG_F_SECCTX: ::c_int = 0x0010;
1486 pub const NFQA_CFG_F_MAX: ::c_int = 0x0020;
1487
1488 pub const NFQA_SKB_CSUMNOTREADY: ::c_int = 0x0001;
1489 pub const NFQA_SKB_GSO: ::c_int = 0x0002;
1490 pub const NFQA_SKB_CSUM_NOTVERIFIED: ::c_int = 0x0004;
1491
13981492 pub const GENL_NAMSIZ: ::c_int = 16;
13991493
14001494 pub const GENL_MIN_ID: ::c_int = NLMSG_MIN_TYPE;
14871581 pub const SO_ORIGINAL_DST: ::c_int = 80;
14881582 pub const IP_ORIGDSTADDR: ::c_int = 20;
14891583 pub const IP_RECVORIGDSTADDR: ::c_int = IP_ORIGDSTADDR;
1584 pub const IPV6_FLOWINFO: ::c_int = 11;
14901585 pub const IPV6_ORIGDSTADDR: ::c_int = 74;
14911586 pub const IPV6_RECVORIGDSTADDR: ::c_int = IPV6_ORIGDSTADDR;
14921587 pub const IPV6_FLOWLABEL_MGR: ::c_int = 32;
15831678 pub const NF_IP6_PRI_SELINUX_LAST: ::c_int = 225;
15841679 pub const NF_IP6_PRI_CONNTRACK_HELPER: ::c_int = 300;
15851680 pub const NF_IP6_PRI_LAST: ::c_int = ::INT_MAX;
1681
1682 // linux/netfilter_ipv6/ip6_tables.h
1683 pub const IP6T_SO_ORIGINAL_DST: ::c_int = 80;
15861684
15871685 // linux/netfilter/nf_tables.h
15881686 pub const NFT_TABLE_MAXNAMELEN: ::c_int = 256;
16791777 pub const NFT_RANGE_EQ: ::c_int = 0;
16801778 pub const NFT_RANGE_NEQ: ::c_int = 1;
16811779
1682 pub const NFT_LOOKUP_F_INV: ::c_int = (1 << 0);
1780 pub const NFT_LOOKUP_F_INV: ::c_int = 1 << 0;
16831781
16841782 pub const NFT_DYNSET_OP_ADD: ::c_int = 0;
16851783 pub const NFT_DYNSET_OP_UPDATE: ::c_int = 1;
16861784
1687 pub const NFT_DYNSET_F_INV: ::c_int = (1 << 0);
1785 pub const NFT_DYNSET_F_INV: ::c_int = 1 << 0;
16881786
16891787 pub const NFT_PAYLOAD_LL_HEADER: ::c_int = 0;
16901788 pub const NFT_PAYLOAD_NETWORK_HEADER: ::c_int = 1;
17391837 pub const NFT_LIMIT_PKTS: ::c_int = 0;
17401838 pub const NFT_LIMIT_PKT_BYTES: ::c_int = 1;
17411839
1742 pub const NFT_LIMIT_F_INV: ::c_int = (1 << 0);
1840 pub const NFT_LIMIT_F_INV: ::c_int = 1 << 0;
17431841
17441842 pub const NFT_QUEUE_FLAG_BYPASS: ::c_int = 0x01;
17451843 pub const NFT_QUEUE_FLAG_CPU_FANOUT: ::c_int = 0x02;
17461844 pub const NFT_QUEUE_FLAG_MASK: ::c_int = 0x03;
17471845
1748 pub const NFT_QUOTA_F_INV: ::c_int = (1 << 0);
1846 pub const NFT_QUOTA_F_INV: ::c_int = 1 << 0;
17491847
17501848 pub const NFT_REJECT_ICMP_UNREACH: ::c_int = 0;
17511849 pub const NFT_REJECT_TCP_RST: ::c_int = 1;
19372035 pub const IN_ATTRIB: u32 = 0x0000_0004;
19382036 pub const IN_CLOSE_WRITE: u32 = 0x0000_0008;
19392037 pub const IN_CLOSE_NOWRITE: u32 = 0x0000_0010;
1940 pub const IN_CLOSE: u32 = (IN_CLOSE_WRITE | IN_CLOSE_NOWRITE);
2038 pub const IN_CLOSE: u32 = IN_CLOSE_WRITE | IN_CLOSE_NOWRITE;
19412039 pub const IN_OPEN: u32 = 0x0000_0020;
19422040 pub const IN_MOVED_FROM: u32 = 0x0000_0040;
19432041 pub const IN_MOVED_TO: u32 = 0x0000_0080;
1944 pub const IN_MOVE: u32 = (IN_MOVED_FROM | IN_MOVED_TO);
2042 pub const IN_MOVE: u32 = IN_MOVED_FROM | IN_MOVED_TO;
19452043 pub const IN_CREATE: u32 = 0x0000_0100;
19462044 pub const IN_DELETE: u32 = 0x0000_0200;
19472045 pub const IN_DELETE_SELF: u32 = 0x0000_0400;
19582056 pub const IN_ISDIR: u32 = 0x4000_0000;
19592057 pub const IN_ONESHOT: u32 = 0x8000_0000;
19602058
1961 pub const IN_ALL_EVENTS: u32 = (IN_ACCESS
2059 pub const IN_ALL_EVENTS: u32 = IN_ACCESS
19622060 | IN_MODIFY
19632061 | IN_ATTRIB
19642062 | IN_CLOSE_WRITE
19692067 | IN_DELETE
19702068 | IN_CREATE
19712069 | IN_DELETE_SELF
1972 | IN_MOVE_SELF);
2070 | IN_MOVE_SELF;
19732071
19742072 pub const IN_CLOEXEC: ::c_int = O_CLOEXEC;
19752073 pub const IN_NONBLOCK: ::c_int = O_NONBLOCK;
19932091 pub const FUTEX_CMD_MASK: ::c_int =
19942092 !(FUTEX_PRIVATE_FLAG | FUTEX_CLOCK_REALTIME);
19952093
2094 // linux/errqueue.h
2095 pub const SO_EE_ORIGIN_NONE: u8 = 0;
2096 pub const SO_EE_ORIGIN_LOCAL: u8 = 1;
2097 pub const SO_EE_ORIGIN_ICMP: u8 = 2;
2098 pub const SO_EE_ORIGIN_ICMP6: u8 = 3;
2099 pub const SO_EE_ORIGIN_TXSTATUS: u8 = 4;
2100 pub const SO_EE_ORIGIN_TIMESTAMPING: u8 = SO_EE_ORIGIN_TXSTATUS;
2101
2102 // errno.h
2103 pub const EPERM: ::c_int = 1;
2104 pub const ENOENT: ::c_int = 2;
2105 pub const ESRCH: ::c_int = 3;
2106 pub const EINTR: ::c_int = 4;
2107 pub const EIO: ::c_int = 5;
2108 pub const ENXIO: ::c_int = 6;
2109 pub const E2BIG: ::c_int = 7;
2110 pub const ENOEXEC: ::c_int = 8;
2111 pub const EBADF: ::c_int = 9;
2112 pub const ECHILD: ::c_int = 10;
2113 pub const EAGAIN: ::c_int = 11;
2114 pub const ENOMEM: ::c_int = 12;
2115 pub const EACCES: ::c_int = 13;
2116 pub const EFAULT: ::c_int = 14;
2117 pub const ENOTBLK: ::c_int = 15;
2118 pub const EBUSY: ::c_int = 16;
2119 pub const EEXIST: ::c_int = 17;
2120 pub const EXDEV: ::c_int = 18;
2121 pub const ENODEV: ::c_int = 19;
2122 pub const ENOTDIR: ::c_int = 20;
2123 pub const EISDIR: ::c_int = 21;
2124 pub const EINVAL: ::c_int = 22;
2125 pub const ENFILE: ::c_int = 23;
2126 pub const EMFILE: ::c_int = 24;
2127 pub const ENOTTY: ::c_int = 25;
2128 pub const ETXTBSY: ::c_int = 26;
2129 pub const EFBIG: ::c_int = 27;
2130 pub const ENOSPC: ::c_int = 28;
2131 pub const ESPIPE: ::c_int = 29;
2132 pub const EROFS: ::c_int = 30;
2133 pub const EMLINK: ::c_int = 31;
2134 pub const EPIPE: ::c_int = 32;
2135 pub const EDOM: ::c_int = 33;
2136 pub const ERANGE: ::c_int = 34;
2137 pub const EWOULDBLOCK: ::c_int = EAGAIN;
2138
19962139 f! {
19972140 pub fn CMSG_NXTHDR(mhdr: *const msghdr,
19982141 cmsg: *const cmsghdr) -> *mut cmsghdr {
20512194
20522195 pub fn NLA_ALIGN(len: ::c_int) -> ::c_int {
20532196 return ((len) + NLA_ALIGNTO - 1) & !(NLA_ALIGNTO - 1)
2197 }
2198
2199 pub fn SO_EE_OFFENDER(ee: *const ::sock_extended_err) -> *mut ::sockaddr {
2200 ee.offset(1) as *mut ::sockaddr
20542201 }
20552202 }
20562203
22612408 pub fn setfsgid(gid: ::gid_t) -> ::c_int;
22622409 pub fn setfsuid(uid: ::uid_t) -> ::c_int;
22632410 pub fn sigsuspend(mask: *const ::sigset_t) -> ::c_int;
2264 #[cfg_attr(target_os = "solaris", link_name = "__posix_getgrgid_r")]
22652411 pub fn getgrgid_r(
22662412 gid: ::gid_t,
22672413 grp: *mut ::group,
22692415 buflen: ::size_t,
22702416 result: *mut *mut ::group,
22712417 ) -> ::c_int;
2272 #[cfg_attr(
2273 all(target_os = "macos", target_arch = "x86"),
2274 link_name = "sigaltstack$UNIX2003"
2275 )]
2276 #[cfg_attr(target_os = "netbsd", link_name = "__sigaltstack14")]
22772418 pub fn sigaltstack(ss: *const stack_t, oss: *mut stack_t) -> ::c_int;
22782419 pub fn sem_close(sem: *mut sem_t) -> ::c_int;
2279 #[cfg_attr(target_os = "solaris", link_name = "__posix_getgrnam_r")]
22802420 pub fn getgrnam_r(
22812421 name: *const ::c_char,
22822422 grp: *mut ::group,
22842424 buflen: ::size_t,
22852425 result: *mut *mut ::group,
22862426 ) -> ::c_int;
2287 #[cfg_attr(
2288 all(target_os = "macos", target_arch = "x86"),
2289 link_name = "pthread_sigmask$UNIX2003"
2290 )]
22912427 pub fn pthread_sigmask(
22922428 how: ::c_int,
22932429 set: *const sigset_t,
22982434 pub fn pthread_kill(thread: ::pthread_t, sig: ::c_int) -> ::c_int;
22992435 pub fn sem_unlink(name: *const ::c_char) -> ::c_int;
23002436 pub fn daemon(nochdir: ::c_int, noclose: ::c_int) -> ::c_int;
2301 #[cfg_attr(target_os = "netbsd", link_name = "__getpwnam_r50")]
2302 #[cfg_attr(target_os = "solaris", link_name = "__posix_getpwnam_r")]
23032437 pub fn getpwnam_r(
23042438 name: *const ::c_char,
23052439 pwd: *mut passwd,
23072441 buflen: ::size_t,
23082442 result: *mut *mut passwd,
23092443 ) -> ::c_int;
2310 #[cfg_attr(target_os = "netbsd", link_name = "__getpwuid_r50")]
2311 #[cfg_attr(target_os = "solaris", link_name = "__posix_getpwuid_r")]
23122444 pub fn getpwuid_r(
23132445 uid: ::uid_t,
23142446 pwd: *mut passwd,
23162448 buflen: ::size_t,
23172449 result: *mut *mut passwd,
23182450 ) -> ::c_int;
2319 #[cfg_attr(
2320 all(target_os = "macos", target_arch = "x86"),
2321 link_name = "sigwait$UNIX2003"
2322 )]
2323 #[cfg_attr(target_os = "solaris", link_name = "__posix_sigwait")]
23242451 pub fn sigwait(set: *const sigset_t, sig: *mut ::c_int) -> ::c_int;
23252452 pub fn pthread_atfork(
23262453 prepare: ::Option<unsafe extern "C" fn()>,
23392466 attr: *const pthread_mutexattr_t,
23402467 pshared: *mut ::c_int,
23412468 ) -> ::c_int;
2342 #[cfg_attr(
2343 all(target_os = "macos", target_arch = "x86"),
2344 link_name = "popen$UNIX2003"
2345 )]
23462469 pub fn popen(command: *const c_char, mode: *const c_char) -> *mut ::FILE;
23472470 pub fn faccessat(
23482471 dirfd: ::c_int,
3737 }
3838
3939 #[allow(missing_debug_implementations)]
40 #[repr(align(8))]
40 #[repr(align(16))]
4141 pub struct max_align_t {
42 priv_: [f64; 2]
42 priv_: [f64; 4]
4343 }
4444
4545 }
3434 pub type nlink_t = u32;
3535
3636 #[cfg_attr(feature = "extra_traits", derive(Debug))]
37 pub enum fpos64_t {} // TODO: fill this out with a struct
37 pub enum fpos64_t {} // FIXME: fill this out with a struct
3838 impl ::Copy for fpos64_t {}
3939 impl ::Clone for fpos64_t {
4040 fn clone(&self) -> fpos64_t {
11731173 pub const O_NOATIME: ::c_int = 0o1000000;
11741174 pub const O_CLOEXEC: ::c_int = 0x80000;
11751175
1176 pub const EBFONT: ::c_int = 59;
1177 pub const ENOSTR: ::c_int = 60;
1178 pub const ENODATA: ::c_int = 61;
1179 pub const ETIME: ::c_int = 62;
1180 pub const ENOSR: ::c_int = 63;
1181 pub const ENONET: ::c_int = 64;
1182 pub const ENOPKG: ::c_int = 65;
1183 pub const EREMOTE: ::c_int = 66;
1184 pub const ENOLINK: ::c_int = 67;
1185 pub const EADV: ::c_int = 68;
1186 pub const ESRMNT: ::c_int = 69;
1187 pub const ECOMM: ::c_int = 70;
1188 pub const EPROTO: ::c_int = 71;
1189 pub const EDOTDOT: ::c_int = 73;
1176 // Defined as wasi value.
1177 pub const EPERM: ::c_int = 63;
1178 pub const ENOENT: ::c_int = 44;
1179 pub const ESRCH: ::c_int = 71;
1180 pub const EINTR: ::c_int = 27;
1181 pub const EIO: ::c_int = 29;
1182 pub const ENXIO: ::c_int = 60;
1183 pub const E2BIG: ::c_int = 1;
1184 pub const ENOEXEC: ::c_int = 45;
1185 pub const EBADF: ::c_int = 8;
1186 pub const ECHILD: ::c_int = 12;
1187 pub const EAGAIN: ::c_int = 6;
1188 pub const ENOMEM: ::c_int = 48;
1189 pub const EACCES: ::c_int = 2;
1190 pub const EFAULT: ::c_int = 21;
1191 pub const ENOTBLK: ::c_int = 105;
1192 pub const EBUSY: ::c_int = 10;
1193 pub const EEXIST: ::c_int = 20;
1194 pub const EXDEV: ::c_int = 75;
1195 pub const ENODEV: ::c_int = 43;
1196 pub const ENOTDIR: ::c_int = 54;
1197 pub const EISDIR: ::c_int = 31;
1198 pub const EINVAL: ::c_int = 28;
1199 pub const ENFILE: ::c_int = 41;
1200 pub const EMFILE: ::c_int = 33;
1201 pub const ENOTTY: ::c_int = 59;
1202 pub const ETXTBSY: ::c_int = 74;
1203 pub const EFBIG: ::c_int = 22;
1204 pub const ENOSPC: ::c_int = 51;
1205 pub const ESPIPE: ::c_int = 70;
1206 pub const EROFS: ::c_int = 69;
1207 pub const EMLINK: ::c_int = 34;
1208 pub const EPIPE: ::c_int = 64;
1209 pub const EDOM: ::c_int = 18;
1210 pub const ERANGE: ::c_int = 68;
1211 pub const EWOULDBLOCK: ::c_int = EAGAIN;
1212 pub const ENOLINK: ::c_int = 47;
1213 pub const EPROTO: ::c_int = 65;
1214 pub const EDEADLK: ::c_int = 16;
1215 pub const EDEADLOCK: ::c_int = EDEADLK;
1216 pub const ENAMETOOLONG: ::c_int = 37;
1217 pub const ENOLCK: ::c_int = 46;
1218 pub const ENOSYS: ::c_int = 52;
1219 pub const ENOTEMPTY: ::c_int = 55;
1220 pub const ELOOP: ::c_int = 32;
1221 pub const ENOMSG: ::c_int = 49;
1222 pub const EIDRM: ::c_int = 24;
1223 pub const EMULTIHOP: ::c_int = 36;
1224 pub const EBADMSG: ::c_int = 9;
1225 pub const EOVERFLOW: ::c_int = 61;
1226 pub const EILSEQ: ::c_int = 25;
1227 pub const ENOTSOCK: ::c_int = 57;
1228 pub const EDESTADDRREQ: ::c_int = 17;
1229 pub const EMSGSIZE: ::c_int = 35;
1230 pub const EPROTOTYPE: ::c_int = 67;
1231 pub const ENOPROTOOPT: ::c_int = 50;
1232 pub const EPROTONOSUPPORT: ::c_int = 66;
1233 pub const EAFNOSUPPORT: ::c_int = 5;
1234 pub const EADDRINUSE: ::c_int = 3;
1235 pub const EADDRNOTAVAIL: ::c_int = 4;
1236 pub const ENETDOWN: ::c_int = 38;
1237 pub const ENETUNREACH: ::c_int = 40;
1238 pub const ENETRESET: ::c_int = 39;
1239 pub const ECONNABORTED: ::c_int = 13;
1240 pub const ECONNRESET: ::c_int = 15;
1241 pub const ENOBUFS: ::c_int = 42;
1242 pub const EISCONN: ::c_int = 30;
1243 pub const ENOTCONN: ::c_int = 53;
1244 pub const ETIMEDOUT: ::c_int = 73;
1245 pub const ECONNREFUSED: ::c_int = 14;
1246 pub const EHOSTUNREACH: ::c_int = 23;
1247 pub const EALREADY: ::c_int = 7;
1248 pub const EINPROGRESS: ::c_int = 26;
1249 pub const ESTALE: ::c_int = 72;
1250 pub const EDQUOT: ::c_int = 19;
1251 pub const ECANCELED: ::c_int = 11;
1252 pub const EOWNERDEAD: ::c_int = 62;
1253 pub const ENOTRECOVERABLE: ::c_int = 56;
1254
1255 pub const ENOSTR: ::c_int = 100;
1256 pub const EBFONT: ::c_int = 101;
1257 pub const EBADSLT: ::c_int = 102;
1258 pub const EBADRQC: ::c_int = 103;
1259 pub const ENOANO: ::c_int = 104;
1260 pub const ECHRNG: ::c_int = 106;
1261 pub const EL3HLT: ::c_int = 107;
1262 pub const EL3RST: ::c_int = 108;
1263 pub const ELNRNG: ::c_int = 109;
1264 pub const EUNATCH: ::c_int = 110;
1265 pub const ENOCSI: ::c_int = 111;
1266 pub const EL2HLT: ::c_int = 112;
1267 pub const EBADE: ::c_int = 113;
1268 pub const EBADR: ::c_int = 114;
1269 pub const EXFULL: ::c_int = 115;
1270 pub const ENODATA: ::c_int = 116;
1271 pub const ETIME: ::c_int = 117;
1272 pub const ENOSR: ::c_int = 118;
1273 pub const ENONET: ::c_int = 119;
1274 pub const ENOPKG: ::c_int = 120;
1275 pub const EREMOTE: ::c_int = 121;
1276 pub const EADV: ::c_int = 122;
1277 pub const ESRMNT: ::c_int = 123;
1278 pub const ECOMM: ::c_int = 124;
1279 pub const EDOTDOT: ::c_int = 125;
1280 pub const ENOTUNIQ: ::c_int = 126;
1281 pub const EBADFD: ::c_int = 127;
1282 pub const EREMCHG: ::c_int = 128;
1283 pub const ELIBACC: ::c_int = 129;
1284 pub const ELIBBAD: ::c_int = 130;
1285 pub const ELIBSCN: ::c_int = 131;
1286 pub const ELIBMAX: ::c_int = 132;
1287 pub const ELIBEXEC: ::c_int = 133;
1288 pub const ERESTART: ::c_int = 134;
1289 pub const ESTRPIPE: ::c_int = 135;
1290 pub const EUSERS: ::c_int = 136;
1291 pub const ESOCKTNOSUPPORT: ::c_int = 137;
1292 pub const EOPNOTSUPP: ::c_int = 138;
1293 pub const ENOTSUP: ::c_int = EOPNOTSUPP;
1294 pub const EPFNOSUPPORT: ::c_int = 139;
1295 pub const ESHUTDOWN: ::c_int = 140;
1296 pub const ETOOMANYREFS: ::c_int = 141;
1297 pub const EHOSTDOWN: ::c_int = 142;
1298 pub const EUCLEAN: ::c_int = 143;
1299 pub const ENOTNAM: ::c_int = 144;
1300 pub const ENAVAIL: ::c_int = 145;
1301 pub const EISNAM: ::c_int = 146;
1302 pub const EREMOTEIO: ::c_int = 147;
1303 pub const ENOMEDIUM: ::c_int = 148;
1304 pub const EMEDIUMTYPE: ::c_int = 149;
1305 pub const ENOKEY: ::c_int = 150;
1306 pub const EKEYEXPIRED: ::c_int = 151;
1307 pub const EKEYREVOKED: ::c_int = 152;
1308 pub const EKEYREJECTED: ::c_int = 153;
1309 pub const ERFKILL: ::c_int = 154;
1310 pub const EHWPOISON: ::c_int = 155;
1311 pub const EL2NSYNC: ::c_int = 156;
11901312
11911313 pub const SA_NODEFER: ::c_int = 0x40000000;
11921314 pub const SA_RESETHAND: ::c_int = 0x80000000;
12851407 pub const RTLD_GLOBAL: ::c_int = 0x100;
12861408 pub const RTLD_NOLOAD: ::c_int = 0x4;
12871409
1288 // TODO(#247) Temporarily musl-specific (available since musl 0.9.12 / Linux
1289 // kernel 3.10). See also linux_like/mod.rs
12901410 pub const CLOCK_SGI_CYCLE: ::clockid_t = 10;
1291 pub const CLOCK_TAI: ::clockid_t = 11;
12921411
12931412 pub const MCL_CURRENT: ::c_int = 0x0001;
12941413 pub const MCL_FUTURE: ::c_int = 0x0002;
14391558
14401559 pub const SOL_SOCKET: ::c_int = 1;
14411560
1442 pub const EDEADLK: ::c_int = 35;
1443 pub const ENAMETOOLONG: ::c_int = 36;
1444 pub const ENOLCK: ::c_int = 37;
1445 pub const ENOSYS: ::c_int = 38;
1446 pub const ENOTEMPTY: ::c_int = 39;
1447 pub const ELOOP: ::c_int = 40;
1448 pub const ENOMSG: ::c_int = 42;
1449 pub const EIDRM: ::c_int = 43;
1450 pub const ECHRNG: ::c_int = 44;
1451 pub const EL2NSYNC: ::c_int = 45;
1452 pub const EL3HLT: ::c_int = 46;
1453 pub const EL3RST: ::c_int = 47;
1454 pub const ELNRNG: ::c_int = 48;
1455 pub const EUNATCH: ::c_int = 49;
1456 pub const ENOCSI: ::c_int = 50;
1457 pub const EL2HLT: ::c_int = 51;
1458 pub const EBADE: ::c_int = 52;
1459 pub const EBADR: ::c_int = 53;
1460 pub const EXFULL: ::c_int = 54;
1461 pub const ENOANO: ::c_int = 55;
1462 pub const EBADRQC: ::c_int = 56;
1463 pub const EBADSLT: ::c_int = 57;
1464 pub const EDEADLOCK: ::c_int = EDEADLK;
1465 pub const EMULTIHOP: ::c_int = 72;
1466 pub const EBADMSG: ::c_int = 74;
1467 pub const EOVERFLOW: ::c_int = 75;
1468 pub const ENOTUNIQ: ::c_int = 76;
1469 pub const EBADFD: ::c_int = 77;
1470 pub const EREMCHG: ::c_int = 78;
1471 pub const ELIBACC: ::c_int = 79;
1472 pub const ELIBBAD: ::c_int = 80;
1473 pub const ELIBSCN: ::c_int = 81;
1474 pub const ELIBMAX: ::c_int = 82;
1475 pub const ELIBEXEC: ::c_int = 83;
1476 pub const EILSEQ: ::c_int = 84;
1477 pub const ERESTART: ::c_int = 85;
1478 pub const ESTRPIPE: ::c_int = 86;
1479 pub const EUSERS: ::c_int = 87;
1480 pub const ENOTSOCK: ::c_int = 88;
1481 pub const EDESTADDRREQ: ::c_int = 89;
1482 pub const EMSGSIZE: ::c_int = 90;
1483 pub const EPROTOTYPE: ::c_int = 91;
1484 pub const ENOPROTOOPT: ::c_int = 92;
1485 pub const EPROTONOSUPPORT: ::c_int = 93;
1486 pub const ESOCKTNOSUPPORT: ::c_int = 94;
1487 pub const EOPNOTSUPP: ::c_int = 95;
1488 pub const ENOTSUP: ::c_int = EOPNOTSUPP;
1489 pub const EPFNOSUPPORT: ::c_int = 96;
1490 pub const EAFNOSUPPORT: ::c_int = 97;
1491 pub const EADDRINUSE: ::c_int = 98;
1492 pub const EADDRNOTAVAIL: ::c_int = 99;
1493 pub const ENETDOWN: ::c_int = 100;
1494 pub const ENETUNREACH: ::c_int = 101;
1495 pub const ENETRESET: ::c_int = 102;
1496 pub const ECONNABORTED: ::c_int = 103;
1497 pub const ECONNRESET: ::c_int = 104;
1498 pub const ENOBUFS: ::c_int = 105;
1499 pub const EISCONN: ::c_int = 106;
1500 pub const ENOTCONN: ::c_int = 107;
1501 pub const ESHUTDOWN: ::c_int = 108;
1502 pub const ETOOMANYREFS: ::c_int = 109;
1503 pub const ETIMEDOUT: ::c_int = 110;
1504 pub const ECONNREFUSED: ::c_int = 111;
1505 pub const EHOSTDOWN: ::c_int = 112;
1506 pub const EHOSTUNREACH: ::c_int = 113;
1507 pub const EALREADY: ::c_int = 114;
1508 pub const EINPROGRESS: ::c_int = 115;
1509 pub const ESTALE: ::c_int = 116;
1510 pub const EUCLEAN: ::c_int = 117;
1511 pub const ENOTNAM: ::c_int = 118;
1512 pub const ENAVAIL: ::c_int = 119;
1513 pub const EISNAM: ::c_int = 120;
1514 pub const EREMOTEIO: ::c_int = 121;
1515 pub const EDQUOT: ::c_int = 122;
1516 pub const ENOMEDIUM: ::c_int = 123;
1517 pub const EMEDIUMTYPE: ::c_int = 124;
1518 pub const ECANCELED: ::c_int = 125;
1519 pub const ENOKEY: ::c_int = 126;
1520 pub const EKEYEXPIRED: ::c_int = 127;
1521 pub const EKEYREVOKED: ::c_int = 128;
1522 pub const EKEYREJECTED: ::c_int = 129;
1523 pub const EOWNERDEAD: ::c_int = 130;
1524 pub const ENOTRECOVERABLE: ::c_int = 131;
1525 pub const ERFKILL: ::c_int = 132;
1526 pub const EHWPOISON: ::c_int = 133;
1527
15281561 pub const SO_REUSEADDR: ::c_int = 2;
15291562 pub const SO_TYPE: ::c_int = 3;
15301563 pub const SO_ERROR: ::c_int = 4;
15791612 pub const F_SETLK: ::c_int = 13;
15801613 pub const F_SETLKW: ::c_int = 14;
15811614 pub const F_SETOWN: ::c_int = 8;
1615 pub const F_OFD_GETLK: ::c_int = 36;
1616 pub const F_OFD_SETLK: ::c_int = 37;
1617 pub const F_OFD_SETLKW: ::c_int = 38;
15821618
15831619 pub const VEOF: usize = 4;
15841620 pub const VEOL: usize = 11;
16951731
16961732 pub fn major(dev: ::dev_t) -> ::c_uint {
16971733 // see
1698 // https://github.com/kripken/emscripten/blob/
1734 // https://github.com/emscripten-core/emscripten/blob/
16991735 // master/system/include/libc/sys/sysmacros.h
17001736 let mut major = 0;
17011737 major |= (dev & 0x00000fff) >> 8;
17051741
17061742 pub fn minor(dev: ::dev_t) -> ::c_uint {
17071743 // see
1708 // https://github.com/kripken/emscripten/blob/
1744 // https://github.com/emscripten-core/emscripten/blob/
17091745 // master/system/include/libc/sys/sysmacros.h
17101746 let mut minor = 0;
17111747 minor |= (dev & 0x000000ff) >> 0;
66 target_arch = "mips64",
77 target_arch = "s390x",
88 target_arch = "sparc64",
9 target_arch = "aarch64"),
9 target_arch = "aarch64",
10 target_arch = "riscv64"),
1011 repr(align(4)))]
1112 #[cfg_attr(not(any(target_pointer_width = "32",
1213 target_arch = "x86_64",
1415 target_arch = "mips64",
1516 target_arch = "s390x",
1617 target_arch = "sparc64",
17 target_arch = "aarch64")),
18 target_arch = "aarch64",
19 target_arch = "riscv64")),
1820 repr(align(8)))]
1921 pub struct pthread_mutexattr_t {
2022 #[doc(hidden)]
3537 pub struct pthread_condattr_t {
3638 #[doc(hidden)]
3739 size: [u8; ::__SIZEOF_PTHREAD_CONDATTR_T],
40 }
41
42 #[repr(align(8))]
43 pub struct fanotify_event_metadata {
44 pub event_len: __u32,
45 pub vers: __u8,
46 pub reserved: __u8,
47 pub metadata_len: __u16,
48 pub mask: __u64,
49 pub fd: ::c_int,
50 pub pid: ::c_int,
3851 }
3952 }
4053
211211 pub const MAP_STACK: ::c_int = 0x020000;
212212 pub const MAP_HUGETLB: ::c_int = 0x040000;
213213 pub const MAP_GROWSDOWN: ::c_int = 0x0100;
214 pub const MAP_SYNC : ::c_int = 0x080000;
214215
215216 pub const SOL_SOCKET: ::c_int = 1;
216217
142142 pub const F_WRLCK: ::c_int = 1;
143143 pub const F_UNLCK: ::c_int = 2;
144144
145 pub const F_OFD_GETLK: ::c_int = 36;
146 pub const F_OFD_SETLK: ::c_int = 37;
147 pub const F_OFD_SETLKW: ::c_int = 38;
148
145149 pub const SFD_CLOEXEC: ::c_int = 0x080000;
146150
147151 pub const NCCS: usize = 32;
212212 pub const MAP_STACK: ::c_int = 0x020000;
213213 pub const MAP_HUGETLB: ::c_int = 0x040000;
214214 pub const MAP_GROWSDOWN: ::c_int = 0x0100;
215 pub const MAP_SYNC : ::c_int = 0x080000;
215216
216217 pub const SOL_SOCKET: ::c_int = 1;
217218
244244 pub const MAP_NONBLOCK: ::c_int = 0x010000;
245245 pub const MAP_STACK: ::c_int = 0x020000;
246246 pub const MAP_HUGETLB: ::c_int = 0x040000;
247 pub const MAP_SYNC : ::c_int = 0x080000;
247248
248249 pub const EDEADLK: ::c_int = 78;
249250 pub const ENAMETOOLONG: ::c_int = 63;
394395 pub const F_SETOWN: ::c_int = 6;
395396 pub const F_SETLK: ::c_int = 8;
396397 pub const F_SETLKW: ::c_int = 9;
398 pub const F_OFD_GETLK: ::c_int = 36;
399 pub const F_OFD_SETLK: ::c_int = 37;
400 pub const F_OFD_SETLKW: ::c_int = 38;
397401
398402 pub const F_RDLCK: ::c_int = 1;
399403 pub const F_WRLCK: ::c_int = 2;
415415 pub const MAP_STACK: ::c_int = 0x020000;
416416 pub const MAP_HUGETLB: ::c_int = 0x040000;
417417 pub const MAP_GROWSDOWN: ::c_int = 0x0100;
418 pub const MAP_SYNC : ::c_int = 0x080000;
418419
419420 pub const EDEADLOCK: ::c_int = 35;
420421 pub const EUCLEAN: ::c_int = 117;
44 priv_: [f32; 8]
55 }
66 }
7
8 s! {
9 pub struct ucontext_t {
10 pub uc_flags: ::c_ulong,
11 pub uc_link: *mut ucontext_t,
12 pub uc_stack: ::stack_t,
13 pub uc_sigmask: ::sigset_t,
14 pub uc_mcontext: mcontext_t,
15 }
16
17 #[repr(align(16))]
18 pub struct mcontext_t {
19 pub fault_address: ::c_ulonglong,
20 pub regs: [::c_ulonglong; 31],
21 pub sp: ::c_ulonglong,
22 pub pc: ::c_ulonglong,
23 pub pstate: ::c_ulonglong,
24 // nested arrays to get the right size/length while being able to
25 // auto-derive traits like Debug
26 __reserved: [[u64; 32]; 16],
27 }
28 }
428428 pub const F_SETOWN: ::c_int = 8;
429429 pub const F_SETLK: ::c_int = 6;
430430 pub const F_SETLKW: ::c_int = 7;
431 pub const F_OFD_GETLK: ::c_int = 36;
432 pub const F_OFD_SETLK: ::c_int = 37;
433 pub const F_OFD_SETLKW: ::c_int = 38;
431434
432435 pub const F_RDLCK: ::c_int = 0;
433436 pub const F_WRLCK: ::c_int = 1;
529532 pub const MAP_NONBLOCK: ::c_int = 0x010000;
530533 pub const MAP_STACK: ::c_int = 0x020000;
531534 pub const MAP_HUGETLB: ::c_int = 0x040000;
535 pub const MAP_SYNC: ::c_int = 0x080000;
532536
533537 pub const EDEADLOCK: ::c_int = 35;
534538
660664
661665 pub const TIOCLINUX: ::c_ulong = 0x541C;
662666 pub const TIOCGSERIAL: ::c_ulong = 0x541E;
667
668 // sys/auxv.h
669 pub const HWCAP_FP: ::c_ulong = 1 << 0;
670 pub const HWCAP_ASIMD: ::c_ulong = 1 << 1;
671 pub const HWCAP_EVTSTRM: ::c_ulong = 1 << 2;
672 pub const HWCAP_AES: ::c_ulong = 1 << 3;
673 pub const HWCAP_PMULL: ::c_ulong = 1 << 4;
674 pub const HWCAP_SHA1: ::c_ulong = 1 << 5;
675 pub const HWCAP_SHA2: ::c_ulong = 1 << 6;
676 pub const HWCAP_CRC32: ::c_ulong = 1 << 7;
677 pub const HWCAP_ATOMICS: ::c_ulong = 1 << 8;
678 pub const HWCAP_FPHP: ::c_ulong = 1 << 9;
679 pub const HWCAP_ASIMDHP: ::c_ulong = 1 << 10;
680 pub const HWCAP_CPUID: ::c_ulong = 1 << 11;
681 pub const HWCAP_ASIMDRDM: ::c_ulong = 1 << 12;
682 pub const HWCAP_JSCVT: ::c_ulong = 1 << 13;
683 pub const HWCAP_FCMA: ::c_ulong = 1 << 14;
684 pub const HWCAP_LRCPC: ::c_ulong = 1 << 15;
685 pub const HWCAP_DCPOP: ::c_ulong = 1 << 16;
686 pub const HWCAP_SHA3: ::c_ulong = 1 << 17;
687 pub const HWCAP_SM3: ::c_ulong = 1 << 18;
688 pub const HWCAP_SM4: ::c_ulong = 1 << 19;
689 pub const HWCAP_ASIMDDP: ::c_ulong = 1 << 20;
690 pub const HWCAP_SHA512: ::c_ulong = 1 << 21;
691 pub const HWCAP_SVE: ::c_ulong = 1 << 22;
692 pub const HWCAP_ASIMDFHM: ::c_ulong = 1 << 23;
693 pub const HWCAP_DIT: ::c_ulong = 1 << 24;
694 pub const HWCAP_USCAT: ::c_ulong = 1 << 25;
695 pub const HWCAP_ILRCPC: ::c_ulong = 1 << 26;
696 pub const HWCAP_FLAGM: ::c_ulong = 1 << 27;
697 pub const HWCAP_SSBS: ::c_ulong = 1 << 28;
698 pub const HWCAP_SB: ::c_ulong = 1 << 29;
699 pub const HWCAP_PACA: ::c_ulong = 1 << 30;
700 pub const HWCAP_PACG: ::c_ulong = 1 << 31;
701 // FIXME: enable these again once linux-api-headers are up to date enough on CI.
702 // See discussion in https://github.com/rust-lang/libc/pull/1638
703 //pub const HWCAP2_DCPODP: ::c_ulong = 1 << 0;
704 //pub const HWCAP2_SVE2: ::c_ulong = 1 << 1;
705 //pub const HWCAP2_SVEAES: ::c_ulong = 1 << 2;
706 //pub const HWCAP2_SVEPMULL: ::c_ulong = 1 << 3;
707 //pub const HWCAP2_SVEBITPERM: ::c_ulong = 1 << 4;
708 //pub const HWCAP2_SVESHA3: ::c_ulong = 1 << 5;
709 //pub const HWCAP2_SVESM4: ::c_ulong = 1 << 6;
710 //pub const HWCAP2_FLAGM2: ::c_ulong = 1 << 7;
711 //pub const HWCAP2_FRINT: ::c_ulong = 1 << 8;
663712
664713 // Syscall table
665714 pub const SYS_io_setup: ::c_long = 0;
856856 pub const F_SETOWN: ::c_int = 24;
857857 pub const F_SETLK: ::c_int = 6;
858858 pub const F_SETLKW: ::c_int = 7;
859 pub const F_OFD_GETLK: ::c_int = 36;
860 pub const F_OFD_SETLK: ::c_int = 37;
861 pub const F_OFD_SETLKW: ::c_int = 38;
859862
860863 pub const SFD_NONBLOCK: ::c_int = 0x80;
861864
415415 pub const F_SETOWN: ::c_int = 8;
416416 pub const F_SETLK: ::c_int = 6;
417417 pub const F_SETLKW: ::c_int = 7;
418 pub const F_OFD_GETLK: ::c_int = 36;
419 pub const F_OFD_SETLK: ::c_int = 37;
420 pub const F_OFD_SETLKW: ::c_int = 38;
418421
419422 pub const F_RDLCK: ::c_int = 0;
420423 pub const F_WRLCK: ::c_int = 1;
540543
541544 pub const MAP_LOCKED: ::c_int = 0x00080;
542545 pub const MAP_NORESERVE: ::c_int = 0x00040;
546 pub const MAP_SYNC : ::c_int = 0x080000;
543547
544548 pub const EDEADLOCK: ::c_int = 58;
545549 pub const EUCLEAN: ::c_int = 117;
204204 pub l_len: ::off_t,
205205 pub l_pid: ::pid_t,
206206 }
207
208 pub struct flock64 {
209 pub l_type: ::c_short,
210 pub l_whence: ::c_short,
211 pub l_start: ::off64_t,
212 pub l_len: ::off64_t,
213 pub l_pid: ::pid_t,
214 }
207215 }
208216
209217 pub const POSIX_FADV_DONTNEED: ::c_int = 4;
210218 pub const POSIX_FADV_NOREUSE: ::c_int = 5;
211219 pub const VEOF: usize = 4;
220 pub const RTLD_DEEPBIND: ::c_int = 0x8;
221 pub const RTLD_GLOBAL: ::c_int = 0x100;
222 pub const RTLD_NOLOAD: ::c_int = 0x4;
212223 pub const TIOCGSOFTCAR: ::c_ulong = 21529;
213224 pub const TIOCSSOFTCAR: ::c_ulong = 21530;
214225 pub const TIOCGRS485: ::c_int = 21550;
399410 pub const F_RDLCK: ::c_int = 0;
400411 pub const F_WRLCK: ::c_int = 1;
401412 pub const F_UNLCK: ::c_int = 2;
413 pub const F_OFD_GETLK: ::c_int = 36;
414 pub const F_OFD_SETLK: ::c_int = 37;
415 pub const F_OFD_SETLKW: ::c_int = 38;
402416 pub const SFD_NONBLOCK: ::c_int = 2048;
403417 pub const TCSANOW: ::c_int = 0;
404418 pub const TCSADRAIN: ::c_int = 1;
459473 pub const MAP_POPULATE: ::c_int = 32768;
460474 pub const MAP_NONBLOCK: ::c_int = 65536;
461475 pub const MAP_STACK: ::c_int = 131072;
476 pub const MAP_SYNC : ::c_int = 0x080000;
462477 pub const EDEADLOCK: ::c_int = 35;
463478 pub const EUCLEAN: ::c_int = 117;
464479 pub const ENOTNAM: ::c_int = 118;
539539 pub const F_SETOWN: ::c_int = 8;
540540 pub const F_SETLK: ::c_int = 6;
541541 pub const F_SETLKW: ::c_int = 7;
542 pub const F_OFD_GETLK: ::c_int = 36;
543 pub const F_OFD_SETLK: ::c_int = 37;
544 pub const F_OFD_SETLKW: ::c_int = 38;
542545
543546 pub const SFD_NONBLOCK: ::c_int = 0x0800;
544547
246246 pub const MAP_NONBLOCK: ::c_int = 0x010000;
247247 pub const MAP_STACK: ::c_int = 0x020000;
248248 pub const MAP_HUGETLB: ::c_int = 0x040000;
249 pub const MAP_SYNC : ::c_int = 0x080000;
249250
250251 pub const EDEADLK: ::c_int = 78;
251252 pub const ENAMETOOLONG: ::c_int = 63;
396397 pub const F_SETOWN: ::c_int = 6;
397398 pub const F_SETLK: ::c_int = 8;
398399 pub const F_SETLKW: ::c_int = 9;
400 pub const F_OFD_GETLK: ::c_int = 36;
401 pub const F_OFD_SETLK: ::c_int = 37;
402 pub const F_OFD_SETLKW: ::c_int = 38;
399403
400404 pub const F_RDLCK: ::c_int = 1;
401405 pub const F_WRLCK: ::c_int = 2;
617617 pub const F_SETOWN: ::c_int = 8;
618618 pub const F_SETLK: ::c_int = 6;
619619 pub const F_SETLKW: ::c_int = 7;
620 pub const F_OFD_GETLK: ::c_int = 36;
621 pub const F_OFD_SETLK: ::c_int = 37;
622 pub const F_OFD_SETLKW: ::c_int = 38;
620623
621624 pub const F_RDLCK: ::c_int = 0;
622625 pub const F_WRLCK: ::c_int = 1;
697700 pub const MAP_POPULATE: ::c_int = 0x08000;
698701 pub const MAP_NONBLOCK: ::c_int = 0x010000;
699702 pub const MAP_STACK: ::c_int = 0x020000;
703 pub const MAP_SYNC : ::c_int = 0x080000;
700704
701705 pub const EDEADLOCK: ::c_int = 35;
702706 pub const EUCLEAN: ::c_int = 117;
00 pub type pthread_t = c_ulong;
11 pub type __priority_which_t = ::c_uint;
22 pub type __rlimit_resource_t = ::c_uint;
3 pub type Lmid_t = ::c_long;
4 pub type regoff_t = ::c_int;
35
46 s! {
57 pub struct statx {
181183 pub rt_window: ::c_ulong,
182184 pub rt_irtt: ::c_ushort,
183185 }
186
187 pub struct timex {
188 pub modes: ::c_uint,
189 #[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
190 pub offset: i64,
191 #[cfg(not(all(target_arch = "x86_64", target_pointer_width = "32")))]
192 pub offset: ::c_long,
193 #[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
194 pub freq: i64,
195 #[cfg(not(all(target_arch = "x86_64", target_pointer_width = "32")))]
196 pub freq: ::c_long,
197 #[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
198 pub maxerror: i64,
199 #[cfg(not(all(target_arch = "x86_64", target_pointer_width = "32")))]
200 pub maxerror: ::c_long,
201 #[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
202 pub esterror: i64,
203 #[cfg(not(all(target_arch = "x86_64", target_pointer_width = "32")))]
204 pub esterror: ::c_long,
205 pub status: ::c_int,
206 #[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
207 pub constant: i64,
208 #[cfg(not(all(target_arch = "x86_64", target_pointer_width = "32")))]
209 pub constant: ::c_long,
210 #[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
211 pub precision: i64,
212 #[cfg(not(all(target_arch = "x86_64", target_pointer_width = "32")))]
213 pub precision: ::c_long,
214 #[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
215 pub tolerance: i64,
216 #[cfg(not(all(target_arch = "x86_64", target_pointer_width = "32")))]
217 pub tolerance: ::c_long,
218 pub time: ::timeval,
219 #[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
220 pub tick: i64,
221 #[cfg(not(all(target_arch = "x86_64", target_pointer_width = "32")))]
222 pub tick: ::c_long,
223 #[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
224 pub ppsfreq: i64,
225 #[cfg(not(all(target_arch = "x86_64", target_pointer_width = "32")))]
226 pub ppsfreq: ::c_long,
227 #[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
228 pub jitter: i64,
229 #[cfg(not(all(target_arch = "x86_64", target_pointer_width = "32")))]
230 pub jitter: ::c_long,
231 pub shift: ::c_int,
232 #[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
233 pub stabil: i64,
234 #[cfg(not(all(target_arch = "x86_64", target_pointer_width = "32")))]
235 pub stabil: ::c_long,
236 #[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
237 pub jitcnt: i64,
238 #[cfg(not(all(target_arch = "x86_64", target_pointer_width = "32")))]
239 pub jitcnt: ::c_long,
240 #[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
241 pub calcnt: i64,
242 #[cfg(not(all(target_arch = "x86_64", target_pointer_width = "32")))]
243 pub calcnt: ::c_long,
244 #[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
245 pub errcnt: i64,
246 #[cfg(not(all(target_arch = "x86_64", target_pointer_width = "32")))]
247 pub errcnt: ::c_long,
248 #[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
249 pub stbcnt: i64,
250 #[cfg(not(all(target_arch = "x86_64", target_pointer_width = "32")))]
251 pub stbcnt: ::c_long,
252 pub tai: ::c_int,
253 pub __unused1: i32,
254 pub __unused2: i32,
255 pub __unused3: i32,
256 pub __unused4: i32,
257 pub __unused5: i32,
258 pub __unused6: i32,
259 pub __unused7: i32,
260 pub __unused8: i32,
261 pub __unused9: i32,
262 pub __unused10: i32,
263 pub __unused11: i32,
264 }
265
266 pub struct ntptimeval {
267 pub time: ::timeval,
268 pub maxerror: ::c_long,
269 pub esterror: ::c_long,
270 pub tai: ::c_long,
271 pub __glibc_reserved1: ::c_long,
272 pub __glibc_reserved2: ::c_long,
273 pub __glibc_reserved3: ::c_long,
274 pub __glibc_reserved4: ::c_long,
275 }
276
277 pub struct regex_t {
278 __buffer: *mut ::c_void,
279 __allocated: ::size_t,
280 __used: ::size_t,
281 __syntax: ::c_ulong,
282 __fastmap: *mut ::c_char,
283 __translate: *mut ::c_char,
284 __re_nsub: ::size_t,
285 __bitfield: u8,
286 }
184287 }
185288
186289 impl siginfo_t {
307410 }
308411 }
309412
413 // include/uapi/asm-generic/hugetlb_encode.h
414 pub const HUGETLB_FLAG_ENCODE_SHIFT: ::c_int = 26;
415 pub const HUGETLB_FLAG_ENCODE_MASK: ::c_int = 0x3f;
416
417 pub const HUGETLB_FLAG_ENCODE_64KB: ::c_int = 16 << HUGETLB_FLAG_ENCODE_SHIFT;
418 pub const HUGETLB_FLAG_ENCODE_512KB: ::c_int = 19 << HUGETLB_FLAG_ENCODE_SHIFT;
419 pub const HUGETLB_FLAG_ENCODE_1MB: ::c_int = 20 << HUGETLB_FLAG_ENCODE_SHIFT;
420 pub const HUGETLB_FLAG_ENCODE_2MB: ::c_int = 21 << HUGETLB_FLAG_ENCODE_SHIFT;
421 pub const HUGETLB_FLAG_ENCODE_8MB: ::c_int = 23 << HUGETLB_FLAG_ENCODE_SHIFT;
422 pub const HUGETLB_FLAG_ENCODE_16MB: ::c_int = 24 << HUGETLB_FLAG_ENCODE_SHIFT;
423 pub const HUGETLB_FLAG_ENCODE_32MB: ::c_int = 25 << HUGETLB_FLAG_ENCODE_SHIFT;
424 pub const HUGETLB_FLAG_ENCODE_256MB: ::c_int = 28 << HUGETLB_FLAG_ENCODE_SHIFT;
425 pub const HUGETLB_FLAG_ENCODE_512MB: ::c_int = 29 << HUGETLB_FLAG_ENCODE_SHIFT;
426 pub const HUGETLB_FLAG_ENCODE_1GB: ::c_int = 30 << HUGETLB_FLAG_ENCODE_SHIFT;
427 pub const HUGETLB_FLAG_ENCODE_2GB: ::c_int = 31 << HUGETLB_FLAG_ENCODE_SHIFT;
428 pub const HUGETLB_FLAG_ENCODE_16GB: ::c_int = 34 << HUGETLB_FLAG_ENCODE_SHIFT;
429
430 // include/uapi/linux/mman.h
431 /*
432 * Huge page size encoding when MAP_HUGETLB is specified, and a huge page
433 * size other than the default is desired. See hugetlb_encode.h.
434 * All known huge page size encodings are provided here. It is the
435 * responsibility of the application to know which sizes are supported on
436 * the running system. See mmap(2) man page for details.
437 */
438 pub const MAP_HUGE_SHIFT: ::c_int = HUGETLB_FLAG_ENCODE_SHIFT;
439 pub const MAP_HUGE_MASK: ::c_int = HUGETLB_FLAG_ENCODE_MASK;
440
441 pub const MAP_HUGE_64KB: ::c_int = HUGETLB_FLAG_ENCODE_64KB;
442 pub const MAP_HUGE_512KB: ::c_int = HUGETLB_FLAG_ENCODE_512KB;
443 pub const MAP_HUGE_1MB: ::c_int = HUGETLB_FLAG_ENCODE_1MB;
444 pub const MAP_HUGE_2MB: ::c_int = HUGETLB_FLAG_ENCODE_2MB;
445 pub const MAP_HUGE_8MB: ::c_int = HUGETLB_FLAG_ENCODE_8MB;
446 pub const MAP_HUGE_16MB: ::c_int = HUGETLB_FLAG_ENCODE_16MB;
447 pub const MAP_HUGE_32MB: ::c_int = HUGETLB_FLAG_ENCODE_32MB;
448 pub const MAP_HUGE_256MB: ::c_int = HUGETLB_FLAG_ENCODE_256MB;
449 pub const MAP_HUGE_512MB: ::c_int = HUGETLB_FLAG_ENCODE_512MB;
450 pub const MAP_HUGE_1GB: ::c_int = HUGETLB_FLAG_ENCODE_1GB;
451 pub const MAP_HUGE_2GB: ::c_int = HUGETLB_FLAG_ENCODE_2GB;
452 pub const MAP_HUGE_16GB: ::c_int = HUGETLB_FLAG_ENCODE_16GB;
453
310454 pub const RLIMIT_CPU: ::__rlimit_resource_t = 0;
311455 pub const RLIMIT_FSIZE: ::__rlimit_resource_t = 1;
312456 pub const RLIMIT_DATA: ::__rlimit_resource_t = 2;
336480 pub const DEAD_PROCESS: ::c_short = 8;
337481 pub const ACCOUNTING: ::c_short = 9;
338482
483 // dlfcn.h
484 pub const LM_ID_BASE: ::c_long = 0;
485 pub const LM_ID_NEWLM: ::c_long = -1;
486
487 pub const RTLD_DI_LMID: ::c_int = 1;
488 pub const RTLD_DI_LINKMAP: ::c_int = 2;
489 pub const RTLD_DI_CONFIGADDR: ::c_int = 3;
490 pub const RTLD_DI_SERINFO: ::c_int = 4;
491 pub const RTLD_DI_SERINFOSIZE: ::c_int = 5;
492 pub const RTLD_DI_ORIGIN: ::c_int = 6;
493 pub const RTLD_DI_PROFILENAME: ::c_int = 7;
494 pub const RTLD_DI_PROFILEOUT: ::c_int = 8;
495 pub const RTLD_DI_TLS_MODID: ::c_int = 9;
496 pub const RTLD_DI_TLS_DATA: ::c_int = 10;
497
339498 pub const SOCK_NONBLOCK: ::c_int = O_NONBLOCK;
340499
341500 pub const SOL_RXRPC: ::c_int = 272;
355514 pub const LC_TELEPHONE: ::c_int = 10;
356515 pub const LC_MEASUREMENT: ::c_int = 11;
357516 pub const LC_IDENTIFICATION: ::c_int = 12;
358 pub const LC_PAPER_MASK: ::c_int = (1 << LC_PAPER);
359 pub const LC_NAME_MASK: ::c_int = (1 << LC_NAME);
360 pub const LC_ADDRESS_MASK: ::c_int = (1 << LC_ADDRESS);
361 pub const LC_TELEPHONE_MASK: ::c_int = (1 << LC_TELEPHONE);
362 pub const LC_MEASUREMENT_MASK: ::c_int = (1 << LC_MEASUREMENT);
363 pub const LC_IDENTIFICATION_MASK: ::c_int = (1 << LC_IDENTIFICATION);
517 pub const LC_PAPER_MASK: ::c_int = 1 << LC_PAPER;
518 pub const LC_NAME_MASK: ::c_int = 1 << LC_NAME;
519 pub const LC_ADDRESS_MASK: ::c_int = 1 << LC_ADDRESS;
520 pub const LC_TELEPHONE_MASK: ::c_int = 1 << LC_TELEPHONE;
521 pub const LC_MEASUREMENT_MASK: ::c_int = 1 << LC_MEASUREMENT;
522 pub const LC_IDENTIFICATION_MASK: ::c_int = 1 << LC_IDENTIFICATION;
364523 pub const LC_ALL_MASK: ::c_int = ::LC_CTYPE_MASK
365524 | ::LC_NUMERIC_MASK
366525 | ::LC_TIME_MASK
374533 | LC_MEASUREMENT_MASK
375534 | LC_IDENTIFICATION_MASK;
376535
377 pub const MAP_SHARED_VALIDATE: ::c_int = 0x3;
378 pub const MAP_FIXED_NOREPLACE: ::c_int = 0x100000;
379
380536 pub const ENOTSUP: ::c_int = EOPNOTSUPP;
381537
382538 pub const SOCK_SEQPACKET: ::c_int = 5;
393549 pub const TCP_REPAIR_OPTIONS: ::c_int = 22;
394550 pub const TCP_FASTOPEN: ::c_int = 23;
395551 pub const TCP_TIMESTAMP: ::c_int = 24;
552 pub const TCP_FASTOPEN_CONNECT: ::c_int = 30;
396553
397554 /* DCCP socket options */
398555 pub const DCCP_SOCKOPT_PACKET_SIZE: ::c_int = 1;
526683 pub const SMB_SUPER_MAGIC: ::c_long = 0x0000517b;
527684 pub const TMPFS_MAGIC: ::c_long = 0x01021994;
528685 pub const USBDEVICE_SUPER_MAGIC: ::c_long = 0x00009fa2;
686 pub const CGROUP_SUPER_MAGIC: ::c_long = 0x27e0eb;
687 pub const CGROUP2_SUPER_MAGIC: ::c_long = 0x63677270;
529688
530689 pub const CPU_SETSIZE: ::c_int = 0x400;
531690
557716 pub const SEEK_DATA: ::c_int = 3;
558717 pub const SEEK_HOLE: ::c_int = 4;
559718
560 pub const LINUX_REBOOT_MAGIC1: ::c_int = 0xfee1dead;
561 pub const LINUX_REBOOT_MAGIC2: ::c_int = 672274793;
562 pub const LINUX_REBOOT_MAGIC2A: ::c_int = 85072278;
563 pub const LINUX_REBOOT_MAGIC2B: ::c_int = 369367448;
564 pub const LINUX_REBOOT_MAGIC2C: ::c_int = 537993216;
565
566 pub const LINUX_REBOOT_CMD_RESTART: ::c_int = 0x01234567;
567 pub const LINUX_REBOOT_CMD_HALT: ::c_int = 0xCDEF0123;
568 pub const LINUX_REBOOT_CMD_CAD_ON: ::c_int = 0x89ABCDEF;
569 pub const LINUX_REBOOT_CMD_CAD_OFF: ::c_int = 0x00000000;
570 pub const LINUX_REBOOT_CMD_POWER_OFF: ::c_int = 0x4321FEDC;
571 pub const LINUX_REBOOT_CMD_RESTART2: ::c_int = 0xA1B2C3D4;
572 pub const LINUX_REBOOT_CMD_SW_SUSPEND: ::c_int = 0xD000FCE2;
573 pub const LINUX_REBOOT_CMD_KEXEC: ::c_int = 0x45584543;
574
575719 // linux/rtnetlink.h
576720 pub const TCA_PAD: ::c_ushort = 9;
577721 pub const TCA_DUMP_INVISIBLE: ::c_ushort = 10;
630774
631775 pub const NFPROTO_INET: ::c_int = 1;
632776 pub const NFPROTO_NETDEV: ::c_int = 5;
777
778 // linux/keyctl.h
779 pub const KEYCTL_DH_COMPUTE: u32 = 23;
780 pub const KEYCTL_PKEY_QUERY: u32 = 24;
781 pub const KEYCTL_PKEY_ENCRYPT: u32 = 25;
782 pub const KEYCTL_PKEY_DECRYPT: u32 = 26;
783 pub const KEYCTL_PKEY_SIGN: u32 = 27;
784 pub const KEYCTL_PKEY_VERIFY: u32 = 28;
785 pub const KEYCTL_RESTRICT_KEYRING: u32 = 29;
786
787 pub const KEYCTL_SUPPORTS_ENCRYPT: u32 = 0x01;
788 pub const KEYCTL_SUPPORTS_DECRYPT: u32 = 0x02;
789 pub const KEYCTL_SUPPORTS_SIGN: u32 = 0x04;
790 pub const KEYCTL_SUPPORTS_VERIFY: u32 = 0x08;
791 cfg_if! {
792 if #[cfg(not(any(target_arch="mips", target_arch="mips64")))] {
793 pub const KEYCTL_MOVE: u32 = 30;
794 pub const KEYCTL_CAPABILITIES: u32 = 31;
795
796 pub const KEYCTL_CAPS0_CAPABILITIES: u32 = 0x01;
797 pub const KEYCTL_CAPS0_PERSISTENT_KEYRINGS: u32 = 0x02;
798 pub const KEYCTL_CAPS0_DIFFIE_HELLMAN: u32 = 0x04;
799 pub const KEYCTL_CAPS0_PUBLIC_KEY: u32 = 0x08;
800 pub const KEYCTL_CAPS0_BIG_KEY: u32 = 0x10;
801 pub const KEYCTL_CAPS0_INVALIDATE: u32 = 0x20;
802 pub const KEYCTL_CAPS0_RESTRICT_KEYRING: u32 = 0x40;
803 pub const KEYCTL_CAPS0_MOVE: u32 = 0x80;
804 pub const KEYCTL_CAPS1_NS_KEYRING_NAME: u32 = 0x01;
805 pub const KEYCTL_CAPS1_NS_KEY_TAG: u32 = 0x02;
806 }
807 }
633808
634809 // linux/netfilter/nf_tables.h
635810 pub const NFT_TABLE_MAXNAMELEN: ::c_int = 256;
730905 pub const NFT_RANGE_EQ: ::c_int = 0;
731906 pub const NFT_RANGE_NEQ: ::c_int = 1;
732907
733 pub const NFT_LOOKUP_F_INV: ::c_int = (1 << 0);
908 pub const NFT_LOOKUP_F_INV: ::c_int = 1 << 0;
734909
735910 pub const NFT_DYNSET_OP_ADD: ::c_int = 0;
736911 pub const NFT_DYNSET_OP_UPDATE: ::c_int = 1;
737912
738 pub const NFT_DYNSET_F_INV: ::c_int = (1 << 0);
913 pub const NFT_DYNSET_F_INV: ::c_int = 1 << 0;
739914
740915 pub const NFT_PAYLOAD_LL_HEADER: ::c_int = 0;
741916 pub const NFT_PAYLOAD_NETWORK_HEADER: ::c_int = 1;
790965 pub const NFT_LIMIT_PKTS: ::c_int = 0;
791966 pub const NFT_LIMIT_PKT_BYTES: ::c_int = 1;
792967
793 pub const NFT_LIMIT_F_INV: ::c_int = (1 << 0);
968 pub const NFT_LIMIT_F_INV: ::c_int = 1 << 0;
794969
795970 pub const NFT_QUEUE_FLAG_BYPASS: ::c_int = 0x01;
796971 pub const NFT_QUEUE_FLAG_CPU_FANOUT: ::c_int = 0x02;
797972 pub const NFT_QUEUE_FLAG_MASK: ::c_int = 0x03;
798973
799 pub const NFT_QUOTA_F_INV: ::c_int = (1 << 0);
974 pub const NFT_QUOTA_F_INV: ::c_int = 1 << 0;
800975
801976 pub const NFT_REJECT_ICMP_UNREACH: ::c_int = 0;
802977 pub const NFT_REJECT_TCP_RST: ::c_int = 1;
8571032 pub const STATX_ATTR_ENCRYPTED: ::c_int = 0x0800;
8581033 pub const STATX_ATTR_AUTOMOUNT: ::c_int = 0x1000;
8591034
1035 // sys/auxv.h
1036 pub const AT_NULL: ::c_ulong = 0;
1037 pub const AT_IGNORE: ::c_ulong = 1;
1038 pub const AT_EXECFD: ::c_ulong = 2;
1039 pub const AT_PHDR: ::c_ulong = 3;
1040 pub const AT_PHENT: ::c_ulong = 4;
1041 pub const AT_PHNUM: ::c_ulong = 5;
1042 pub const AT_PAGESZ: ::c_ulong = 6;
1043 pub const AT_BASE: ::c_ulong = 7;
1044 pub const AT_FLAGS: ::c_ulong = 8;
1045 pub const AT_ENTRY: ::c_ulong = 9;
1046 pub const AT_NOTELF: ::c_ulong = 10;
1047 pub const AT_UID: ::c_ulong = 11;
1048 pub const AT_EUID: ::c_ulong = 12;
1049 pub const AT_GID: ::c_ulong = 13;
1050 pub const AT_EGID: ::c_ulong = 14;
1051 pub const AT_PLATFORM: ::c_ulong = 15;
1052 pub const AT_HWCAP: ::c_ulong = 16;
1053 pub const AT_CLKTCK: ::c_ulong = 17;
1054 // AT_* values 18 through 22 are reserved
1055 pub const AT_SECURE: ::c_ulong = 23;
1056 pub const AT_BASE_PLATFORM: ::c_ulong = 24;
1057 pub const AT_RANDOM: ::c_ulong = 25;
1058 pub const AT_HWCAP2: ::c_ulong = 26;
1059
1060 pub const AT_EXECFN: ::c_ulong = 31;
1061
1062 //sys/timex.h
1063 pub const ADJ_OFFSET: ::c_uint = 0x0001;
1064 pub const ADJ_FREQUENCY: ::c_uint = 0x0002;
1065 pub const ADJ_MAXERROR: ::c_uint = 0x0004;
1066 pub const ADJ_ESTERROR: ::c_uint = 0x0008;
1067 pub const ADJ_STATUS: ::c_uint = 0x0010;
1068 pub const ADJ_TIMECONST: ::c_uint = 0x0020;
1069 pub const ADJ_TAI: ::c_uint = 0x0080;
1070 pub const ADJ_SETOFFSET: ::c_uint = 0x0100;
1071 pub const ADJ_MICRO: ::c_uint = 0x1000;
1072 pub const ADJ_NANO: ::c_uint = 0x2000;
1073 pub const ADJ_TICK: ::c_uint = 0x4000;
1074 pub const ADJ_OFFSET_SINGLESHOT: ::c_uint = 0x8001;
1075 pub const ADJ_OFFSET_SS_READ: ::c_uint = 0xa001;
1076 pub const MOD_OFFSET: ::c_uint = ADJ_OFFSET;
1077 pub const MOD_FREQUENCY: ::c_uint = ADJ_FREQUENCY;
1078 pub const MOD_MAXERROR: ::c_uint = ADJ_MAXERROR;
1079 pub const MOD_ESTERROR: ::c_uint = ADJ_ESTERROR;
1080 pub const MOD_STATUS: ::c_uint = ADJ_STATUS;
1081 pub const MOD_TIMECONST: ::c_uint = ADJ_TIMECONST;
1082 pub const MOD_CLKB: ::c_uint = ADJ_TICK;
1083 pub const MOD_CLKA: ::c_uint = ADJ_OFFSET_SINGLESHOT;
1084 pub const MOD_TAI: ::c_uint = ADJ_TAI;
1085 pub const MOD_MICRO: ::c_uint = ADJ_MICRO;
1086 pub const MOD_NANO: ::c_uint = ADJ_NANO;
1087 pub const STA_PLL: ::c_int = 0x0001;
1088 pub const STA_PPSFREQ: ::c_int = 0x0002;
1089 pub const STA_PPSTIME: ::c_int = 0x0004;
1090 pub const STA_FLL: ::c_int = 0x0008;
1091 pub const STA_INS: ::c_int = 0x0010;
1092 pub const STA_DEL: ::c_int = 0x0020;
1093 pub const STA_UNSYNC: ::c_int = 0x0040;
1094 pub const STA_FREQHOLD: ::c_int = 0x0080;
1095 pub const STA_PPSSIGNAL: ::c_int = 0x0100;
1096 pub const STA_PPSJITTER: ::c_int = 0x0200;
1097 pub const STA_PPSWANDER: ::c_int = 0x0400;
1098 pub const STA_PPSERROR: ::c_int = 0x0800;
1099 pub const STA_CLOCKERR: ::c_int = 0x1000;
1100 pub const STA_NANO: ::c_int = 0x2000;
1101 pub const STA_MODE: ::c_int = 0x4000;
1102 pub const STA_CLK: ::c_int = 0x8000;
1103 pub const STA_RONLY: ::c_int = STA_PPSSIGNAL
1104 | STA_PPSJITTER
1105 | STA_PPSWANDER
1106 | STA_PPSERROR
1107 | STA_CLOCKERR
1108 | STA_NANO
1109 | STA_MODE
1110 | STA_CLK;
1111 pub const NTP_API: ::c_int = 4;
1112 pub const TIME_OK: ::c_int = 0;
1113 pub const TIME_INS: ::c_int = 1;
1114 pub const TIME_DEL: ::c_int = 2;
1115 pub const TIME_OOP: ::c_int = 3;
1116 pub const TIME_WAIT: ::c_int = 4;
1117 pub const TIME_ERROR: ::c_int = 5;
1118 pub const TIME_BAD: ::c_int = TIME_ERROR;
1119 pub const MAXTC: ::c_long = 6;
1120
8601121 cfg_if! {
8611122 if #[cfg(any(
8621123 target_arch = "arm",
8631124 target_arch = "x86",
8641125 target_arch = "x86_64",
865 target_arch = "s390x"
1126 target_arch = "s390x",
1127 target_arch = "riscv64"
8661128 ))] {
8671129 pub const PTHREAD_STACK_MIN: ::size_t = 16384;
8681130 } else if #[cfg(any(
8761138 }
8771139 pub const PTHREAD_MUTEX_ADAPTIVE_NP: ::c_int = 3;
8781140
1141 pub const REG_STARTEND: ::c_int = 4;
1142
1143 pub const REG_EEND: ::c_int = 14;
1144 pub const REG_ESIZE: ::c_int = 15;
1145 pub const REG_ERPAREN: ::c_int = 16;
1146
8791147 extern "C" {
1148 pub fn fgetspent_r(
1149 fp: *mut ::FILE,
1150 spbuf: *mut ::spwd,
1151 buf: *mut ::c_char,
1152 buflen: ::size_t,
1153 spbufp: *mut *mut ::spwd,
1154 ) -> ::c_int;
1155 pub fn sgetspent_r(
1156 s: *const ::c_char,
1157 spbuf: *mut ::spwd,
1158 buf: *mut ::c_char,
1159 buflen: ::size_t,
1160 spbufp: *mut *mut ::spwd,
1161 ) -> ::c_int;
1162 pub fn getspent_r(
1163 spbuf: *mut ::spwd,
1164 buf: *mut ::c_char,
1165 buflen: ::size_t,
1166 spbufp: *mut *mut ::spwd,
1167 ) -> ::c_int;
1168 pub fn qsort_r(
1169 base: *mut ::c_void,
1170 num: ::size_t,
1171 size: ::size_t,
1172 compar: ::Option<
1173 unsafe extern "C" fn(
1174 *const ::c_void,
1175 *const ::c_void,
1176 *mut ::c_void,
1177 ) -> ::c_int,
1178 >,
1179 arg: *mut ::c_void,
1180 );
8801181 pub fn sendmmsg(
8811182 sockfd: ::c_int,
8821183 msgvec: *mut ::mmsghdr,
9421243 buflen: ::size_t,
9431244 flags: ::c_uint,
9441245 ) -> ::ssize_t;
1246
1247 pub fn memmem(
1248 haystack: *const ::c_void,
1249 haystacklen: ::size_t,
1250 needle: *const ::c_void,
1251 needlelen: ::size_t,
1252 ) -> *mut ::c_void;
1253 pub fn getauxval(type_: ::c_ulong) -> ::c_ulong;
1254
1255 pub fn adjtimex(buf: *mut timex) -> ::c_int;
1256 pub fn ntp_adjtime(buf: *mut timex) -> ::c_int;
1257 #[link_name = "ntp_gettimex"]
1258 pub fn ntp_gettime(buf: *mut ntptimeval) -> ::c_int;
1259 pub fn copy_file_range(
1260 fd_in: ::c_int,
1261 off_in: *mut ::off64_t,
1262 fd_out: ::c_int,
1263 off_out: *mut ::off64_t,
1264 len: ::size_t,
1265 flags: ::c_uint,
1266 ) -> ::ssize_t;
1267 pub fn fanotify_mark(
1268 fd: ::c_int,
1269 flags: ::c_uint,
1270 mask: u64,
1271 dirfd: ::c_int,
1272 path: *const ::c_char,
1273 ) -> ::c_int;
9451274 }
9461275
9471276 #[link(name = "util")]
9951324 pub fn sched_getcpu() -> ::c_int;
9961325 pub fn mallinfo() -> ::mallinfo;
9971326 pub fn malloc_usable_size(ptr: *mut ::c_void) -> ::size_t;
998 pub fn getauxval(type_: ::c_ulong) -> ::c_ulong;
999 #[cfg_attr(target_os = "netbsd", link_name = "__getpwent_r50")]
1000 #[cfg_attr(target_os = "solaris", link_name = "__posix_getpwent_r")]
10011327 pub fn getpwent_r(
10021328 pwd: *mut ::passwd,
10031329 buf: *mut ::c_char,
10041330 buflen: ::size_t,
10051331 result: *mut *mut ::passwd,
10061332 ) -> ::c_int;
1007 #[cfg_attr(target_os = "netbsd", link_name = "__getgrent_r50")]
1008 #[cfg_attr(target_os = "solaris", link_name = "__posix_getgrent_r")]
10091333 pub fn getgrent_r(
10101334 grp: *mut ::group,
10111335 buf: *mut ::c_char,
10201344 pub fn pthread_setname_np(
10211345 thread: ::pthread_t,
10221346 name: *const ::c_char,
1347 ) -> ::c_int;
1348 }
1349
1350 #[link(name = "dl")]
1351 extern "C" {
1352 pub fn dlmopen(
1353 lmid: Lmid_t,
1354 filename: *const ::c_char,
1355 flag: ::c_int,
1356 ) -> *mut ::c_void;
1357 pub fn dlinfo(
1358 handle: *mut ::c_void,
1359 request: ::c_int,
1360 info: *mut ::c_void,
10231361 ) -> ::c_int;
10241362 }
10251363
3636 pub type Elf64_Section = u16;
3737
3838 #[cfg_attr(feature = "extra_traits", derive(Debug))]
39 pub enum fpos64_t {} // TODO: fill this out with a struct
39 pub enum fpos64_t {} // FIXME: fill this out with a struct
4040 impl ::Copy for fpos64_t {}
4141 impl ::Clone for fpos64_t {
4242 fn clone(&self) -> fpos64_t {
476476 pub len: u32
477477 }
478478
479 pub struct fanotify_response {
480 pub fd: ::c_int,
481 pub response: __u32,
482 }
483
479484 pub struct sockaddr_vm {
480485 pub svm_family: ::sa_family_t,
481486 pub svm_reserved1: ::c_ushort,
482487 pub svm_port: ::c_uint,
483488 pub svm_cid: ::c_uint,
484489 pub svm_zero: [u8; 4]
490 }
491
492 pub struct regmatch_t {
493 pub rm_so: regoff_t,
494 pub rm_eo: regoff_t,
495 }
496
497 pub struct sock_extended_err {
498 pub ee_errno: u32,
499 pub ee_origin: u8,
500 pub ee_type: u8,
501 pub ee_code: u8,
502 pub ee_pad: u8,
503 pub ee_info: u32,
504 pub ee_data: u32,
485505 }
486506 }
487507
12041224 pub const RTLD_NODELETE: ::c_int = 0x1000;
12051225 pub const RTLD_NOW: ::c_int = 0x2;
12061226
1227 pub const AT_EACCESS: ::c_int = 0x200;
1228
12071229 pub const TCP_MD5SIG: ::c_int = 14;
12081230
12091231 align_const! {
12951317 pub const IPPROTO_RAW: ::c_int = 255;
12961318 pub const IPPROTO_MAX: ::c_int = 256;
12971319
1320 pub const IP_MSFILTER: ::c_int = 41;
1321 pub const MCAST_JOIN_GROUP: ::c_int = 42;
1322 pub const MCAST_BLOCK_SOURCE: ::c_int = 43;
1323 pub const MCAST_UNBLOCK_SOURCE: ::c_int = 44;
1324 pub const MCAST_LEAVE_GROUP: ::c_int = 45;
1325 pub const MCAST_JOIN_SOURCE_GROUP: ::c_int = 46;
1326 pub const MCAST_LEAVE_SOURCE_GROUP: ::c_int = 47;
1327 pub const MCAST_MSFILTER: ::c_int = 48;
1328 pub const IP_MULTICAST_ALL: ::c_int = 49;
1329 pub const IP_UNICAST_IF: ::c_int = 50;
1330
12981331 pub const AF_IB: ::c_int = 27;
12991332 pub const AF_MPLS: ::c_int = 28;
13001333 pub const AF_NFC: ::c_int = 39;
15591592 pub const SO_ORIGINAL_DST: ::c_int = 80;
15601593 pub const IP_ORIGDSTADDR: ::c_int = 20;
15611594 pub const IP_RECVORIGDSTADDR: ::c_int = IP_ORIGDSTADDR;
1595 pub const IPV6_FLOWINFO: ::c_int = 11;
15621596 pub const IPV6_ORIGDSTADDR: ::c_int = 74;
15631597 pub const IPV6_RECVORIGDSTADDR: ::c_int = IPV6_ORIGDSTADDR;
15641598 pub const IPV6_FLOWLABEL_MGR: ::c_int = 32;
17721806 pub const NFULNL_CFG_F_SEQ_GLOBAL: ::c_int = 0x0002;
17731807 pub const NFULNL_CFG_F_CONNTRACK: ::c_int = 0x0004;
17741808
1809 // linux/netfilter/nfnetlink_log.h
1810 pub const NFQNL_MSG_PACKET: ::c_int = 0;
1811 pub const NFQNL_MSG_VERDICT: ::c_int = 1;
1812 pub const NFQNL_MSG_CONFIG: ::c_int = 2;
1813 pub const NFQNL_MSG_VERDICT_BATCH: ::c_int = 3;
1814
1815 pub const NFQA_UNSPEC: ::c_int = 0;
1816 pub const NFQA_PACKET_HDR: ::c_int = 1;
1817 pub const NFQA_VERDICT_HDR: ::c_int = 2;
1818 pub const NFQA_MARK: ::c_int = 3;
1819 pub const NFQA_TIMESTAMP: ::c_int = 4;
1820 pub const NFQA_IFINDEX_INDEV: ::c_int = 5;
1821 pub const NFQA_IFINDEX_OUTDEV: ::c_int = 6;
1822 pub const NFQA_IFINDEX_PHYSINDEV: ::c_int = 7;
1823 pub const NFQA_IFINDEX_PHYSOUTDEV: ::c_int = 8;
1824 pub const NFQA_HWADDR: ::c_int = 9;
1825 pub const NFQA_PAYLOAD: ::c_int = 10;
1826 pub const NFQA_CT: ::c_int = 11;
1827 pub const NFQA_CT_INFO: ::c_int = 12;
1828 pub const NFQA_CAP_LEN: ::c_int = 13;
1829 pub const NFQA_SKB_INFO: ::c_int = 14;
1830 pub const NFQA_EXP: ::c_int = 15;
1831 pub const NFQA_UID: ::c_int = 16;
1832 pub const NFQA_GID: ::c_int = 17;
1833 pub const NFQA_SECCTX: ::c_int = 18;
1834 /*
1835 FIXME: These are not yet available in musl sanitized kernel headers and
1836 make the tests fail. Enable them once musl has them.
1837
1838 See https://github.com/rust-lang/libc/pull/1628 for more details.
1839 pub const NFQA_VLAN: ::c_int = 19;
1840 pub const NFQA_L2HDR: ::c_int = 20;
1841
1842 pub const NFQA_VLAN_UNSPEC: ::c_int = 0;
1843 pub const NFQA_VLAN_PROTO: ::c_int = 1;
1844 pub const NFQA_VLAN_TCI: ::c_int = 2;
1845 */
1846
1847 pub const NFQNL_CFG_CMD_NONE: ::c_int = 0;
1848 pub const NFQNL_CFG_CMD_BIND: ::c_int = 1;
1849 pub const NFQNL_CFG_CMD_UNBIND: ::c_int = 2;
1850 pub const NFQNL_CFG_CMD_PF_BIND: ::c_int = 3;
1851 pub const NFQNL_CFG_CMD_PF_UNBIND: ::c_int = 4;
1852
1853 pub const NFQNL_COPY_NONE: ::c_int = 0;
1854 pub const NFQNL_COPY_META: ::c_int = 1;
1855 pub const NFQNL_COPY_PACKET: ::c_int = 2;
1856
1857 pub const NFQA_CFG_UNSPEC: ::c_int = 0;
1858 pub const NFQA_CFG_CMD: ::c_int = 1;
1859 pub const NFQA_CFG_PARAMS: ::c_int = 2;
1860 pub const NFQA_CFG_QUEUE_MAXLEN: ::c_int = 3;
1861 pub const NFQA_CFG_MASK: ::c_int = 4;
1862 pub const NFQA_CFG_FLAGS: ::c_int = 5;
1863
1864 pub const NFQA_CFG_F_FAIL_OPEN: ::c_int = 0x0001;
1865 pub const NFQA_CFG_F_CONNTRACK: ::c_int = 0x0002;
1866 pub const NFQA_CFG_F_GSO: ::c_int = 0x0004;
1867 pub const NFQA_CFG_F_UID_GID: ::c_int = 0x0008;
1868 pub const NFQA_CFG_F_SECCTX: ::c_int = 0x0010;
1869 pub const NFQA_CFG_F_MAX: ::c_int = 0x0020;
1870
1871 pub const NFQA_SKB_CSUMNOTREADY: ::c_int = 0x0001;
1872 pub const NFQA_SKB_GSO: ::c_int = 0x0002;
1873 pub const NFQA_SKB_CSUM_NOTVERIFIED: ::c_int = 0x0004;
1874
17751875 pub const GENL_NAMSIZ: ::c_int = 16;
17761876
17771877 pub const GENL_MIN_ID: ::c_int = NLMSG_MIN_TYPE;
18981998 pub const NF_IP6_PRI_SELINUX_LAST: ::c_int = 225;
18991999 pub const NF_IP6_PRI_CONNTRACK_HELPER: ::c_int = 300;
19002000 pub const NF_IP6_PRI_LAST: ::c_int = ::INT_MAX;
2001
2002 // linux/netfilter_ipv6/ip6_tables.h
2003 pub const IP6T_SO_ORIGINAL_DST: ::c_int = 80;
19012004
19022005 pub const SIOCADDRT: ::c_ulong = 0x0000890B;
19032006 pub const SIOCDELRT: ::c_ulong = 0x0000890C;
22342337 pub const ALG_OP_DECRYPT: ::c_int = 0;
22352338 pub const ALG_OP_ENCRYPT: ::c_int = 1;
22362339
2340 // include/uapi/linux/udp.h
2341 pub const UDP_CORK: ::c_int = 1;
2342 pub const UDP_ENCAP: ::c_int = 100;
2343 pub const UDP_NO_CHECK6_TX: ::c_int = 101;
2344 pub const UDP_NO_CHECK6_RX: ::c_int = 102;
2345 pub const UDP_SEGMENT: ::c_int = 103;
2346 pub const UDP_GRO: ::c_int = 104;
2347
2348 // include/uapi/linux/mman.h
2349 pub const MAP_SHARED_VALIDATE: ::c_int = 0x3;
2350
2351 // include/uapi/asm-generic/mman-common.h
2352 pub const MAP_FIXED_NOREPLACE: ::c_int = 0x100000;
2353
22372354 // uapi/linux/vm_sockets.h
22382355 pub const VMADDR_CID_ANY: ::c_uint = 0xFFFFFFFF;
22392356 pub const VMADDR_CID_HYPERVISOR: ::c_uint = 0;
22472364 pub const IN_ATTRIB: u32 = 0x0000_0004;
22482365 pub const IN_CLOSE_WRITE: u32 = 0x0000_0008;
22492366 pub const IN_CLOSE_NOWRITE: u32 = 0x0000_0010;
2250 pub const IN_CLOSE: u32 = (IN_CLOSE_WRITE | IN_CLOSE_NOWRITE);
2367 pub const IN_CLOSE: u32 = IN_CLOSE_WRITE | IN_CLOSE_NOWRITE;
22512368 pub const IN_OPEN: u32 = 0x0000_0020;
22522369 pub const IN_MOVED_FROM: u32 = 0x0000_0040;
22532370 pub const IN_MOVED_TO: u32 = 0x0000_0080;
2254 pub const IN_MOVE: u32 = (IN_MOVED_FROM | IN_MOVED_TO);
2371 pub const IN_MOVE: u32 = IN_MOVED_FROM | IN_MOVED_TO;
22552372 pub const IN_CREATE: u32 = 0x0000_0100;
22562373 pub const IN_DELETE: u32 = 0x0000_0200;
22572374 pub const IN_DELETE_SELF: u32 = 0x0000_0400;
22632380 pub const IN_DONT_FOLLOW: u32 = 0x0200_0000;
22642381 // pub const IN_EXCL_UNLINK: u32 = 0x0400_0000;
22652382
2383 // linux/keyctl.h
2384 pub const KEY_SPEC_THREAD_KEYRING: i32 = -1;
2385 pub const KEY_SPEC_PROCESS_KEYRING: i32 = -2;
2386 pub const KEY_SPEC_SESSION_KEYRING: i32 = -3;
2387 pub const KEY_SPEC_USER_KEYRING: i32 = -4;
2388 pub const KEY_SPEC_USER_SESSION_KEYRING: i32 = -5;
2389 pub const KEY_SPEC_GROUP_KEYRING: i32 = -6;
2390 pub const KEY_SPEC_REQKEY_AUTH_KEY: i32 = -7;
2391 pub const KEY_SPEC_REQUESTOR_KEYRING: i32 = -8;
2392
2393 pub const KEY_REQKEY_DEFL_NO_CHANGE: i32 = -1;
2394 pub const KEY_REQKEY_DEFL_DEFAULT: i32 = 0;
2395 pub const KEY_REQKEY_DEFL_THREAD_KEYRING: i32 = 1;
2396 pub const KEY_REQKEY_DEFL_PROCESS_KEYRING: i32 = 2;
2397 pub const KEY_REQKEY_DEFL_SESSION_KEYRING: i32 = 3;
2398 pub const KEY_REQKEY_DEFL_USER_KEYRING: i32 = 4;
2399 pub const KEY_REQKEY_DEFL_USER_SESSION_KEYRING: i32 = 5;
2400 pub const KEY_REQKEY_DEFL_GROUP_KEYRING: i32 = 6;
2401 pub const KEY_REQKEY_DEFL_REQUESTOR_KEYRING: i32 = 7;
2402
2403 pub const KEYCTL_GET_KEYRING_ID: u32 = 0;
2404 pub const KEYCTL_JOIN_SESSION_KEYRING: u32 = 1;
2405 pub const KEYCTL_UPDATE: u32 = 2;
2406 pub const KEYCTL_REVOKE: u32 = 3;
2407 pub const KEYCTL_CHOWN: u32 = 4;
2408 pub const KEYCTL_SETPERM: u32 = 5;
2409 pub const KEYCTL_DESCRIBE: u32 = 6;
2410 pub const KEYCTL_CLEAR: u32 = 7;
2411 pub const KEYCTL_LINK: u32 = 8;
2412 pub const KEYCTL_UNLINK: u32 = 9;
2413 pub const KEYCTL_SEARCH: u32 = 10;
2414 pub const KEYCTL_READ: u32 = 11;
2415 pub const KEYCTL_INSTANTIATE: u32 = 12;
2416 pub const KEYCTL_NEGATE: u32 = 13;
2417 pub const KEYCTL_SET_REQKEY_KEYRING: u32 = 14;
2418 pub const KEYCTL_SET_TIMEOUT: u32 = 15;
2419 pub const KEYCTL_ASSUME_AUTHORITY: u32 = 16;
2420 pub const KEYCTL_GET_SECURITY: u32 = 17;
2421 pub const KEYCTL_SESSION_TO_PARENT: u32 = 18;
2422 pub const KEYCTL_REJECT: u32 = 19;
2423 pub const KEYCTL_INSTANTIATE_IOV: u32 = 20;
2424 pub const KEYCTL_INVALIDATE: u32 = 21;
2425 pub const KEYCTL_GET_PERSISTENT: u32 = 22;
2426
22662427 // pub const IN_MASK_CREATE: u32 = 0x1000_0000;
22672428 // pub const IN_MASK_ADD: u32 = 0x2000_0000;
22682429 pub const IN_ISDIR: u32 = 0x4000_0000;
22692430 pub const IN_ONESHOT: u32 = 0x8000_0000;
22702431
2271 pub const IN_ALL_EVENTS: u32 = (IN_ACCESS
2432 pub const IN_ALL_EVENTS: u32 = IN_ACCESS
22722433 | IN_MODIFY
22732434 | IN_ATTRIB
22742435 | IN_CLOSE_WRITE
22792440 | IN_DELETE
22802441 | IN_CREATE
22812442 | IN_DELETE_SELF
2282 | IN_MOVE_SELF);
2443 | IN_MOVE_SELF;
22832444
22842445 pub const IN_CLOEXEC: ::c_int = O_CLOEXEC;
22852446 pub const IN_NONBLOCK: ::c_int = O_NONBLOCK;
2447
2448 // uapi/linux/fanotify.h
2449 pub const FAN_ACCESS: u64 = 0x0000_0001;
2450 pub const FAN_MODIFY: u64 = 0x0000_0002;
2451 pub const FAN_CLOSE_WRITE: u64 = 0x0000_0008;
2452 pub const FAN_CLOSE_NOWRITE: u64 = 0x0000_0010;
2453 pub const FAN_OPEN: u64 = 0x0000_0020;
2454
2455 pub const FAN_Q_OVERFLOW: u64 = 0x0000_4000;
2456
2457 pub const FAN_OPEN_PERM: u64 = 0x0001_0000;
2458 pub const FAN_ACCESS_PERM: u64 = 0x0002_0000;
2459
2460 pub const FAN_ONDIR: u64 = 0x4000_0000;
2461
2462 pub const FAN_EVENT_ON_CHILD: u64 = 0x0800_0000;
2463
2464 pub const FAN_CLOSE: u64 = FAN_CLOSE_WRITE | FAN_CLOSE_NOWRITE;
2465
2466 pub const FAN_CLOEXEC: ::c_uint = 0x0000_0001;
2467 pub const FAN_NONBLOCK: ::c_uint = 0x0000_0002;
2468
2469 pub const FAN_CLASS_NOTIF: ::c_uint = 0x0000_0000;
2470 pub const FAN_CLASS_CONTENT: ::c_uint = 0x0000_0004;
2471 pub const FAN_CLASS_PRE_CONTENT: ::c_uint = 0x0000_0008;
2472
2473 pub const FAN_UNLIMITED_QUEUE: ::c_uint = 0x0000_0010;
2474 pub const FAN_UNLIMITED_MARKS: ::c_uint = 0x0000_0020;
2475
2476 pub const FAN_MARK_ADD: ::c_uint = 0x0000_0001;
2477 pub const FAN_MARK_REMOVE: ::c_uint = 0x0000_0002;
2478 pub const FAN_MARK_DONT_FOLLOW: ::c_uint = 0x0000_0004;
2479 pub const FAN_MARK_ONLYDIR: ::c_uint = 0x0000_0008;
2480 pub const FAN_MARK_INODE: ::c_uint = 0x0000_0000;
2481 pub const FAN_MARK_MOUNT: ::c_uint = 0x0000_0010;
2482 // NOTE: FAN_MARK_FILESYSTEM requires Linux Kernel >= 4.20.0
2483 pub const FAN_MARK_FILESYSTEM: ::c_uint = 0x0000_0100;
2484 pub const FAN_MARK_IGNORED_MASK: ::c_uint = 0x0000_0020;
2485 pub const FAN_MARK_IGNORED_SURV_MODIFY: ::c_uint = 0x0000_0040;
2486 pub const FAN_MARK_FLUSH: ::c_uint = 0x0000_0080;
2487
2488 pub const FANOTIFY_METADATA_VERSION: u8 = 3;
2489
2490 pub const FAN_ALLOW: u32 = 0x01;
2491 pub const FAN_DENY: u32 = 0x02;
2492
2493 pub const FAN_NOFD: ::c_int = -1;
22862494
22872495 pub const FUTEX_WAIT: ::c_int = 0;
22882496 pub const FUTEX_WAKE: ::c_int = 1;
23022510 pub const FUTEX_CLOCK_REALTIME: ::c_int = 256;
23032511 pub const FUTEX_CMD_MASK: ::c_int =
23042512 !(FUTEX_PRIVATE_FLAG | FUTEX_CLOCK_REALTIME);
2513
2514 // linux/reboot.h
2515 pub const LINUX_REBOOT_MAGIC1: ::c_int = 0xfee1dead;
2516 pub const LINUX_REBOOT_MAGIC2: ::c_int = 672274793;
2517 pub const LINUX_REBOOT_MAGIC2A: ::c_int = 85072278;
2518 pub const LINUX_REBOOT_MAGIC2B: ::c_int = 369367448;
2519 pub const LINUX_REBOOT_MAGIC2C: ::c_int = 537993216;
2520
2521 pub const LINUX_REBOOT_CMD_RESTART: ::c_int = 0x01234567;
2522 pub const LINUX_REBOOT_CMD_HALT: ::c_int = 0xCDEF0123;
2523 pub const LINUX_REBOOT_CMD_CAD_ON: ::c_int = 0x89ABCDEF;
2524 pub const LINUX_REBOOT_CMD_CAD_OFF: ::c_int = 0x00000000;
2525 pub const LINUX_REBOOT_CMD_POWER_OFF: ::c_int = 0x4321FEDC;
2526 pub const LINUX_REBOOT_CMD_RESTART2: ::c_int = 0xA1B2C3D4;
2527 pub const LINUX_REBOOT_CMD_SW_SUSPEND: ::c_int = 0xD000FCE2;
2528 pub const LINUX_REBOOT_CMD_KEXEC: ::c_int = 0x45584543;
2529
2530 pub const REG_EXTENDED: ::c_int = 1;
2531 pub const REG_ICASE: ::c_int = 2;
2532 pub const REG_NEWLINE: ::c_int = 4;
2533 pub const REG_NOSUB: ::c_int = 8;
2534
2535 pub const REG_NOTBOL: ::c_int = 1;
2536 pub const REG_NOTEOL: ::c_int = 2;
2537
2538 pub const REG_ENOSYS: ::c_int = -1;
2539 pub const REG_NOMATCH: ::c_int = 1;
2540 pub const REG_BADPAT: ::c_int = 2;
2541 pub const REG_ECOLLATE: ::c_int = 3;
2542 pub const REG_ECTYPE: ::c_int = 4;
2543 pub const REG_EESCAPE: ::c_int = 5;
2544 pub const REG_ESUBREG: ::c_int = 6;
2545 pub const REG_EBRACK: ::c_int = 7;
2546 pub const REG_EPAREN: ::c_int = 8;
2547 pub const REG_EBRACE: ::c_int = 9;
2548 pub const REG_BADBR: ::c_int = 10;
2549 pub const REG_ERANGE: ::c_int = 11;
2550 pub const REG_ESPACE: ::c_int = 12;
2551 pub const REG_BADRPT: ::c_int = 13;
2552
2553 // linux/errqueue.h
2554 pub const SO_EE_ORIGIN_NONE: u8 = 0;
2555 pub const SO_EE_ORIGIN_LOCAL: u8 = 1;
2556 pub const SO_EE_ORIGIN_ICMP: u8 = 2;
2557 pub const SO_EE_ORIGIN_ICMP6: u8 = 3;
2558 pub const SO_EE_ORIGIN_TXSTATUS: u8 = 4;
2559 pub const SO_EE_ORIGIN_TIMESTAMPING: u8 = SO_EE_ORIGIN_TXSTATUS;
2560
2561 // errno.h
2562 pub const EPERM: ::c_int = 1;
2563 pub const ENOENT: ::c_int = 2;
2564 pub const ESRCH: ::c_int = 3;
2565 pub const EINTR: ::c_int = 4;
2566 pub const EIO: ::c_int = 5;
2567 pub const ENXIO: ::c_int = 6;
2568 pub const E2BIG: ::c_int = 7;
2569 pub const ENOEXEC: ::c_int = 8;
2570 pub const EBADF: ::c_int = 9;
2571 pub const ECHILD: ::c_int = 10;
2572 pub const EAGAIN: ::c_int = 11;
2573 pub const ENOMEM: ::c_int = 12;
2574 pub const EACCES: ::c_int = 13;
2575 pub const EFAULT: ::c_int = 14;
2576 pub const ENOTBLK: ::c_int = 15;
2577 pub const EBUSY: ::c_int = 16;
2578 pub const EEXIST: ::c_int = 17;
2579 pub const EXDEV: ::c_int = 18;
2580 pub const ENODEV: ::c_int = 19;
2581 pub const ENOTDIR: ::c_int = 20;
2582 pub const EISDIR: ::c_int = 21;
2583 pub const EINVAL: ::c_int = 22;
2584 pub const ENFILE: ::c_int = 23;
2585 pub const EMFILE: ::c_int = 24;
2586 pub const ENOTTY: ::c_int = 25;
2587 pub const ETXTBSY: ::c_int = 26;
2588 pub const EFBIG: ::c_int = 27;
2589 pub const ENOSPC: ::c_int = 28;
2590 pub const ESPIPE: ::c_int = 29;
2591 pub const EROFS: ::c_int = 30;
2592 pub const EMLINK: ::c_int = 31;
2593 pub const EPIPE: ::c_int = 32;
2594 pub const EDOM: ::c_int = 33;
2595 pub const ERANGE: ::c_int = 34;
2596 pub const EWOULDBLOCK: ::c_int = EAGAIN;
23052597
23062598 f! {
23072599 pub fn NLA_ALIGN(len: ::c_int) -> ::c_int {
24032695 pub fn RT_LOCALADDR(flags: u32) -> bool {
24042696 (flags & RTF_ADDRCLASSMASK) == (RTF_LOCAL | RTF_INTERFACE)
24052697 }
2698
2699 pub fn SO_EE_OFFENDER(ee: *const ::sock_extended_err) -> *mut ::sockaddr {
2700 ee.offset(1) as *mut ::sockaddr
2701 }
24062702 }
24072703
24082704 extern "C" {
24492745 pub fn endspent();
24502746 pub fn getspent() -> *mut spwd;
24512747
2452 pub fn getspnam(__name: *const ::c_char) -> *mut spwd;
2748 pub fn getspnam(name: *const ::c_char) -> *mut spwd;
2749 // Only `getspnam_r` is implemented for musl, out of all of the reenterant
2750 // functions from `shadow.h`.
2751 // https://git.musl-libc.org/cgit/musl/tree/include/shadow.h
2752 pub fn getspnam_r(
2753 name: *const ::c_char,
2754 spbuf: *mut spwd,
2755 buf: *mut ::c_char,
2756 buflen: ::size_t,
2757 spbufp: *mut *mut spwd,
2758 ) -> ::c_int;
24532759
24542760 pub fn shm_open(
24552761 name: *const c_char,
29463252 count: ::size_t,
29473253 ) -> ::ssize_t;
29483254 pub fn sigsuspend(mask: *const ::sigset_t) -> ::c_int;
2949 #[cfg_attr(target_os = "solaris", link_name = "__posix_getgrgid_r")]
29503255 pub fn getgrgid_r(
29513256 gid: ::gid_t,
29523257 grp: *mut ::group,
29543259 buflen: ::size_t,
29553260 result: *mut *mut ::group,
29563261 ) -> ::c_int;
2957 #[cfg_attr(
2958 all(target_os = "macos", target_arch = "x86"),
2959 link_name = "sigaltstack$UNIX2003"
2960 )]
2961 #[cfg_attr(target_os = "netbsd", link_name = "__sigaltstack14")]
29623262 pub fn sigaltstack(ss: *const stack_t, oss: *mut stack_t) -> ::c_int;
29633263 pub fn sem_close(sem: *mut sem_t) -> ::c_int;
29643264 pub fn getdtablesize() -> ::c_int;
2965 #[cfg_attr(target_os = "solaris", link_name = "__posix_getgrnam_r")]
29663265 pub fn getgrnam_r(
29673266 name: *const ::c_char,
29683267 grp: *mut ::group,
29713270 result: *mut *mut ::group,
29723271 ) -> ::c_int;
29733272 pub fn initgroups(user: *const ::c_char, group: ::gid_t) -> ::c_int;
2974 #[cfg_attr(
2975 all(target_os = "macos", target_arch = "x86"),
2976 link_name = "pthread_sigmask$UNIX2003"
2977 )]
29783273 pub fn pthread_sigmask(
29793274 how: ::c_int,
29803275 set: *const sigset_t,
29863281 pub fn pthread_kill(thread: ::pthread_t, sig: ::c_int) -> ::c_int;
29873282 pub fn sem_unlink(name: *const ::c_char) -> ::c_int;
29883283 pub fn daemon(nochdir: ::c_int, noclose: ::c_int) -> ::c_int;
2989 #[cfg_attr(target_os = "netbsd", link_name = "__getpwnam_r50")]
2990 #[cfg_attr(target_os = "solaris", link_name = "__posix_getpwnam_r")]
29913284 pub fn getpwnam_r(
29923285 name: *const ::c_char,
29933286 pwd: *mut passwd,
29953288 buflen: ::size_t,
29963289 result: *mut *mut passwd,
29973290 ) -> ::c_int;
2998 #[cfg_attr(target_os = "netbsd", link_name = "__getpwuid_r50")]
2999 #[cfg_attr(target_os = "solaris", link_name = "__posix_getpwuid_r")]
30003291 pub fn getpwuid_r(
30013292 uid: ::uid_t,
30023293 pwd: *mut passwd,
30043295 buflen: ::size_t,
30053296 result: *mut *mut passwd,
30063297 ) -> ::c_int;
3007 #[cfg_attr(
3008 all(target_os = "macos", target_arch = "x86"),
3009 link_name = "sigwait$UNIX2003"
3010 )]
3011 #[cfg_attr(target_os = "solaris", link_name = "__posix_sigwait")]
30123298 pub fn sigwait(set: *const sigset_t, sig: *mut ::c_int) -> ::c_int;
30133299 pub fn pthread_atfork(
30143300 prepare: ::Option<unsafe extern "C" fn()>,
30263312 attr: *const pthread_mutexattr_t,
30273313 pshared: *mut ::c_int,
30283314 ) -> ::c_int;
3029 #[cfg_attr(
3030 all(target_os = "macos", target_arch = "x86"),
3031 link_name = "popen$UNIX2003"
3032 )]
30333315 pub fn popen(command: *const c_char, mode: *const c_char) -> *mut ::FILE;
30343316 pub fn faccessat(
30353317 dirfd: ::c_int,
31693451 path: *const ::c_char,
31703452 mask: u32,
31713453 ) -> ::c_int;
3454 pub fn fanotify_init(flags: ::c_uint, event_f_flags: ::c_uint) -> ::c_int;
3455
3456 pub fn regcomp(
3457 preg: *mut ::regex_t,
3458 pattern: *const ::c_char,
3459 cflags: ::c_int,
3460 ) -> ::c_int;
3461
3462 pub fn regexec(
3463 preg: *const ::regex_t,
3464 input: *const ::c_char,
3465 nmatch: ::size_t,
3466 pmatch: *mut regmatch_t,
3467 eflags: ::c_int,
3468 ) -> ::c_int;
3469
3470 pub fn regerror(
3471 errcode: ::c_int,
3472 preg: *const ::regex_t,
3473 errbuf: *mut ::c_char,
3474 errbuf_size: ::size_t,
3475 ) -> ::size_t;
3476
3477 pub fn regfree(preg: *mut ::regex_t);
31723478 }
31733479
31743480 cfg_if! {
148148 pub f_flag: ::c_ulong,
149149 pub f_namemax: ::c_ulong,
150150 __f_spare: [::c_int; 6],
151 }
152
153 pub struct nlmsghdr {
154 pub nlmsg_len: u32,
155 pub nlmsg_type: u16,
156 pub nlmsg_flags: u16,
157 pub nlmsg_seq: u32,
158 pub nlmsg_pid: u32,
159 }
160
161 pub struct nlmsgerr {
162 pub error: ::c_int,
163 pub msg: nlmsghdr,
164 }
165
166 pub struct nlattr {
167 pub nla_len: u16,
168 pub nla_type: u16,
151169 }
152170 }
153171
261279 pub const MAP_POPULATE: ::c_int = 0x08000;
262280 pub const MAP_NONBLOCK: ::c_int = 0x010000;
263281 pub const MAP_STACK: ::c_int = 0x020000;
282 pub const MAP_SYNC : ::c_int = 0x080000;
264283
265284 pub const SOCK_STREAM: ::c_int = 1;
266285 pub const SOCK_DGRAM: ::c_int = 2;
417436 pub const F_SETLK: ::c_int = 13;
418437 pub const F_SETLKW: ::c_int = 14;
419438 pub const F_SETOWN: ::c_int = 8;
439 pub const F_OFD_GETLK: ::c_int = 36;
440 pub const F_OFD_SETLK: ::c_int = 37;
441 pub const F_OFD_SETLKW: ::c_int = 38;
420442
421443 pub const VEOF: usize = 4;
422444 pub const VEOL: usize = 11;
257257 pub const MAP_DENYWRITE: ::c_int = 2048;
258258 pub const MAP_EXECUTABLE: ::c_int = 4096;
259259 pub const MAP_GROWSDOWN: ::c_int = 256;
260 pub const MAP_HUGE_MASK: ::c_int = 63;
261 pub const MAP_HUGE_SHIFT: ::c_int = 26;
262260 pub const MAP_HUGETLB: ::c_int = 262144;
263261 pub const MAP_LOCKED: ::c_int = 8192;
264262 pub const MAP_NONBLOCK: ::c_int = 65536;
159159 pub f_flag: ::c_ulong,
160160 pub f_namemax: ::c_ulong,
161161 __f_spare: [::c_int; 6],
162 }
163
164 pub struct nlmsghdr {
165 pub nlmsg_len: u32,
166 pub nlmsg_type: u16,
167 pub nlmsg_flags: u16,
168 pub nlmsg_seq: u32,
169 pub nlmsg_pid: u32,
170 }
171
172 pub struct nlmsgerr {
173 pub error: ::c_int,
174 pub msg: nlmsghdr,
175 }
176
177 pub struct nlattr {
178 pub nla_len: u16,
179 pub nla_type: u16,
162180 }
163181 }
164182
427445 pub const F_SETLK: ::c_int = 34;
428446 pub const F_SETLKW: ::c_int = 35;
429447 pub const F_SETOWN: ::c_int = 24;
448 pub const F_OFD_GETLK: ::c_int = 36;
449 pub const F_OFD_SETLK: ::c_int = 37;
450 pub const F_OFD_SETLKW: ::c_int = 38;
430451
431452 pub const VEOF: usize = 16;
432453 pub const VEOL: usize = 17;
22 pub type nlink_t = u32;
33 pub type blksize_t = ::c_long;
44 pub type __u64 = ::c_ulonglong;
5 pub type regoff_t = ::c_int;
56
67 s! {
78 pub struct pthread_attr_t {
420420 pub const F_SETLK: ::c_int = 13;
421421 pub const F_SETLKW: ::c_int = 14;
422422 pub const F_SETOWN: ::c_int = 8;
423 pub const F_OFD_GETLK: ::c_int = 36;
424 pub const F_OFD_SETLK: ::c_int = 37;
425 pub const F_OFD_SETLKW: ::c_int = 38;
423426
424427 pub const VEOF: usize = 4;
425428 pub const VEOL: usize = 6;
152152 pub f_flag: ::c_ulong,
153153 pub f_namemax: ::c_ulong,
154154 __f_spare: [::c_int; 6],
155 }
156
157 pub struct nlmsghdr {
158 pub nlmsg_len: u32,
159 pub nlmsg_type: u16,
160 pub nlmsg_flags: u16,
161 pub nlmsg_seq: u32,
162 pub nlmsg_pid: u32,
163 }
164
165 pub struct nlmsgerr {
166 pub error: ::c_int,
167 pub msg: nlmsghdr,
168 }
169
170 pub struct nlattr {
171 pub nla_len: u16,
172 pub nla_type: u16,
155173 }
156174 }
157175
321339 pub const MAP_POPULATE: ::c_int = 0x08000;
322340 pub const MAP_NONBLOCK: ::c_int = 0x010000;
323341 pub const MAP_STACK: ::c_int = 0x020000;
342 pub const MAP_SYNC : ::c_int = 0x080000;
324343
325344 pub const SOCK_STREAM: ::c_int = 1;
326345 pub const SOCK_DGRAM: ::c_int = 2;
478497 pub const F_SETLK: ::c_int = 13;
479498 pub const F_SETLKW: ::c_int = 14;
480499 pub const F_SETOWN: ::c_int = 8;
500 pub const F_OFD_GETLK: ::c_int = 36;
501 pub const F_OFD_SETLK: ::c_int = 37;
502 pub const F_OFD_SETLKW: ::c_int = 38;
481503
482504 pub const VEOF: usize = 4;
483505 pub const VEOL: usize = 11;
169169 pub const MAP_NONBLOCK: ::c_int = 0x010000;
170170 pub const MAP_STACK: ::c_int = 0x020000;
171171 pub const MAP_HUGETLB: ::c_int = 0x040000;
172 pub const MAP_SYNC : ::c_int = 0x080000;
172173
173174 pub const SOCK_STREAM: ::c_int = 1;
174175 pub const SOCK_DGRAM: ::c_int = 2;
226227 pub const F_SETLK: ::c_int = 6;
227228 pub const F_SETLKW: ::c_int = 7;
228229 pub const F_SETOWN: ::c_int = 8;
230 pub const F_OFD_GETLK: ::c_int = 36;
231 pub const F_OFD_SETLK: ::c_int = 37;
232 pub const F_OFD_SETLKW: ::c_int = 38;
229233
230234 pub const VEOF: usize = 4;
231235
8080 pub f_frsize: ::c_ulong,
8181 pub f_flags: ::c_ulong,
8282 pub f_spare: [::c_ulong; 5],
83 }
84
85 pub struct nlmsghdr {
86 pub nlmsg_len: u32,
87 pub nlmsg_type: u16,
88 pub nlmsg_flags: u16,
89 pub nlmsg_seq: u32,
90 pub nlmsg_pid: u32,
91 }
92
93 pub struct nlmsgerr {
94 pub error: ::c_int,
95 pub msg: nlmsghdr,
96 }
97
98 pub struct nlattr {
99 pub nla_len: u16,
100 pub nla_type: u16,
83101 }
84102
85103 pub struct ipc_perm {
634652 pub const F_SETOWN: ::c_int = 24;
635653 pub const F_SETLK: ::c_int = 6;
636654 pub const F_SETLKW: ::c_int = 7;
655 pub const F_OFD_GETLK: ::c_int = 36;
656 pub const F_OFD_SETLK: ::c_int = 37;
657 pub const F_OFD_SETLKW: ::c_int = 38;
637658
638659 pub const TCGETS: ::c_ulong = 0x540d;
639660 pub const TCSETS: ::c_ulong = 0x540e;
00 pub type c_long = i64;
11 pub type c_ulong = u64;
2 pub type regoff_t = ::c_long;
23
34 s! {
45 pub struct statfs64 {
169169 pub const MAP_NONBLOCK: ::c_int = 0x010000;
170170 pub const MAP_STACK: ::c_int = 0x020000;
171171 pub const MAP_HUGETLB: ::c_int = 0x040000;
172 pub const MAP_SYNC : ::c_int = 0x080000;
172173
173174 pub const SOCK_STREAM: ::c_int = 1;
174175 pub const SOCK_DGRAM: ::c_int = 2;
226227 pub const F_SETLK: ::c_int = 6;
227228 pub const F_SETLKW: ::c_int = 7;
228229 pub const F_SETOWN: ::c_int = 8;
230 pub const F_OFD_GETLK: ::c_int = 36;
231 pub const F_OFD_SETLK: ::c_int = 37;
232 pub const F_OFD_SETLKW: ::c_int = 38;
229233
230234 pub const VEOF: usize = 4;
231235
4545 pub st_ctime: ::time_t,
4646 pub st_ctime_nsec: ::c_long,
4747 __reserved: [::c_long; 3],
48 }
49
50 pub struct nlmsghdr {
51 pub nlmsg_len: u32,
52 pub nlmsg_type: u16,
53 pub nlmsg_flags: u16,
54 pub nlmsg_seq: u32,
55 pub nlmsg_pid: u32,
56 }
57
58 pub struct nlmsgerr {
59 pub error: ::c_int,
60 pub msg: nlmsghdr,
61 }
62
63 pub struct nlattr {
64 pub nla_len: u16,
65 pub nla_type: u16,
4866 }
4967
5068 pub struct user_regs_struct {
776794 pub const F_SETLK: ::c_int = 6;
777795 pub const F_SETLKW: ::c_int = 7;
778796 pub const F_SETOWN: ::c_int = 8;
797 pub const F_OFD_GETLK: ::c_int = 36;
798 pub const F_OFD_SETLK: ::c_int = 37;
799 pub const F_OFD_SETLKW: ::c_int = 38;
779800
780801 pub const VEOF: usize = 4;
781802
815836 pub const MAP_NONBLOCK: ::c_int = 0x010000;
816837 pub const MAP_STACK: ::c_int = 0x020000;
817838 pub const MAP_HUGETLB: ::c_int = 0x040000;
839 pub const MAP_SYNC : ::c_int = 0x080000;
818840
819841 pub const RLIMIT_NLIMITS: ::c_int = 15;
820842 pub const TIOCINQ: ::c_int = ::FIONREAD;
107107 pub l_start: ::off_t,
108108 pub l_len: ::off_t,
109109 pub l_pid: ::pid_t,
110 }
111
112 pub struct regex_t {
113 __re_nsub: ::size_t,
114 __opaque: *mut ::c_void,
115 __padding: [*mut ::c_void; 4usize],
116 __nsub2: ::size_t,
117 __padding2: ::c_char,
110118 }
111119 }
112120
198206 }
199207 }
200208
209 // include/sys/mman.h
210 /*
211 * Huge page size encoding when MAP_HUGETLB is specified, and a huge page
212 * size other than the default is desired. See hugetlb_encode.h.
213 * All known huge page size encodings are provided here. It is the
214 * responsibility of the application to know which sizes are supported on
215 * the running system. See mmap(2) man page for details.
216 */
217 pub const MAP_HUGE_SHIFT: ::c_int = 26;
218 pub const MAP_HUGE_MASK: ::c_int = 0x3f;
219
220 pub const MAP_HUGE_64KB: ::c_int = 16 << MAP_HUGE_SHIFT;
221 pub const MAP_HUGE_512KB: ::c_int = 19 << MAP_HUGE_SHIFT;
222 pub const MAP_HUGE_1MB: ::c_int = 20 << MAP_HUGE_SHIFT;
223 pub const MAP_HUGE_2MB: ::c_int = 21 << MAP_HUGE_SHIFT;
224 pub const MAP_HUGE_8MB: ::c_int = 23 << MAP_HUGE_SHIFT;
225 pub const MAP_HUGE_16MB: ::c_int = 24 << MAP_HUGE_SHIFT;
226 pub const MAP_HUGE_32MB: ::c_int = 25 << MAP_HUGE_SHIFT;
227 pub const MAP_HUGE_256MB: ::c_int = 28 << MAP_HUGE_SHIFT;
228 pub const MAP_HUGE_512MB: ::c_int = 29 << MAP_HUGE_SHIFT;
229 pub const MAP_HUGE_1GB: ::c_int = 30 << MAP_HUGE_SHIFT;
230 pub const MAP_HUGE_2GB: ::c_int = 31 << MAP_HUGE_SHIFT;
231 pub const MAP_HUGE_16GB: ::c_int = 34 << MAP_HUGE_SHIFT;
232
201233 pub const MS_RMT_MASK: ::c_ulong = 0x02800051;
202234
203235 pub const SFD_CLOEXEC: ::c_int = 0x080000;
270302 pub const TCP_REPAIR_OPTIONS: ::c_int = 22;
271303 pub const TCP_FASTOPEN: ::c_int = 23;
272304 pub const TCP_TIMESTAMP: ::c_int = 24;
305 pub const TCP_FASTOPEN_CONNECT: ::c_int = 30;
273306
274307 #[deprecated(since = "0.2.55", note = "Use SIGSYS instead")]
275308 pub const SIGUNUSED: ::c_int = ::SIGSYS;
326359 pub const RTLD_GLOBAL: ::c_int = 0x100;
327360 pub const RTLD_NOLOAD: ::c_int = 0x4;
328361
329 // TODO(#247) Temporarily musl-specific (available since musl 0.9.12 / Linux
330 // kernel 3.10). See also linux_like/mod.rs
331362 pub const CLOCK_SGI_CYCLE: ::clockid_t = 10;
332 pub const CLOCK_TAI: ::clockid_t = 11;
333363
334364 pub const B0: ::speed_t = 0o000000;
335365 pub const B50: ::speed_t = 0o000001;
368398 pub const RLIMIT_NICE: ::c_int = 13;
369399 pub const RLIMIT_RTPRIO: ::c_int = 14;
370400
401 pub const REG_OK: ::c_int = 0;
402
371403 extern "C" {
372404 pub fn sendmmsg(
373405 sockfd: ::c_int,
415447 cpuset: *const ::cpu_set_t,
416448 ) -> ::c_int;
417449 pub fn sched_getcpu() -> ::c_int;
450 pub fn memmem(
451 haystack: *const ::c_void,
452 haystacklen: ::size_t,
453 needle: *const ::c_void,
454 needlelen: ::size_t,
455 ) -> *mut ::c_void;
456 // Musl targets need the `mask` argument of `fanotify_mark` be specified
457 // `::c_ulonglong` instead of `u64` or there will be a type mismatch between
458 // `long long unsigned int` and the expected `uint64_t`.
459 pub fn fanotify_mark(
460 fd: ::c_int,
461 flags: ::c_uint,
462 mask: ::c_ulonglong,
463 dirfd: ::c_int,
464 path: *const ::c_char,
465 ) -> ::c_int;
418466 }
419467
420468 cfg_if! {
66 target_arch = "mips64",
77 target_arch = "s390x",
88 target_arch = "sparc64",
9 target_arch = "riscv64",
910 all(target_arch = "aarch64",
1011 target_env = "musl")))]
1112 __align: [::c_int; 0],
1415 target_arch = "mips64",
1516 target_arch = "s390x",
1617 target_arch = "sparc64",
18 target_arch = "riscv64",
1719 all(target_arch = "aarch64",
1820 target_env = "musl"))))]
1921 __align: [::c_long; 0],
3133 pub struct pthread_condattr_t {
3234 __align: [::c_int; 0],
3335 size: [u8; ::__SIZEOF_PTHREAD_CONDATTR_T],
36 }
37
38 pub struct fanotify_event_metadata {
39 __align: [::c_long; 0],
40 pub event_len: __u32,
41 pub vers: __u8,
42 pub reserved: __u8,
43 pub metadata_len: __u16,
44 pub mask: __u64,
45 pub fd: ::c_int,
46 pub pid: ::c_int,
3447 }
3548 }
3649
471471 pub const F_SEAL_GROW: ::c_int = 0x0004;
472472 pub const F_SEAL_WRITE: ::c_int = 0x0008;
473473
474 // TODO(#235): Include file sealing fcntls once we have a way to verify them.
474 // FIXME(#235): Include file sealing fcntls once we have a way to verify them.
475475
476476 pub const SIGTRAP: ::c_int = 5;
477477
488488 pub const CLOCK_BOOTTIME: ::clockid_t = 7;
489489 pub const CLOCK_REALTIME_ALARM: ::clockid_t = 8;
490490 pub const CLOCK_BOOTTIME_ALARM: ::clockid_t = 9;
491 // TODO(#247) Someday our Travis shall have glibc 2.21 (released in Sep
492 // 2014.) See also musl/mod.rs
493 // pub const CLOCK_SGI_CYCLE: ::clockid_t = 10;
494 // pub const CLOCK_TAI: ::clockid_t = 11;
491 pub const CLOCK_TAI: ::clockid_t = 11;
495492 pub const TIMER_ABSTIME: ::c_int = 1;
496493
497494 pub const RUSAGE_SELF: ::c_int = 0;
553550 pub const LC_MONETARY: ::c_int = 4;
554551 pub const LC_MESSAGES: ::c_int = 5;
555552 pub const LC_ALL: ::c_int = 6;
556 pub const LC_CTYPE_MASK: ::c_int = (1 << LC_CTYPE);
557 pub const LC_NUMERIC_MASK: ::c_int = (1 << LC_NUMERIC);
558 pub const LC_TIME_MASK: ::c_int = (1 << LC_TIME);
559 pub const LC_COLLATE_MASK: ::c_int = (1 << LC_COLLATE);
560 pub const LC_MONETARY_MASK: ::c_int = (1 << LC_MONETARY);
561 pub const LC_MESSAGES_MASK: ::c_int = (1 << LC_MESSAGES);
553 pub const LC_CTYPE_MASK: ::c_int = 1 << LC_CTYPE;
554 pub const LC_NUMERIC_MASK: ::c_int = 1 << LC_NUMERIC;
555 pub const LC_TIME_MASK: ::c_int = 1 << LC_TIME;
556 pub const LC_COLLATE_MASK: ::c_int = 1 << LC_COLLATE;
557 pub const LC_MONETARY_MASK: ::c_int = 1 << LC_MONETARY;
558 pub const LC_MESSAGES_MASK: ::c_int = 1 << LC_MESSAGES;
562559 // LC_ALL_MASK defined per platform
563560
564561 pub const MAP_FILE: ::c_int = 0x0000;
600597 pub const MS_ACTIVE: ::c_ulong = 0x40000000;
601598 pub const MS_MGC_VAL: ::c_ulong = 0xc0ed0000;
602599 pub const MS_MGC_MSK: ::c_ulong = 0xffff0000;
603
604 pub const EPERM: ::c_int = 1;
605 pub const ENOENT: ::c_int = 2;
606 pub const ESRCH: ::c_int = 3;
607 pub const EINTR: ::c_int = 4;
608 pub const EIO: ::c_int = 5;
609 pub const ENXIO: ::c_int = 6;
610 pub const E2BIG: ::c_int = 7;
611 pub const ENOEXEC: ::c_int = 8;
612 pub const EBADF: ::c_int = 9;
613 pub const ECHILD: ::c_int = 10;
614 pub const EAGAIN: ::c_int = 11;
615 pub const ENOMEM: ::c_int = 12;
616 pub const EACCES: ::c_int = 13;
617 pub const EFAULT: ::c_int = 14;
618 pub const ENOTBLK: ::c_int = 15;
619 pub const EBUSY: ::c_int = 16;
620 pub const EEXIST: ::c_int = 17;
621 pub const EXDEV: ::c_int = 18;
622 pub const ENODEV: ::c_int = 19;
623 pub const ENOTDIR: ::c_int = 20;
624 pub const EISDIR: ::c_int = 21;
625 pub const EINVAL: ::c_int = 22;
626 pub const ENFILE: ::c_int = 23;
627 pub const EMFILE: ::c_int = 24;
628 pub const ENOTTY: ::c_int = 25;
629 pub const ETXTBSY: ::c_int = 26;
630 pub const EFBIG: ::c_int = 27;
631 pub const ENOSPC: ::c_int = 28;
632 pub const ESPIPE: ::c_int = 29;
633 pub const EROFS: ::c_int = 30;
634 pub const EMLINK: ::c_int = 31;
635 pub const EPIPE: ::c_int = 32;
636 pub const EDOM: ::c_int = 33;
637 pub const ERANGE: ::c_int = 34;
638 pub const EWOULDBLOCK: ::c_int = EAGAIN;
639600
640601 pub const SCM_RIGHTS: ::c_int = 0x01;
641602 pub const SCM_CREDENTIALS: ::c_int = 0x02;
811772 pub const IP_TTL: ::c_int = 2;
812773 pub const IP_HDRINCL: ::c_int = 3;
813774 pub const IP_PKTINFO: ::c_int = 8;
775 pub const IP_MTU_DISCOVER: ::c_int = 10;
814776 pub const IP_RECVTOS: ::c_int = 13;
815777 pub const IP_RECVERR: ::c_int = 11;
816778 pub const IP_ADD_MEMBERSHIP: ::c_int = 35;
827789 pub const IPV6_CHECKSUM: ::c_int = 7;
828790 pub const IPV6_2292HOPLIMIT: ::c_int = 8;
829791 pub const IPV6_NEXTHOP: ::c_int = 9;
830 pub const IPV6_FLOWINFO: ::c_int = 11;
831792 pub const IPV6_UNICAST_HOPS: ::c_int = 16;
832793 pub const IPV6_MULTICAST_IF: ::c_int = 17;
833794 pub const IPV6_MULTICAST_HOPS: ::c_int = 18;
845806 pub const IPV6_PKTINFO: ::c_int = 50;
846807 pub const IPV6_RECVTCLASS: ::c_int = 66;
847808 pub const IPV6_TCLASS: ::c_int = 67;
809
810 pub const IP_PMTUDISC_DONT: ::c_int = 0;
811 pub const IP_PMTUDISC_WANT: ::c_int = 1;
812 pub const IP_PMTUDISC_DO: ::c_int = 2;
813 pub const IP_PMTUDISC_PROBE: ::c_int = 3;
848814
849815 pub const TCP_NODELAY: ::c_int = 1;
850816 pub const TCP_MAXSEG: ::c_int = 2;
10941060 pub const IPOPT_RESERVED1: u8 = 0x20;
10951061 pub const IPOPT_MEASUREMENT: u8 = 0x40;
10961062 pub const IPOPT_RESERVED2: u8 = 0x60;
1097 pub const IPOPT_END: u8 = (0 | IPOPT_CONTROL);
1098 pub const IPOPT_NOOP: u8 = (1 | IPOPT_CONTROL);
1099 pub const IPOPT_SEC: u8 = (2 | IPOPT_CONTROL | IPOPT_COPY);
1100 pub const IPOPT_LSRR: u8 = (3 | IPOPT_CONTROL | IPOPT_COPY);
1101 pub const IPOPT_TIMESTAMP: u8 = (4 | IPOPT_MEASUREMENT);
1102 pub const IPOPT_RR: u8 = (7 | IPOPT_CONTROL);
1103 pub const IPOPT_SID: u8 = (8 | IPOPT_CONTROL | IPOPT_COPY);
1104 pub const IPOPT_SSRR: u8 = (9 | IPOPT_CONTROL | IPOPT_COPY);
1105 pub const IPOPT_RA: u8 = (20 | IPOPT_CONTROL | IPOPT_COPY);
1063 pub const IPOPT_END: u8 = 0 | IPOPT_CONTROL;
1064 pub const IPOPT_NOOP: u8 = 1 | IPOPT_CONTROL;
1065 pub const IPOPT_SEC: u8 = 2 | IPOPT_CONTROL | IPOPT_COPY;
1066 pub const IPOPT_LSRR: u8 = 3 | IPOPT_CONTROL | IPOPT_COPY;
1067 pub const IPOPT_TIMESTAMP: u8 = 4 | IPOPT_MEASUREMENT;
1068 pub const IPOPT_RR: u8 = 7 | IPOPT_CONTROL;
1069 pub const IPOPT_SID: u8 = 8 | IPOPT_CONTROL | IPOPT_COPY;
1070 pub const IPOPT_SSRR: u8 = 9 | IPOPT_CONTROL | IPOPT_COPY;
1071 pub const IPOPT_RA: u8 = 20 | IPOPT_CONTROL | IPOPT_COPY;
11061072 pub const IPVERSION: u8 = 4;
11071073 pub const MAXTTL: u8 = 255;
11081074 pub const IPDEFTTL: u8 = 64;
225225 pub const S_ISGID: ::mode_t = 0x400;
226226 pub const S_ISVTX: ::mode_t = 0x200;
227227
228 pub const IF_NAMESIZE: ::size_t = 16;
229 pub const IFNAMSIZ: ::size_t = IF_NAMESIZE;
228 cfg_if! {
229 if #[cfg(not(any(target_os = "illumos", target_os = "solaris")))] {
230 pub const IF_NAMESIZE: ::size_t = 16;
231 pub const IFNAMSIZ: ::size_t = IF_NAMESIZE;
232 }
233 }
230234
231235 pub const LOG_EMERG: ::c_int = 0;
232236 pub const LOG_ALERT: ::c_int = 1;
364368 }
365369 }
366370 #[cfg_attr(feature = "extra_traits", derive(Debug))]
367 pub enum fpos_t {} // TODO: fill this out with a struct
371 pub enum fpos_t {} // FIXME: fill this out with a struct
368372 impl ::Copy for fpos_t {}
369373 impl ::Clone for fpos_t {
370374 fn clone(&self) -> fpos_t {
387391 pub fn isblank(c: c_int) -> c_int;
388392 pub fn tolower(c: c_int) -> c_int;
389393 pub fn toupper(c: c_int) -> c_int;
394 pub fn qsort(
395 base: *mut c_void,
396 num: size_t,
397 size: size_t,
398 compar: ::Option<
399 unsafe extern "C" fn(*const c_void, *const c_void) -> c_int,
400 >,
401 );
402 pub fn bsearch(
403 key: *const c_void,
404 base: *const c_void,
405 num: size_t,
406 size: size_t,
407 compar: ::Option<
408 unsafe extern "C" fn(*const c_void, *const c_void) -> c_int,
409 >,
410 ) -> *mut c_void;
390411 #[cfg_attr(
391412 all(target_os = "macos", target_arch = "x86"),
392413 link_name = "fopen$UNIX2003"
503524 pub fn strspn(cs: *const c_char, ct: *const c_char) -> size_t;
504525 pub fn strcspn(cs: *const c_char, ct: *const c_char) -> size_t;
505526 pub fn strdup(cs: *const c_char) -> *mut c_char;
527 pub fn strndup(cs: *const c_char, n: size_t) -> *mut c_char;
506528 pub fn strpbrk(cs: *const c_char, ct: *const c_char) -> *mut c_char;
507529 pub fn strstr(cs: *const c_char, ct: *const c_char) -> *mut c_char;
508530 pub fn strcasecmp(s1: *const c_char, s2: *const c_char) -> c_int;
520542 pub fn strerror(n: c_int) -> *mut c_char;
521543 pub fn strtok(s: *mut c_char, t: *const c_char) -> *mut c_char;
522544 pub fn strxfrm(s: *mut c_char, ct: *const c_char, n: size_t) -> size_t;
545 pub fn strsignal(sig: c_int) -> *mut c_char;
523546 pub fn wcslen(buf: *const wchar_t) -> size_t;
524547 pub fn wcstombs(
525548 dest: *mut c_char,
528551 ) -> ::size_t;
529552
530553 pub fn memchr(cx: *const c_void, c: c_int, n: size_t) -> *mut c_void;
554 pub fn wmemchr(cx: *const wchar_t, c: wchar_t, n: size_t) -> *mut wchar_t;
531555 pub fn memcmp(cx: *const c_void, ct: *const c_void, n: size_t) -> c_int;
532556 pub fn memcpy(
533557 dest: *mut c_void,
592616 all(target_os = "macos", target_arch = "x86"),
593617 link_name = "listen$UNIX2003"
594618 )]
595 #[cfg_attr(target_os = "illumos", link_name = "__xnet_listen")]
596619 pub fn listen(socket: ::c_int, backlog: ::c_int) -> ::c_int;
597620 #[cfg_attr(
598621 all(target_os = "macos", target_arch = "x86"),
835858 pub fn geteuid() -> uid_t;
836859 pub fn getgid() -> gid_t;
837860 pub fn getgroups(ngroups_max: ::c_int, groups: *mut gid_t) -> ::c_int;
861 #[cfg_attr(target_os = "illumos", link_name = "getloginx")]
838862 pub fn getlogin() -> *mut c_char;
839863 #[cfg_attr(
840864 all(target_os = "macos", target_arch = "x86"),
891915 all(target_os = "macos", target_arch = "x86"),
892916 link_name = "ttyname_r$UNIX2003"
893917 )]
918 #[cfg_attr(target_os = "illumos", link_name = "__posix_ttyname_r")]
894919 pub fn ttyname_r(
895920 fd: ::c_int,
896921 buf: *mut c_char,
11971222 pub fn dlclose(handle: *mut ::c_void) -> ::c_int;
11981223 pub fn dladdr(addr: *const ::c_void, info: *mut Dl_info) -> ::c_int;
11991224
1225 #[cfg_attr(target_os = "illumos", link_name = "__xnet_getaddrinfo")]
12001226 pub fn getaddrinfo(
12011227 node: *const c_char,
12021228 service: *const c_char,
14281454 n: *mut size_t,
14291455 stream: *mut FILE,
14301456 ) -> ssize_t;
1457
1458 pub fn lockf(
1459 fd: ::c_int,
1460 cmd: ::c_int,
1461 len: ::off_t,
1462 ) -> ::c_int;
14311463 }
14321464
14331465 cfg_if! {
416416 pub const AF_INET: ::c_int = 2;
417417 pub const AF_INET6: ::c_int = 23;
418418
419 pub const CLOCK_REALTIME: ::clockid_t = 1;
420 pub const CLOCK_MONOTONIC: ::clockid_t = 4;
421 pub const CLOCK_BOOTTIME: ::clockid_t = 4;
422
419423 pub const SOCK_STREAM: ::c_int = 1;
420424 pub const SOCK_DGRAM: ::c_int = 2;
421425
596600
597601 pub fn bind(fd: ::c_int, addr: *const sockaddr, len: socklen_t)
598602 -> ::c_int;
603 pub fn clock_settime(
604 clock_id: ::clockid_t,
605 tp: *const ::timespec,
606 ) -> ::c_int;
607 pub fn clock_gettime(
608 clock_id: ::clockid_t,
609 tp: *mut ::timespec,
610 ) -> ::c_int;
611 pub fn clock_getres(
612 clock_id: ::clockid_t,
613 res: *mut ::timespec,
614 ) -> ::c_int;
599615 pub fn closesocket(sockfd: ::c_int) -> ::c_int;
600616 pub fn ioctl(fd: ::c_int, request: ::c_ulong, ...) -> ::c_int;
601617 pub fn recvfrom(
622638 envp: *const *const ::c_char,
623639 ) -> ::c_int;
624640 pub fn gettimeofday(tp: *mut ::timeval, tz: *mut ::c_void) -> ::c_int;
625 #[cfg_attr(target_os = "solaris", link_name = "__posix_getgrgid_r")]
626641 pub fn getgrgid_r(
627642 gid: ::gid_t,
628643 grp: *mut ::group,
630645 buflen: ::size_t,
631646 result: *mut *mut ::group,
632647 ) -> ::c_int;
633 #[cfg_attr(
634 all(target_os = "macos", target_arch = "x86"),
635 link_name = "sigaltstack$UNIX2003"
636 )]
637 #[cfg_attr(target_os = "netbsd", link_name = "__sigaltstack14")]
638648 pub fn sigaltstack(ss: *const stack_t, oss: *mut stack_t) -> ::c_int;
639649 pub fn sem_close(sem: *mut sem_t) -> ::c_int;
640650 pub fn getdtablesize() -> ::c_int;
641 #[cfg_attr(target_os = "solaris", link_name = "__posix_getgrnam_r")]
642651 pub fn getgrnam_r(
643652 name: *const ::c_char,
644653 grp: *mut ::group,
646655 buflen: ::size_t,
647656 result: *mut *mut ::group,
648657 ) -> ::c_int;
649 #[cfg_attr(
650 all(target_os = "macos", target_arch = "x86"),
651 link_name = "pthread_sigmask$UNIX2003"
652 )]
653658 pub fn pthread_sigmask(
654659 how: ::c_int,
655660 set: *const sigset_t,
660665 pub fn pthread_kill(thread: ::pthread_t, sig: ::c_int) -> ::c_int;
661666 pub fn sem_unlink(name: *const ::c_char) -> ::c_int;
662667 pub fn daemon(nochdir: ::c_int, noclose: ::c_int) -> ::c_int;
663 #[cfg_attr(target_os = "netbsd", link_name = "__getpwnam_r50")]
664 #[cfg_attr(target_os = "solaris", link_name = "__posix_getpwnam_r")]
665668 pub fn getpwnam_r(
666669 name: *const ::c_char,
667670 pwd: *mut passwd,
669672 buflen: ::size_t,
670673 result: *mut *mut passwd,
671674 ) -> ::c_int;
672 #[cfg_attr(target_os = "netbsd", link_name = "__getpwuid_r50")]
673 #[cfg_attr(target_os = "solaris", link_name = "__posix_getpwuid_r")]
674675 pub fn getpwuid_r(
675676 uid: ::uid_t,
676677 pwd: *mut passwd,
678679 buflen: ::size_t,
679680 result: *mut *mut passwd,
680681 ) -> ::c_int;
681 #[cfg_attr(
682 all(target_os = "macos", target_arch = "x86"),
683 link_name = "sigwait$UNIX2003"
684 )]
685 #[cfg_attr(target_os = "solaris", link_name = "__posix_sigwait")]
686682 pub fn sigwait(set: *const sigset_t, sig: *mut ::c_int) -> ::c_int;
687683 pub fn pthread_atfork(
688684 prepare: ::Option<unsafe extern "C" fn()>,
690686 child: ::Option<unsafe extern "C" fn()>,
691687 ) -> ::c_int;
692688 pub fn getgrgid(gid: ::gid_t) -> *mut ::group;
693 #[cfg_attr(
694 all(target_os = "macos", target_arch = "x86"),
695 link_name = "popen$UNIX2003"
696 )]
697689 pub fn popen(command: *const c_char, mode: *const c_char) -> *mut ::FILE;
698690 pub fn uname(buf: *mut ::utsname) -> ::c_int;
699691 }
257257 pub const F_SETLK: ::c_int = 6;
258258 pub const F_SETLKW: ::c_int = 7;
259259
260 // TODO: relibc {
260 // FIXME: relibc {
261261 pub const RTLD_DEFAULT: *mut ::c_void = 0i64 as *mut ::c_void;
262262 // }
263263
412412 pub const F_SETFD: ::c_int = 2;
413413 pub const F_GETFL: ::c_int = 3;
414414 pub const F_SETFL: ::c_int = 4;
415 // TODO: relibc {
415 // FIXME: relibc {
416416 pub const F_DUPFD_CLOEXEC: ::c_int = ::F_DUPFD;
417417 // }
418418 pub const FD_CLOEXEC: ::c_int = 0x0100_0000;
434434 pub const O_PATH: ::c_int = 0x2000_0000;
435435 pub const O_SYMLINK: ::c_int = 0x4000_0000;
436436 // Negative to allow it to be used as int
437 // TODO: Fix negative values missing from includes
437 // FIXME: Fix negative values missing from includes
438438 pub const O_NOFOLLOW: ::c_int = -0x8000_0000;
439439
440440 // netdb.h
441441 pub const EAI_SYSTEM: ::c_int = -11;
442442
443443 // netinet/in.h
444 // TODO: relibc {
444 // FIXME: relibc {
445445 pub const IP_TTL: ::c_int = 2;
446446 pub const IPV6_UNICAST_HOPS: ::c_int = 16;
447447 pub const IPV6_MULTICAST_IF: ::c_int = 17;
459459
460460 // netinet/tcp.h
461461 pub const TCP_NODELAY: ::c_int = 1;
462 // TODO: relibc {
462 // FIXME: relibc {
463463 pub const TCP_KEEPIDLE: ::c_int = 1;
464464 // }
465465
574574 pub const EXIT_FAILURE: ::c_int = 1;
575575
576576 // sys/ioctl.h
577 // TODO: relibc {
577 // FIXME: relibc {
578578 pub const FIONBIO: ::c_ulong = 0x5421;
579579 pub const FIOCLEX: ::c_ulong = 0x5451;
580580 // }
837837
838838 pub fn WCOREDUMP(status: ::c_int) -> bool {
839839 (status & 0x80) != 0
840 }
841
842 pub fn FD_CLR(fd: ::c_int, set: *mut fd_set) -> () {
843 let fd = fd as usize;
844 let size = ::mem::size_of_val(&(*set).fds_bits[0]) * 8;
845 (*set).fds_bits[fd / size] &= !(1 << (fd % size));
846 return
847 }
848
849 pub fn FD_ISSET(fd: ::c_int, set: *mut fd_set) -> bool {
850 let fd = fd as usize;
851 let size = ::mem::size_of_val(&(*set).fds_bits[0]) * 8;
852 return ((*set).fds_bits[fd / size] & (1 << (fd % size))) != 0
853 }
854
855 pub fn FD_SET(fd: ::c_int, set: *mut fd_set) -> () {
856 let fd = fd as usize;
857 let size = ::mem::size_of_val(&(*set).fds_bits[0]) * 8;
858 (*set).fds_bits[fd / size] |= 1 << (fd % size);
859 return
860 }
861
862 pub fn FD_ZERO(set: *mut fd_set) -> () {
863 for slot in (*set).fds_bits.iter_mut() {
864 *slot = 0;
865 }
840866 }
841867 }
842868
33 use unix::solarish::*;
44
55 pub unsafe fn cfmakeraw(termios: *mut ::termios) {
6 let mut t = *termios as ::termios;
7 t.c_iflag &= !(IMAXBEL
6 (*termios).c_iflag &= !(IMAXBEL
87 | IGNBRK
98 | BRKINT
109 | PARMRK
1312 | IGNCR
1413 | ICRNL
1514 | IXON);
16 t.c_oflag &= !OPOST;
17 t.c_lflag &= !(ECHO | ECHONL | ICANON | ISIG | IEXTEN);
18 t.c_cflag &= !(CSIZE | PARENB);
19 t.c_cflag |= CS8;
15 (*termios).c_oflag &= !OPOST;
16 (*termios).c_lflag &= !(ECHO | ECHONL | ICANON | ISIG | IEXTEN);
17 (*termios).c_cflag &= !(CSIZE | PARENB);
18 (*termios).c_cflag |= CS8;
19
20 // By default, most software expects a pending read to block until at
21 // least one byte becomes available. As per termio(7I), this requires
22 // setting the MIN and TIME parameters appropriately.
23 //
24 // As a somewhat unfortunate artefact of history, the MIN and TIME slots
25 // in the control character array overlap with the EOF and EOL slots used
26 // for canonical mode processing. Because the EOF character needs to be
27 // the ASCII EOT value (aka Control-D), it has the byte value 4. When
28 // switching to raw mode, this is interpreted as a MIN value of 4; i.e.,
29 // reads will block until at least four bytes have been input.
30 //
31 // Other platforms with a distinct MIN slot like Linux and FreeBSD appear
32 // to default to a MIN value of 1, so we'll force that value here:
33 (*termios).c_cc[VMIN] = 1;
34 (*termios).c_cc[VTIME] = 0;
2035 }
2136
2237 pub unsafe fn cfsetspeed(
0 s! {
1 pub struct shmid_ds {
2 pub shm_perm: ::ipc_perm,
3 pub shm_segsz: ::size_t,
4 pub shm_amp: *mut ::c_void,
5 pub shm_lkcnt: ::c_ushort,
6 pub shm_lpid: ::pid_t,
7 pub shm_cpid: ::pid_t,
8 pub shm_nattch: ::shmatt_t,
9 pub shm_cnattch: ::c_ulong,
10 pub shm_atime: ::time_t,
11 pub shm_dtime: ::time_t,
12 pub shm_ctime: ::time_t,
13 pub shm_pad4: [i64; 4],
14 }
15 }
16
17 pub const AF_LOCAL: ::c_int = 1; // AF_UNIX
18 pub const AF_FILE: ::c_int = 1; // AF_UNIX
19
20 extern "C" {
21 pub fn mincore(
22 addr: ::caddr_t,
23 len: ::size_t,
24 vec: *mut ::c_char,
25 ) -> ::c_int;
26 }
00 pub type c_char = i8;
11 pub type c_long = i64;
22 pub type c_ulong = u64;
3 pub type caddr_t = *mut ::c_char;
34
45 pub type clockid_t = ::c_int;
56 pub type blkcnt_t = ::c_long;
3536 pub type idtype_t = ::c_uint;
3637 pub type shmatt_t = ::c_ulong;
3738
38 pub type door_attr_t = ::c_uint;
39 pub type door_id_t = ::c_ulonglong;
40
4139 #[cfg_attr(feature = "extra_traits", derive(Debug))]
4240 pub enum timezone {}
4341 impl ::Copy for timezone {}
214212 pub ai_canonname: *mut ::c_char,
215213 pub ai_addr: *mut ::sockaddr,
216214 pub ai_next: *mut addrinfo,
217 }
218
219 pub struct shmid_ds {
220 pub shm_perm: ipc_perm,
221 pub shm_segsz: ::size_t,
222 #[cfg(target_os = "illumos")]
223 pub shm_amp: *mut ::c_void,
224 #[cfg(target_os = "solaris")]
225 pub shm_flags: ::uintptr_t,
226 pub shm_lkcnt: ::c_ushort,
227 pub shm_lpid: ::pid_t,
228 pub shm_cpid: ::pid_t,
229 pub shm_nattch: ::shmatt_t,
230 pub shm_cnattch: ::c_ulong,
231 pub shm_atime: ::time_t,
232 pub shm_dtime: ::time_t,
233 pub shm_ctime: ::time_t,
234 #[cfg(target_os = "illumos")]
235 pub shm_pad4: [i64; 4],
236 #[cfg(target_os = "solaris")]
237 pub shm_amp: *mut ::c_void,
238 #[cfg(target_os = "solaris")]
239 pub shm_gransize: u64,
240 #[cfg(target_os = "solaris")]
241 pub shm_allocated: u64,
242 #[cfg(target_os = "solaris")]
243 pub shm_pad4: [i64; 1],
244215 }
245216
246217 pub struct sigset_t {
370341 pub mq_maxmsg: ::c_long,
371342 pub mq_msgsize: ::c_long,
372343 pub mq_curmsgs: ::c_long,
373 _pad: [::c_int; 4]
344 _pad: [::c_int; 12]
374345 }
375346
376347 pub struct port_event {
379350 pub portev_pad: ::c_ushort,
380351 pub portev_object: ::uintptr_t,
381352 pub portev_user: *mut ::c_void,
382 }
383
384 pub struct door_desc_t__d_data__d_desc {
385 pub d_descriptor: ::c_int,
386 pub d_id: ::door_id_t
387353 }
388354
389355 pub struct exit_status {
400366 pub ut_exit: exit_status,
401367 pub ut_time: ::time_t,
402368 }
369
370 pub struct timex {
371 pub modes: u32,
372 pub offset: i32,
373 pub freq: i32,
374 pub maxerror: i32,
375 pub esterror: i32,
376 pub status: i32,
377 pub constant: i32,
378 pub precision: i32,
379 pub tolerance: i32,
380 pub ppsfreq: i32,
381 pub jitter: i32,
382 pub shift: i32,
383 pub stabil: i32,
384 pub jitcnt: i32,
385 pub calcnt: i32,
386 pub errcnt: i32,
387 pub stbcnt: i32,
388 }
389
390 pub struct ntptimeval {
391 pub time: ::timeval,
392 pub maxerror: i32,
393 pub esterror: i32,
394 }
395
403396 }
404397
405398 s_no_extra_traits! {
406 #[cfg_attr(any(target_arch = "x86", target_arch = "x86_64"), repr(packed))]
399 #[cfg_attr(all(
400 any(target_arch = "x86", target_arch = "x86_64"),
401 libc_packedN
402 ), repr(packed(4)))]
403 #[cfg_attr(all(
404 any(target_arch = "x86", target_arch = "x86_64"),
405 not(libc_packedN)
406 ), repr(packed))]
407407 pub struct epoll_event {
408408 pub events: u32,
409409 pub u64: u64,
476476 pub ss_sp: *mut ::c_void,
477477 pub sigev_notify_attributes: *const ::pthread_attr_t,
478478 __sigev_pad2: ::c_int,
479 }
480
481 pub union door_desc_t__d_data {
482 pub d_desc: door_desc_t__d_data__d_desc,
483 d_resv: [::c_int; 5], /* Check out /usr/include/sys/door.h */
484 }
485
486 pub struct door_desc_t {
487 pub d_attributes: door_attr_t,
488 pub d_data: door_desc_t__d_data,
489 }
490
491 pub struct door_arg_t {
492 pub data_ptr: *const ::c_char,
493 pub data_size: ::size_t,
494 pub desc_ptr: *const door_desc_t,
495 pub dec_num: ::c_uint,
496 pub rbuf: *const ::c_char,
497 pub rsize: ::size_t,
498479 }
499480 }
500481
535516 .field("ut_session", &self.ut_session)
536517 .field("ut_pad", &self.ut_pad)
537518 .field("ut_syslen", &self.ut_syslen)
538 .field("ut_host", &self.ut_host)
519 .field("ut_host", &&self.ut_host[..])
539520 .finish()
540521 }
541522 }
831812 pub const LC_MONETARY: ::c_int = 4;
832813 pub const LC_MESSAGES: ::c_int = 5;
833814 pub const LC_ALL: ::c_int = 6;
834 pub const LC_CTYPE_MASK: ::c_int = (1 << LC_CTYPE);
835 pub const LC_NUMERIC_MASK: ::c_int = (1 << LC_NUMERIC);
836 pub const LC_TIME_MASK: ::c_int = (1 << LC_TIME);
837 pub const LC_COLLATE_MASK: ::c_int = (1 << LC_COLLATE);
838 pub const LC_MONETARY_MASK: ::c_int = (1 << LC_MONETARY);
839 pub const LC_MESSAGES_MASK: ::c_int = (1 << LC_MESSAGES);
815 pub const LC_CTYPE_MASK: ::c_int = 1 << LC_CTYPE;
816 pub const LC_NUMERIC_MASK: ::c_int = 1 << LC_NUMERIC;
817 pub const LC_TIME_MASK: ::c_int = 1 << LC_TIME;
818 pub const LC_COLLATE_MASK: ::c_int = 1 << LC_COLLATE;
819 pub const LC_MONETARY_MASK: ::c_int = 1 << LC_MONETARY;
820 pub const LC_MESSAGES_MASK: ::c_int = 1 << LC_MESSAGES;
840821 pub const LC_ALL_MASK: ::c_int = LC_CTYPE_MASK
841822 | LC_NUMERIC_MASK
842823 | LC_TIME_MASK
987968 pub const O_EXCL: ::c_int = 1024;
988969 pub const O_NOCTTY: ::c_int = 2048;
989970 pub const O_TRUNC: ::c_int = 512;
990 pub const O_NOFOLLOW: ::c_int = 0x200000;
971 pub const O_NOFOLLOW: ::c_int = 0x20000;
991972 pub const O_SEARCH: ::c_int = 0x200000;
992973 pub const O_EXEC: ::c_int = 0x400000;
993974 pub const O_CLOEXEC: ::c_int = 0x800000;
10711052
10721053 pub const AT_FDCWD: ::c_int = 0xffd19553;
10731054 pub const AT_SYMLINK_NOFOLLOW: ::c_int = 0x1000;
1055 pub const AT_SYMLINK_FOLLOW: ::c_int = 0x2000;
1056 pub const AT_REMOVEDIR: ::c_int = 0x1;
1057 pub const _AT_TRIGGER: ::c_int = 0x2;
1058 pub const AT_EACCESS: ::c_int = 0x4;
10741059
10751060 pub const P_PID: idtype_t = 0;
10761061 pub const P_PPID: idtype_t = 1;
13261311
13271312 #[deprecated(since = "0.2.64", note = "Not stable across OS versions")]
13281313 pub const RLIM_NLIMITS: rlim_t = 7;
1329 pub const RLIM_INFINITY: rlim_t = 0x7fffffff;
1314 pub const RLIM_INFINITY: rlim_t = 0xfffffffffffffffd;
13301315
13311316 pub const RUSAGE_SELF: ::c_int = 0;
13321317 pub const RUSAGE_CHILDREN: ::c_int = -1;
13401325
13411326 pub const AF_UNSPEC: ::c_int = 0;
13421327 pub const AF_UNIX: ::c_int = 1;
1343 pub const AF_LOCAL: ::c_int = 0;
1344 pub const AF_FILE: ::c_int = 0;
13451328 pub const AF_INET: ::c_int = 2;
13461329 pub const AF_IMPLINK: ::c_int = 3;
13471330 pub const AF_PUP: ::c_int = 4;
14291412 pub const MSG_DUPCTRL: ::c_int = 0x800;
14301413 pub const MSG_XPG4_2: ::c_int = 0x8000;
14311414 pub const MSG_MAXIOVLEN: ::c_int = 16;
1415
1416 pub const IF_NAMESIZE: ::size_t = 32;
1417 pub const IFNAMSIZ: ::size_t = 16;
14321418
14331419 // https://docs.oracle.com/cd/E23824_01/html/821-1475/if-7p.html
14341420 pub const IFF_UP: ::c_int = 0x0000000001; // Address is up
17451731 pub const PORT_SOURCE_ALERT: ::c_int = 5;
17461732 pub const PORT_SOURCE_MQ: ::c_int = 6;
17471733 pub const PORT_SOURCE_FILE: ::c_int = 7;
1748 pub const PORT_SOURCE_POSTWAIT: ::c_int = 8;
1749 pub const PORT_SOURCE_SIGNAL: ::c_int = 9;
17501734
17511735 pub const NONROOT_USR: ::c_short = 2;
17521736 pub const _UTX_USERSIZE: usize = 32;
17681752
17691753 const _TIOC: ::c_int = ('T' as i32) << 8;
17701754 const tIOC: ::c_int = ('t' as i32) << 8;
1771 pub const TCGETA: ::c_int = (_TIOC | 1);
1772 pub const TCSETA: ::c_int = (_TIOC | 2);
1773 pub const TCSETAW: ::c_int = (_TIOC | 3);
1774 pub const TCSETAF: ::c_int = (_TIOC | 4);
1775 pub const TCSBRK: ::c_int = (_TIOC | 5);
1776 pub const TCXONC: ::c_int = (_TIOC | 6);
1777 pub const TCFLSH: ::c_int = (_TIOC | 7);
1778 pub const TCDSET: ::c_int = (_TIOC | 32);
1779 pub const TCGETS: ::c_int = (_TIOC | 13);
1780 pub const TCSETS: ::c_int = (_TIOC | 14);
1781 pub const TCSANOW: ::c_int = (_TIOC | 14);
1782 pub const TCSETSW: ::c_int = (_TIOC | 15);
1783 pub const TCSADRAIN: ::c_int = (_TIOC | 15);
1784 pub const TCSETSF: ::c_int = (_TIOC | 16);
1785 pub const TCSAFLUSH: ::c_int = (_TIOC | 16);
1755 pub const TCGETA: ::c_int = _TIOC | 1;
1756 pub const TCSETA: ::c_int = _TIOC | 2;
1757 pub const TCSETAW: ::c_int = _TIOC | 3;
1758 pub const TCSETAF: ::c_int = _TIOC | 4;
1759 pub const TCSBRK: ::c_int = _TIOC | 5;
1760 pub const TCXONC: ::c_int = _TIOC | 6;
1761 pub const TCFLSH: ::c_int = _TIOC | 7;
1762 pub const TCDSET: ::c_int = _TIOC | 32;
1763 pub const TCGETS: ::c_int = _TIOC | 13;
1764 pub const TCSETS: ::c_int = _TIOC | 14;
1765 pub const TCSANOW: ::c_int = _TIOC | 14;
1766 pub const TCSETSW: ::c_int = _TIOC | 15;
1767 pub const TCSADRAIN: ::c_int = _TIOC | 15;
1768 pub const TCSETSF: ::c_int = _TIOC | 16;
1769 pub const TCSAFLUSH: ::c_int = _TIOC | 16;
17861770 pub const TCIFLUSH: ::c_int = 0;
17871771 pub const TCOFLUSH: ::c_int = 1;
17881772 pub const TCIOFLUSH: ::c_int = 2;
17911775 pub const TCIOFF: ::c_int = 2;
17921776 pub const TCION: ::c_int = 3;
17931777 pub const TIOC: ::c_int = _TIOC;
1794 pub const TIOCKBON: ::c_int = (_TIOC | 8);
1795 pub const TIOCKBOF: ::c_int = (_TIOC | 9);
1796 pub const TIOCGWINSZ: ::c_int = (_TIOC | 104);
1797 pub const TIOCSWINSZ: ::c_int = (_TIOC | 103);
1798 pub const TIOCGSOFTCAR: ::c_int = (_TIOC | 105);
1799 pub const TIOCSSOFTCAR: ::c_int = (_TIOC | 106);
1800 pub const TIOCSETLD: ::c_int = (_TIOC | 123);
1801 pub const TIOCGETLD: ::c_int = (_TIOC | 124);
1802 pub const TIOCGPPS: ::c_int = (_TIOC | 125);
1803 pub const TIOCSPPS: ::c_int = (_TIOC | 126);
1804 pub const TIOCGPPSEV: ::c_int = (_TIOC | 127);
1805 pub const TIOCGETD: ::c_int = (tIOC | 0);
1806 pub const TIOCSETD: ::c_int = (tIOC | 1);
1807 pub const TIOCHPCL: ::c_int = (tIOC | 2);
1808 pub const TIOCGETP: ::c_int = (tIOC | 8);
1809 pub const TIOCSETP: ::c_int = (tIOC | 9);
1810 pub const TIOCSETN: ::c_int = (tIOC | 10);
1811 pub const TIOCEXCL: ::c_int = (tIOC | 13);
1812 pub const TIOCNXCL: ::c_int = (tIOC | 14);
1813 pub const TIOCFLUSH: ::c_int = (tIOC | 16);
1814 pub const TIOCSETC: ::c_int = (tIOC | 17);
1815 pub const TIOCGETC: ::c_int = (tIOC | 18);
1816 pub const TIOCLBIS: ::c_int = (tIOC | 127);
1817 pub const TIOCLBIC: ::c_int = (tIOC | 126);
1818 pub const TIOCLSET: ::c_int = (tIOC | 125);
1819 pub const TIOCLGET: ::c_int = (tIOC | 124);
1820 pub const TIOCSBRK: ::c_int = (tIOC | 123);
1821 pub const TIOCCBRK: ::c_int = (tIOC | 122);
1822 pub const TIOCSDTR: ::c_int = (tIOC | 121);
1823 pub const TIOCCDTR: ::c_int = (tIOC | 120);
1824 pub const TIOCSLTC: ::c_int = (tIOC | 117);
1825 pub const TIOCGLTC: ::c_int = (tIOC | 116);
1826 pub const TIOCOUTQ: ::c_int = (tIOC | 115);
1827 pub const TIOCNOTTY: ::c_int = (tIOC | 113);
1828 pub const TIOCSCTTY: ::c_int = (tIOC | 132);
1829 pub const TIOCSTOP: ::c_int = (tIOC | 111);
1830 pub const TIOCSTART: ::c_int = (tIOC | 110);
1831 pub const TIOCSILOOP: ::c_int = (tIOC | 109);
1832 pub const TIOCCILOOP: ::c_int = (tIOC | 108);
1833 pub const TIOCGPGRP: ::c_int = (tIOC | 20);
1834 pub const TIOCSPGRP: ::c_int = (tIOC | 21);
1835 pub const TIOCGSID: ::c_int = (tIOC | 22);
1836 pub const TIOCSTI: ::c_int = (tIOC | 23);
1837 pub const TIOCMSET: ::c_int = (tIOC | 26);
1838 pub const TIOCMBIS: ::c_int = (tIOC | 27);
1839 pub const TIOCMBIC: ::c_int = (tIOC | 28);
1840 pub const TIOCMGET: ::c_int = (tIOC | 29);
1841 pub const TIOCREMOTE: ::c_int = (tIOC | 30);
1842 pub const TIOCSIGNAL: ::c_int = (tIOC | 31);
1778 pub const TIOCKBON: ::c_int = _TIOC | 8;
1779 pub const TIOCKBOF: ::c_int = _TIOC | 9;
1780 pub const TIOCGWINSZ: ::c_int = _TIOC | 104;
1781 pub const TIOCSWINSZ: ::c_int = _TIOC | 103;
1782 pub const TIOCGSOFTCAR: ::c_int = _TIOC | 105;
1783 pub const TIOCSSOFTCAR: ::c_int = _TIOC | 106;
1784 pub const TIOCSETLD: ::c_int = _TIOC | 123;
1785 pub const TIOCGETLD: ::c_int = _TIOC | 124;
1786 pub const TIOCGPPS: ::c_int = _TIOC | 125;
1787 pub const TIOCSPPS: ::c_int = _TIOC | 126;
1788 pub const TIOCGPPSEV: ::c_int = _TIOC | 127;
1789 pub const TIOCGETD: ::c_int = tIOC | 0;
1790 pub const TIOCSETD: ::c_int = tIOC | 1;
1791 pub const TIOCHPCL: ::c_int = tIOC | 2;
1792 pub const TIOCGETP: ::c_int = tIOC | 8;
1793 pub const TIOCSETP: ::c_int = tIOC | 9;
1794 pub const TIOCSETN: ::c_int = tIOC | 10;
1795 pub const TIOCEXCL: ::c_int = tIOC | 13;
1796 pub const TIOCNXCL: ::c_int = tIOC | 14;
1797 pub const TIOCFLUSH: ::c_int = tIOC | 16;
1798 pub const TIOCSETC: ::c_int = tIOC | 17;
1799 pub const TIOCGETC: ::c_int = tIOC | 18;
1800 pub const TIOCLBIS: ::c_int = tIOC | 127;
1801 pub const TIOCLBIC: ::c_int = tIOC | 126;
1802 pub const TIOCLSET: ::c_int = tIOC | 125;
1803 pub const TIOCLGET: ::c_int = tIOC | 124;
1804 pub const TIOCSBRK: ::c_int = tIOC | 123;
1805 pub const TIOCCBRK: ::c_int = tIOC | 122;
1806 pub const TIOCSDTR: ::c_int = tIOC | 121;
1807 pub const TIOCCDTR: ::c_int = tIOC | 120;
1808 pub const TIOCSLTC: ::c_int = tIOC | 117;
1809 pub const TIOCGLTC: ::c_int = tIOC | 116;
1810 pub const TIOCOUTQ: ::c_int = tIOC | 115;
1811 pub const TIOCNOTTY: ::c_int = tIOC | 113;
1812 pub const TIOCSCTTY: ::c_int = tIOC | 132;
1813 pub const TIOCSTOP: ::c_int = tIOC | 111;
1814 pub const TIOCSTART: ::c_int = tIOC | 110;
1815 pub const TIOCSILOOP: ::c_int = tIOC | 109;
1816 pub const TIOCCILOOP: ::c_int = tIOC | 108;
1817 pub const TIOCGPGRP: ::c_int = tIOC | 20;
1818 pub const TIOCSPGRP: ::c_int = tIOC | 21;
1819 pub const TIOCGSID: ::c_int = tIOC | 22;
1820 pub const TIOCSTI: ::c_int = tIOC | 23;
1821 pub const TIOCMSET: ::c_int = tIOC | 26;
1822 pub const TIOCMBIS: ::c_int = tIOC | 27;
1823 pub const TIOCMBIC: ::c_int = tIOC | 28;
1824 pub const TIOCMGET: ::c_int = tIOC | 29;
1825 pub const TIOCREMOTE: ::c_int = tIOC | 30;
1826 pub const TIOCSIGNAL: ::c_int = tIOC | 31;
18431827
18441828 pub const EPOLLIN: ::c_int = 0x1;
18451829 pub const EPOLLPRI: ::c_int = 0x2;
18531837 pub const EPOLLHUP: ::c_int = 0x10;
18541838 pub const EPOLLET: ::c_int = 0x80000000;
18551839 pub const EPOLLRDHUP: ::c_int = 0x2000;
1856 pub const EPOLLEXCLUSIVE: ::c_int = 0x10000000;
18571840 pub const EPOLLONESHOT: ::c_int = 0x40000000;
18581841 pub const EPOLL_CLOEXEC: ::c_int = 0x80000;
18591842 pub const EPOLL_CTL_ADD: ::c_int = 1;
18851868 pub const B307200: speed_t = 21;
18861869 pub const B460800: speed_t = 22;
18871870 pub const B921600: speed_t = 23;
1888 pub const CSTART: ::tcflag_t = 021;
1889 pub const CSTOP: ::tcflag_t = 023;
1890 pub const CSWTCH: ::tcflag_t = 032;
1871 pub const CSTART: ::tcflag_t = 0o21;
1872 pub const CSTOP: ::tcflag_t = 0o23;
1873 pub const CSWTCH: ::tcflag_t = 0o32;
18911874 pub const CSIZE: ::tcflag_t = 0o000060;
18921875 pub const CS5: ::tcflag_t = 0;
18931876 pub const CS6: ::tcflag_t = 0o000020;
19591942 pub const SOCK_NONBLOCK: ::c_int = 0x100000;
19601943 pub const SOCK_NDELAY: ::c_int = 0x200000;
19611944
1945 //<sys/timex.h>
1946 pub const SCALE_KG: ::c_int = 1 << 6;
1947 pub const SCALE_KF: ::c_int = 1 << 16;
1948 pub const SCALE_KH: ::c_int = 1 << 2;
1949 pub const MAXTC: ::c_int = 1 << 6;
1950 pub const SCALE_PHASE: ::c_int = 1 << 22;
1951 pub const SCALE_USEC: ::c_int = 1 << 16;
1952 pub const SCALE_UPDATE: ::c_int = SCALE_KG * MAXTC;
1953 pub const FINEUSEC: ::c_int = 1 << 22;
1954 pub const MAXPHASE: ::c_int = 512000;
1955 pub const MAXFREQ: ::c_int = 512 * SCALE_USEC;
1956 pub const MAXTIME: ::c_int = 200 << PPS_AVG;
1957 pub const MINSEC: ::c_int = 16;
1958 pub const MAXSEC: ::c_int = 1200;
1959 pub const PPS_AVG: ::c_int = 2;
1960 pub const PPS_SHIFT: ::c_int = 2;
1961 pub const PPS_SHIFTMAX: ::c_int = 8;
1962 pub const PPS_VALID: ::c_int = 120;
1963 pub const MAXGLITCH: ::c_int = 30;
1964 pub const MOD_OFFSET: u32 = 0x0001;
1965 pub const MOD_FREQUENCY: u32 = 0x0002;
1966 pub const MOD_MAXERROR: u32 = 0x0004;
1967 pub const MOD_ESTERROR: u32 = 0x0008;
1968 pub const MOD_STATUS: u32 = 0x0010;
1969 pub const MOD_TIMECONST: u32 = 0x0020;
1970 pub const MOD_CLKB: u32 = 0x4000;
1971 pub const MOD_CLKA: u32 = 0x8000;
1972 pub const STA_PLL: u32 = 0x0001;
1973 pub const STA_PPSFREQ: i32 = 0x0002;
1974 pub const STA_PPSTIME: i32 = 0x0004;
1975 pub const STA_FLL: i32 = 0x0008;
1976 pub const STA_INS: i32 = 0x0010;
1977 pub const STA_DEL: i32 = 0x0020;
1978 pub const STA_UNSYNC: i32 = 0x0040;
1979 pub const STA_FREQHOLD: i32 = 0x0080;
1980 pub const STA_PPSSIGNAL: i32 = 0x0100;
1981 pub const STA_PPSJITTER: i32 = 0x0200;
1982 pub const STA_PPSWANDER: i32 = 0x0400;
1983 pub const STA_PPSERROR: i32 = 0x0800;
1984 pub const STA_CLOCKERR: i32 = 0x1000;
1985 pub const STA_RONLY: i32 = STA_PPSSIGNAL
1986 | STA_PPSJITTER
1987 | STA_PPSWANDER
1988 | STA_PPSERROR
1989 | STA_CLOCKERR;
1990 pub const TIME_OK: i32 = 0;
1991 pub const TIME_INS: i32 = 1;
1992 pub const TIME_DEL: i32 = 2;
1993 pub const TIME_OOP: i32 = 3;
1994 pub const TIME_WAIT: i32 = 4;
1995 pub const TIME_ERROR: i32 = 5;
1996
19621997 f! {
19631998 pub fn FD_CLR(fd: ::c_int, set: *mut fd_set) -> () {
19641999 let bits = ::mem::size_of_val(&(*set).fds_bits[0]) * 8;
20502085 pub fn freeifaddrs(ifa: *mut ::ifaddrs);
20512086
20522087 pub fn stack_getbounds(sp: *mut ::stack_t) -> ::c_int;
2053 pub fn mincore(
2054 addr: *const ::c_void,
2055 len: ::size_t,
2056 vec: *mut c_char,
2057 ) -> ::c_int;
20582088 pub fn initgroups(name: *const ::c_char, basegid: ::gid_t) -> ::c_int;
20592089 pub fn setgroups(ngroups: ::c_int, ptr: *const ::gid_t) -> ::c_int;
20602090 pub fn ioctl(fildes: ::c_int, request: ::c_int, ...) -> ::c_int;
21502180 options: ::c_int,
21512181 ) -> ::c_int;
21522182
2183 #[cfg_attr(target_os = "illumos", link_name = "_glob_ext")]
21532184 pub fn glob(
21542185 pattern: *const ::c_char,
21552186 flags: ::c_int,
21592190 pglob: *mut ::glob_t,
21602191 ) -> ::c_int;
21612192
2193 #[cfg_attr(target_os = "illumos", link_name = "_globfree_ext")]
21622194 pub fn globfree(pglob: *mut ::glob_t);
21632195
21642196 pub fn posix_madvise(
22602292 msg: *mut ::msghdr,
22612293 flags: ::c_int,
22622294 ) -> ::ssize_t;
2295 pub fn accept4(
2296 fd: ::c_int,
2297 address: *mut sockaddr,
2298 address_len: *mut socklen_t,
2299 flags: ::c_int
2300 ) -> ::c_int;
22632301
22642302 pub fn mq_open(name: *const ::c_char, oflag: ::c_int, ...) -> ::mqd_t;
22652303 pub fn mq_close(mqd: ::mqd_t) -> ::c_int;
23212359 nget: *mut ::c_uint,
23222360 timeout: *mut ::timespec,
23232361 ) -> ::c_int;
2324 pub fn fexecve(
2325 fd: ::c_int,
2326 argv: *const *const ::c_char,
2327 envp: *const *const ::c_char,
2362 pub fn port_send(
2363 port: ::c_int,
2364 events: ::c_int,
2365 user: *mut ::c_void,
2366 ) -> ::c_int;
2367 pub fn port_sendn(
2368 port_list: *mut ::c_int,
2369 error_list: *mut ::c_int,
2370 nent: ::c_uint,
2371 events: ::c_int,
2372 user: *mut ::c_void,
23282373 ) -> ::c_int;
23292374 #[cfg_attr(
23302375 any(target_os = "solaris", target_os = "illumos"),
24502495 pub fn dup3(src: ::c_int, dst: ::c_int, flags: ::c_int) -> ::c_int;
24512496 pub fn uname(buf: *mut ::utsname) -> ::c_int;
24522497 pub fn pipe2(fds: *mut ::c_int, flags: ::c_int) -> ::c_int;
2453 pub fn door_call(d: ::c_int, params: *const door_arg_t) -> ::c_int;
2454 pub fn door_return(
2455 data_ptr: *const ::c_char,
2456 data_size: ::size_t,
2457 desc_ptr: *const door_desc_t,
2458 num_desc: ::c_uint,
2459 );
2460 pub fn door_create(
2461 server_procedure: extern "C" fn(
2462 cookie: *const ::c_void,
2463 argp: *const ::c_char,
2464 arg_size: ::size_t,
2465 dp: *const door_desc_t,
2466 n_desc: ::c_uint,
2467 ),
2468 cookie: *const ::c_void,
2469 attributes: door_attr_t,
2470 ) -> ::c_int;
2471 pub fn fattach(fildes: ::c_int, path: *const ::c_char) -> ::c_int;
24722498
24732499 pub fn makeutx(ux: *const utmpx) -> *mut utmpx;
24742500 pub fn modutx(ux: *const utmpx) -> *mut utmpx;
24922518 pub fn getutmp(ux: *const utmpx, u: *mut utmp);
24932519 pub fn getutmpx(u: *const utmp, ux: *mut utmpx);
24942520 pub fn updwtmp(file: *const ::c_char, u: *mut utmp);
2521
2522 pub fn ntp_adjtime(buf: *mut timex) -> ::c_int;
2523 pub fn ntp_gettime(buf: *mut ntptimeval) -> ::c_int;
24952524 }
24962525
24972526 mod compat;
24982527 pub use self::compat::*;
2528
2529 cfg_if! {
2530 if #[cfg(target_os = "illumos")] {
2531 mod illumos;
2532 pub use self::illumos::*;
2533 } else if #[cfg(target_os = "solaris")] {
2534 mod solaris;
2535 pub use self::solaris::*;
2536 } else {
2537 // Unknown target_os
2538 }
2539 }
0 pub type door_attr_t = ::c_uint;
1 pub type door_id_t = ::c_ulonglong;
2
3 s! {
4 pub struct shmid_ds {
5 pub shm_perm: ::ipc_perm,
6 pub shm_segsz: ::size_t,
7 pub shm_flags: ::uintptr_t,
8 pub shm_lkcnt: ::c_ushort,
9 pub shm_lpid: ::pid_t,
10 pub shm_cpid: ::pid_t,
11 pub shm_nattch: ::shmatt_t,
12 pub shm_cnattch: ::c_ulong,
13 pub shm_atime: ::time_t,
14 pub shm_dtime: ::time_t,
15 pub shm_ctime: ::time_t,
16 pub shm_amp: *mut ::c_void,
17 pub shm_gransize: u64,
18 pub shm_allocated: u64,
19 pub shm_pad4: [i64; 1],
20 }
21
22 pub struct door_desc_t__d_data__d_desc {
23 pub d_descriptor: ::c_int,
24 pub d_id: ::door_id_t
25 }
26 }
27
28 pub const PORT_SOURCE_POSTWAIT: ::c_int = 8;
29 pub const PORT_SOURCE_SIGNAL: ::c_int = 9;
30
31 pub const EPOLLEXCLUSIVE: ::c_int = 0x10000000;
32
33 pub const AF_LOCAL: ::c_int = 0;
34 pub const AF_FILE: ::c_int = 0;
35
36 extern "C" {
37 pub fn fexecve(
38 fd: ::c_int,
39 argv: *const *const ::c_char,
40 envp: *const *const ::c_char,
41 ) -> ::c_int;
42
43 pub fn mincore(
44 addr: *const ::c_void,
45 len: ::size_t,
46 vec: *mut ::c_char,
47 ) -> ::c_int;
48
49 pub fn door_call(d: ::c_int, params: *const door_arg_t) -> ::c_int;
50 pub fn door_return(
51 data_ptr: *const ::c_char,
52 data_size: ::size_t,
53 desc_ptr: *const door_desc_t,
54 num_desc: ::c_uint,
55 );
56 pub fn door_create(
57 server_procedure: extern "C" fn(
58 cookie: *const ::c_void,
59 argp: *const ::c_char,
60 arg_size: ::size_t,
61 dp: *const door_desc_t,
62 n_desc: ::c_uint,
63 ),
64 cookie: *const ::c_void,
65 attributes: door_attr_t,
66 ) -> ::c_int;
67
68 pub fn fattach(fildes: ::c_int, path: *const ::c_char) -> ::c_int;
69 }
70
71 s_no_extra_traits! {
72 #[cfg_attr(feature = "extra_traits", allow(missing_debug_implementations))]
73 pub union door_desc_t__d_data {
74 pub d_desc: door_desc_t__d_data__d_desc,
75 d_resv: [::c_int; 5], /* Check out /usr/include/sys/door.h */
76 }
77
78 #[cfg_attr(feature = "extra_traits", allow(missing_debug_implementations))]
79 pub struct door_desc_t {
80 pub d_attributes: door_attr_t,
81 pub d_data: door_desc_t__d_data,
82 }
83
84 #[cfg_attr(feature = "extra_traits", allow(missing_debug_implementations))]
85 pub struct door_arg_t {
86 pub data_ptr: *const ::c_char,
87 pub data_size: ::size_t,
88 pub desc_ptr: *const door_desc_t,
89 pub dec_num: ::c_uint,
90 pub rbuf: *const ::c_char,
91 pub rsize: ::size_t,
92 }
93 }
2222 pub type idtype_t = ::c_uint;
2323
2424 #[cfg_attr(feature = "extra_traits", derive(Debug))]
25 pub enum fpos64_t {} // TODO: fill this out with a struct
25 pub enum fpos64_t {} // FIXME: fill this out with a struct
2626 impl ::Copy for fpos64_t {}
2727 impl ::Clone for fpos64_t {
2828 fn clone(&self) -> fpos64_t {
500500 pub const F_NOTIFY: ::c_int = 1026;
501501 pub const F_DUPFD_CLOEXEC: ::c_int = 1030;
502502
503 // TODO(#235): Include file sealing fcntls once we have a way to verify them.
503 // FIXME(#235): Include file sealing fcntls once we have a way to verify them.
504504
505505 pub const SIGTRAP: ::c_int = 5;
506506
511511 pub const CLOCK_MONOTONIC: ::clockid_t = 1;
512512 pub const CLOCK_PROCESS_CPUTIME_ID: ::clockid_t = 2;
513513 pub const CLOCK_THREAD_CPUTIME_ID: ::clockid_t = 3;
514 // TODO(#247) Someday our Travis shall have glibc 2.21 (released in Sep
515 // 2014.) See also musl/mod.rs
514 // FIXME: Add these constants once uclibc gets them.
516515 // pub const CLOCK_SGI_CYCLE: ::clockid_t = 10;
517516 // pub const CLOCK_TAI: ::clockid_t = 11;
518517 pub const TIMER_ABSTIME: ::c_int = 1;
587586 pub const LC_COLLATE: ::c_int = 4;
588587 pub const LC_MESSAGES: ::c_int = 5;
589588 pub const LC_ALL: ::c_int = 6;
590 pub const LC_CTYPE_MASK: ::c_int = (1 << LC_CTYPE);
591 pub const LC_NUMERIC_MASK: ::c_int = (1 << LC_NUMERIC);
592 pub const LC_TIME_MASK: ::c_int = (1 << LC_TIME);
593 pub const LC_COLLATE_MASK: ::c_int = (1 << LC_COLLATE);
594 pub const LC_MONETARY_MASK: ::c_int = (1 << LC_MONETARY);
595 pub const LC_MESSAGES_MASK: ::c_int = (1 << LC_MESSAGES);
589 pub const LC_CTYPE_MASK: ::c_int = 1 << LC_CTYPE;
590 pub const LC_NUMERIC_MASK: ::c_int = 1 << LC_NUMERIC;
591 pub const LC_TIME_MASK: ::c_int = 1 << LC_TIME;
592 pub const LC_COLLATE_MASK: ::c_int = 1 << LC_COLLATE;
593 pub const LC_MONETARY_MASK: ::c_int = 1 << LC_MONETARY;
594 pub const LC_MESSAGES_MASK: ::c_int = 1 << LC_MESSAGES;
596595 // LC_ALL_MASK defined per platform
597596
598597 pub const MAP_FILE: ::c_int = 0x0000;
10451044 pub const AT_FDCWD: ::c_int = -100;
10461045 pub const AT_SYMLINK_NOFOLLOW: ::c_int = 0x100;
10471046 pub const AT_REMOVEDIR: ::c_int = 0x200;
1047 pub const AT_EACCESS: ::c_int = 0x200;
10481048 pub const AT_SYMLINK_FOLLOW: ::c_int = 0x400;
10491049
10501050 pub const LOG_CRON: ::c_int = 9 << 3;
21842184 msg: *mut ::msghdr,
21852185 flags: ::c_int,
21862186 ) -> ::ssize_t;
2187 #[cfg_attr(target_os = "solaris", link_name = "__posix_getgrgid_r")]
21882187 pub fn getgrgid_r(
21892188 gid: ::gid_t,
21902189 grp: *mut ::group,
21922191 buflen: ::size_t,
21932192 result: *mut *mut ::group,
21942193 ) -> ::c_int;
2195 #[cfg_attr(
2196 all(target_os = "macos", target_arch = "x86"),
2197 link_name = "sigaltstack$UNIX2003"
2198 )]
2199 #[cfg_attr(target_os = "netbsd", link_name = "__sigaltstack14")]
22002194 pub fn sigaltstack(ss: *const stack_t, oss: *mut stack_t) -> ::c_int;
22012195 pub fn sem_close(sem: *mut sem_t) -> ::c_int;
22022196 pub fn getdtablesize() -> ::c_int;
2203 #[cfg_attr(target_os = "solaris", link_name = "__posix_getgrnam_r")]
22042197 pub fn getgrnam_r(
22052198 name: *const ::c_char,
22062199 grp: *mut ::group,
22082201 buflen: ::size_t,
22092202 result: *mut *mut ::group,
22102203 ) -> ::c_int;
2211 #[cfg_attr(
2212 all(target_os = "macos", target_arch = "x86"),
2213 link_name = "pthread_sigmask$UNIX2003"
2214 )]
22152204 pub fn pthread_sigmask(
22162205 how: ::c_int,
22172206 set: *const sigset_t,
22222211 pub fn pthread_kill(thread: ::pthread_t, sig: ::c_int) -> ::c_int;
22232212 pub fn sem_unlink(name: *const ::c_char) -> ::c_int;
22242213 pub fn daemon(nochdir: ::c_int, noclose: ::c_int) -> ::c_int;
2225 #[cfg_attr(target_os = "netbsd", link_name = "__getpwnam_r50")]
2226 #[cfg_attr(target_os = "solaris", link_name = "__posix_getpwnam_r")]
22272214 pub fn getpwnam_r(
22282215 name: *const ::c_char,
22292216 pwd: *mut passwd,
22312218 buflen: ::size_t,
22322219 result: *mut *mut passwd,
22332220 ) -> ::c_int;
2234 #[cfg_attr(target_os = "netbsd", link_name = "__getpwuid_r50")]
2235 #[cfg_attr(target_os = "solaris", link_name = "__posix_getpwuid_r")]
22362221 pub fn getpwuid_r(
22372222 uid: ::uid_t,
22382223 pwd: *mut passwd,
22402225 buflen: ::size_t,
22412226 result: *mut *mut passwd,
22422227 ) -> ::c_int;
2243 #[cfg_attr(
2244 all(target_os = "macos", target_arch = "x86"),
2245 link_name = "sigwait$UNIX2003"
2246 )]
2247 #[cfg_attr(target_os = "solaris", link_name = "__posix_sigwait")]
22482228 pub fn sigwait(set: *const sigset_t, sig: *mut ::c_int) -> ::c_int;
22492229 pub fn pthread_atfork(
22502230 prepare: ::Option<unsafe extern "C" fn()>,
22582238 value: *mut ::c_void,
22592239 ) -> ::c_int;
22602240 pub fn getgrgid(gid: ::gid_t) -> *mut ::group;
2261 #[cfg_attr(
2262 all(target_os = "macos", target_arch = "x86"),
2263 link_name = "popen$UNIX2003"
2264 )]
22652241 pub fn popen(command: *const c_char, mode: *const c_char) -> *mut ::FILE;
22662242 pub fn uname(buf: *mut ::utsname) -> ::c_int;
22672243 }
44 repr(align(4)))]
55 #[cfg_attr(target_pointer_width = "64",
66 repr(align(8)))]
7 pub struct sem_t { // ToDo
7 pub struct sem_t { // FIXME
88 #[cfg(target_pointer_width = "32")]
99 __size: [::c_char; 16],
1010 #[cfg(target_pointer_width = "64")]
2525 target_arch = "s390x",
2626 target_arch = "sparc64")),
2727 repr(align(8)))]
28 pub struct pthread_mutexattr_t { // ToDo
28 pub struct pthread_mutexattr_t { // FIXME
2929 size: [u8; ::__SIZEOF_PTHREAD_MUTEXATTR_T],
3030 }
3131
3232 #[repr(align(4))]
33 pub struct pthread_condattr_t { // ToDo
33 pub struct pthread_condattr_t { // FIXME
3434 size: [u8; ::__SIZEOF_PTHREAD_CONDATTR_T],
3535 }
3636 }
4747 target_arch = "powerpc")))),
4848 repr(align(8)))]
4949 #[allow(missing_debug_implementations)]
50 pub struct pthread_mutex_t { // ToDo
50 pub struct pthread_mutex_t { // FIXME
5151 size: [u8; ::__SIZEOF_PTHREAD_MUTEX_T],
5252 }
5353
5454 #[repr(align(8))]
5555 #[allow(missing_debug_implementations)]
56 pub struct pthread_cond_t { // ToDo
56 pub struct pthread_cond_t { // FIXME
5757 size: [u8; ::__SIZEOF_PTHREAD_COND_T],
5858 }
5959
6868 target_arch = "powerpc"))),
6969 repr(align(8)))]
7070 #[allow(missing_debug_implementations)]
71 pub struct pthread_rwlock_t { // ToDo
71 pub struct pthread_rwlock_t { // FIXME
7272 size: [u8; ::__SIZEOF_PTHREAD_RWLOCK_T],
7373 }
7474 }
146146 pub sa_mask: ::sigset_t,
147147 }
148148
149 pub struct stack_t { // ToDo
149 pub struct stack_t { // FIXME
150150 pub ss_sp: *mut ::c_void,
151151 pub ss_flags: ::c_int,
152152 pub ss_size: ::size_t
153153 }
154154
155 pub struct statfs { // ToDo
155 pub struct statfs { // FIXME
156156 pub f_type: fsword_t,
157157 pub f_bsize: fsword_t,
158158 pub f_blocks: ::fsblkcnt_t,
166166 f_spare: [fsword_t; 5],
167167 }
168168
169 pub struct msghdr { // ToDo
169 pub struct msghdr { // FIXME
170170 pub msg_name: *mut ::c_void,
171171 pub msg_namelen: ::socklen_t,
172172 pub msg_iov: *mut ::iovec,
176176 pub msg_flags: ::c_int,
177177 }
178178
179 pub struct termios { // ToDo
179 pub struct termios { // FIXME
180180 pub c_iflag: ::tcflag_t,
181181 pub c_oflag: ::tcflag_t,
182182 pub c_cflag: ::tcflag_t,
185185 pub c_cc: [::cc_t; ::NCCS],
186186 }
187187
188 pub struct sigset_t { // ToDo
188 pub struct sigset_t { // FIXME
189189 __val: [::c_ulong; 16],
190190 }
191191
192 pub struct sysinfo { // ToDo
192 pub struct sysinfo { // FIXME
193193 pub uptime: ::c_long,
194194 pub loads: [::c_ulong; 3],
195195 pub totalram: ::c_ulong,
206206 pub _f: [::c_char; 0],
207207 }
208208
209 pub struct glob_t { // ToDo
209 pub struct glob_t { // FIXME
210210 pub gl_pathc: ::size_t,
211211 pub gl_pathv: *mut *mut c_char,
212212 pub gl_offs: ::size_t,
218218 __unused5: *mut ::c_void,
219219 }
220220
221 pub struct rlimit64 { // ToDo
221 pub struct rlimit64 { // FIXME
222222 pub rlim_cur: rlim64_t,
223223 pub rlim_max: rlim64_t,
224224 }
225225
226 pub struct cpu_set_t { // ToDo
226 pub struct cpu_set_t { // FIXME
227227 #[cfg(target_pointer_width = "32")]
228228 bits: [u32; 32],
229229 #[cfg(target_pointer_width = "64")]
230230 bits: [u64; 16],
231231 }
232232
233 pub struct fsid_t { // ToDo
233 pub struct fsid_t { // FIXME
234234 __val: [::c_int; 2],
235235 }
236236 }
00 macro_rules! expand_align {
11 () => {
22 s! {
3 pub struct sem_t { // ToDo
3 pub struct sem_t { // FIXME
44 #[cfg(target_pointer_width = "32")]
55 __size: [::c_char; 16],
66 #[cfg(target_pointer_width = "64")]
88 __align: [::c_long; 0],
99 }
1010
11 pub struct pthread_mutex_t { // ToDo
11 pub struct pthread_mutex_t { // FIXME
1212 #[cfg(any(target_arch = "mips",
1313 target_arch = "arm",
1414 target_arch = "powerpc"))]
2020 size: [u8; ::__SIZEOF_PTHREAD_MUTEX_T],
2121 }
2222
23 pub struct pthread_mutexattr_t { // ToDo
23 pub struct pthread_mutexattr_t { // FIXME
2424 #[cfg(any(target_arch = "x86_64", target_arch = "powerpc64",
2525 target_arch = "mips64", target_arch = "s390x",
2626 target_arch = "sparc64"))]
3232 size: [u8; ::__SIZEOF_PTHREAD_MUTEXATTR_T],
3333 }
3434
35 pub struct pthread_cond_t { // ToDo
35 pub struct pthread_cond_t { // FIXME
3636 __align: [::c_longlong; 0],
3737 size: [u8; ::__SIZEOF_PTHREAD_COND_T],
3838 }
3939
40 pub struct pthread_condattr_t { // ToDo
40 pub struct pthread_condattr_t { // FIXME
4141 __align: [::c_int; 0],
4242 size: [u8; ::__SIZEOF_PTHREAD_CONDATTR_T],
4343 }
4444
45 pub struct pthread_rwlock_t { // ToDo
45 pub struct pthread_rwlock_t { // FIXME
4646 #[cfg(any(target_arch = "mips",
4747 target_arch = "arm",
4848 target_arch = "powerpc"))]
9898 pub type _Vx_ticks64_t = ::c_ulonglong;
9999
100100 pub type sa_family_t = ::c_uchar;
101
102 // mqueue.h
103 pub type mqd_t = ::c_int;
101104
102105 #[cfg_attr(feature = "extra_traits", derive(Debug))]
103106 pub enum _Vx_semaphore {}
377380 pub dli_fbase: *mut ::c_void,
378381 pub dli_sname: *const ::c_char,
379382 pub dli_saddr: *mut ::c_void,
383 }
384
385 pub struct mq_attr {
386 pub mq_maxmsg: ::c_long,
387 pub mq_msgsize: ::c_long,
388 pub mq_flags: ::c_long,
389 pub mq_curmsgs: ::c_long,
380390 }
381391 }
382392
771781 pub const _SS_MAXSIZE: usize = 128;
772782 pub const _SS_ALIGNSIZE: usize = size_of::<u32>();
773783 pub const _SS_PAD1SIZE: usize =
774 (_SS_ALIGNSIZE - size_of::<::c_uchar>() - size_of::<::sa_family_t>());
775 pub const _SS_PAD2SIZE: usize = (_SS_MAXSIZE
784 _SS_ALIGNSIZE - size_of::<::c_uchar>() - size_of::<::sa_family_t>();
785 pub const _SS_PAD2SIZE: usize = _SS_MAXSIZE
776786 - size_of::<::c_uchar>()
777787 - size_of::<::sa_family_t>()
778788 - _SS_PAD1SIZE
779 - _SS_ALIGNSIZE);
789 - _SS_ALIGNSIZE;
780790
781791 pub const MSG_OOB: ::c_int = 0x0001;
782792 pub const MSG_PEEK: ::c_int = 0x0002;
9981008 }
9991009 }
10001010 #[cfg_attr(feature = "extra_traits", derive(Debug))]
1001 pub enum fpos_t {} // TODO: fill this out with a struct
1011 pub enum fpos_t {} // FIXME: fill this out with a struct
10021012 impl ::Copy for fpos_t {}
10031013 impl ::Clone for fpos_t {
10041014 fn clone(&self) -> fpos_t {
11721182 ) -> ::size_t;
11731183
11741184 pub fn memchr(cx: *const c_void, c: c_int, n: size_t) -> *mut c_void;
1185 pub fn wmemchr(cx: *const wchar_t, c: wchar_t, n: size_t) -> *mut wchar_t;
11751186 pub fn memcmp(cx: *const c_void, ct: *const c_void, n: size_t) -> c_int;
11761187 pub fn memcpy(
11771188 dest: *mut c_void,
19701981 pub fn randABytes(buf: *mut c_uchar, length: c_int) -> c_int;
19711982 pub fn randUBytes(buf: *mut c_uchar, length: c_int) -> c_int;
19721983 pub fn randSecure() -> c_int;
1984
1985 // mqueue.h
1986 pub fn mq_open(name: *const ::c_char, oflag: ::c_int, ...) -> ::mqd_t;
1987 pub fn mq_close(mqd: ::mqd_t) -> ::c_int;
1988 pub fn mq_unlink(name: *const ::c_char) -> ::c_int;
1989 pub fn mq_receive(
1990 mqd: ::mqd_t,
1991 msg_ptr: *mut ::c_char,
1992 msg_len: ::size_t,
1993 msg_prio: *mut ::c_uint,
1994 ) -> ::ssize_t;
1995 pub fn mq_timedreceive(
1996 mqd: ::mqd_t,
1997 msg_ptr: *mut ::c_char,
1998 msg_len: ::size_t,
1999 msg_prio: *mut ::c_uint,
2000 abs_timeout: *const ::timespec,
2001 ) -> ::ssize_t;
2002 pub fn mq_send(
2003 mqd: ::mqd_t,
2004 msg_ptr: *const ::c_char,
2005 msg_len: ::size_t,
2006 msg_prio: ::c_uint,
2007 ) -> ::c_int;
2008 pub fn mq_timedsend(
2009 mqd: ::mqd_t,
2010 msg_ptr: *const ::c_char,
2011 msg_len: ::size_t,
2012 msg_prio: ::c_uint,
2013 abs_timeout: *const ::timespec,
2014 ) -> ::c_int;
2015 pub fn mq_getattr(mqd: ::mqd_t, attr: *mut ::mq_attr) -> ::c_int;
2016 pub fn mq_setattr(
2017 mqd: ::mqd_t,
2018 newattr: *const ::mq_attr,
2019 oldattr: *mut ::mq_attr,
2020 ) -> ::c_int;
19732021 }
19742022
19752023 //Dummy functions, these don't really exist in VxWorks.
173173 pub const STDIN_FILENO: c_int = 0;
174174 pub const STDOUT_FILENO: c_int = 1;
175175 pub const STDERR_FILENO: c_int = 2;
176 pub const SEEK_SET: c_int = 2;
177 pub const SEEK_CUR: c_int = 0;
178 pub const SEEK_END: c_int = 1;
176 pub const SEEK_SET: c_int = 0;
177 pub const SEEK_CUR: c_int = 1;
178 pub const SEEK_END: c_int = 2;
179179 pub const _IOFBF: c_int = 0;
180180 pub const _IONBF: c_int = 2;
181181 pub const _IOLBF: c_int = 1;
206206 pub const AT_SYMLINK_NOFOLLOW: c_int = 0x1;
207207 pub const AT_SYMLINK_FOLLOW: c_int = 0x2;
208208 pub const AT_REMOVEDIR: c_int = 0x4;
209 pub const UTIME_OMIT: c_long = 1073741822;
210 pub const UTIME_NOW: c_long = 1073741823;
209 pub const UTIME_OMIT: c_long = 0xfffffffe;
210 pub const UTIME_NOW: c_long = 0xffffffff;
211211
212212 pub const E2BIG: c_int = 1;
213213 pub const EACCES: c_int = 2;
727727 pub fn __wasilibc_fd_renumber(fd: c_int, newfd: c_int) -> c_int;
728728 pub fn __wasilibc_unlinkat(fd: c_int, path: *const c_char) -> c_int;
729729 pub fn __wasilibc_rmdirat(fd: c_int, path: *const c_char) -> c_int;
730 pub fn __wasilibc_init_preopen();
731730 pub fn __wasilibc_find_relpath(
732731 path: *const c_char,
733 rights_base: __wasi_rights_t,
734 rights_inheriting: __wasi_rights_t,
735732 relative_path: *mut *const c_char,
736733 ) -> c_int;
737734 pub fn __wasilibc_tell(fd: c_int) -> ::off_t;
1212 s2: *const ::c_char,
1313 n: ::size_t,
1414 ) -> ::c_int;
15
16 // NOTE: For MSVC target, `wmemchr` is only a inline function in `<wchar.h>`
17 // header file. We cannot find a way to link to that symbol from Rust.
18 pub fn wmemchr(
19 cx: *const ::wchar_t,
20 c: ::wchar_t,
21 n: ::size_t,
22 ) -> *mut ::wchar_t;
1523 }
1624
1725 cfg_if! {
249249 }
250250 }
251251 #[cfg_attr(feature = "extra_traits", derive(Debug))]
252 pub enum fpos_t {} // TODO: fill this out with a struct
252 pub enum fpos_t {} // FIXME: fill this out with a struct
253253 impl ::Copy for fpos_t {}
254254 impl ::Clone for fpos_t {
255255 fn clone(&self) -> fpos_t {
399399 pub fn signal(signum: c_int, handler: sighandler_t) -> sighandler_t;
400400 pub fn raise(signum: c_int) -> c_int;
401401
402 #[link_name = "_gmtime64_s"]
403 pub fn gmtime_s(destTime: *mut tm, srcTime: *const time_t) -> ::c_int;
402404 #[link_name = "_time64"]
403405 pub fn time(destTime: *mut time_t) -> time_t;
404406 #[link_name = "_chmod"]
0 {"files":{"COPYING":"01c266bced4a434da0051174d6bee16a4c82cf634e2679b6155d40d75012390f","Cargo.toml":"d909aa4ca83bd6d41f1f6f1ab4ca2af8019c1dbbadfc47084acc5b85105bddad","LICENSE-MIT":"0f96a83840e146e43c0ec96a22ec1f392e0680e6c1226e6f3ba87e0740af850f","README.md":"d2ab7c9c77235b68d1cc856ab5ef7b5115312098469edcac9d5611c5b74d3cd1","UNLICENSE":"7e12e5df4bae12cb21581ba157ced20e1986a0508dd10d0e8a4ab9a4cf94e85c","build.rs":"ed35d244304888581bfcbdc52596721a5bbb908bcbd56bbdfe977800ef3042e1","rustfmt.toml":"1ca600239a27401c4a43f363cf3f38183a212affc1f31bff3ae93234bbaec228","src/c.rs":"86fe35cbb46c8bece9927fbde20f1ca3af526defdde05ac969ad2f4bc9bb25e9","src/fallback.rs":"79519255d480a9c2667c06f9287931cfc2b85f6af6fcf92d453a11ee161dcb74","src/iter.rs":"23b1066d6b40159fe944388db7743c89422b1110ddb44667fde6d722f178ed4e","src/lib.rs":"278f45f16375f084b3d96ffaea40bc8944c3bc252e09a1c2f173e8c121e082fd","src/naive.rs":"c7453bc99cc4e58eb37cf5a50c88688833e50a270ee1849baefddb8acc0ccd94","src/tests/iter.rs":"8d5999a2a5b8a3228c76cd82cd3ee86dfa6f7b4022405b1f06eedf7d74e4c704","src/tests/memchr.rs":"f30074eeab99a16ce5ca8a30f1890f86c43c0422523a7195cbb3ca5f3e465b67","src/tests/miri.rs":"27859a7ac1d0a9305b2d114e6dd8876f3d5e47fc46a81be96239c793ac6edb1f","src/tests/mod.rs":"2ad0c82d33b32562087254522641ea7bfa2a283130152be5e927a33f1978ebc7","src/x86/avx.rs":"b19987410e49a079f33162424c42494626c91303c41824961e478be3b537c9c9","src/x86/mod.rs":"0b13becaabc150a0099f7528226c82e288136cc7ebcdb8e96cf5ee9aae0f05b6","src/x86/sse2.rs":"7c1b8248a8cd48396cb70a862d77f9a972f1e16324d65c260f39d13af73bf638","src/x86/sse42.rs":"f671ae9dd2b518a823e499a09ce32d4957bc5ae043db90d61c027e32f688f2b2"},"package":"53445de381a1f436797497c61d851644d0e8e88e6140f22872ad33a704933978"}
0 {"files":{"COPYING":"01c266bced4a434da0051174d6bee16a4c82cf634e2679b6155d40d75012390f","Cargo.toml":"7f0cb3d85439207568f7bb264b9fd5c8c5f5dedf9ee428813ee5d686ca37df18","LICENSE-MIT":"0f96a83840e146e43c0ec96a22ec1f392e0680e6c1226e6f3ba87e0740af850f","README.md":"d2ab7c9c77235b68d1cc856ab5ef7b5115312098469edcac9d5611c5b74d3cd1","UNLICENSE":"7e12e5df4bae12cb21581ba157ced20e1986a0508dd10d0e8a4ab9a4cf94e85c","build.rs":"ed35d244304888581bfcbdc52596721a5bbb908bcbd56bbdfe977800ef3042e1","rustfmt.toml":"1ca600239a27401c4a43f363cf3f38183a212affc1f31bff3ae93234bbaec228","src/c.rs":"86fe35cbb46c8bece9927fbde20f1ca3af526defdde05ac969ad2f4bc9bb25e9","src/fallback.rs":"79519255d480a9c2667c06f9287931cfc2b85f6af6fcf92d453a11ee161dcb74","src/iter.rs":"23b1066d6b40159fe944388db7743c89422b1110ddb44667fde6d722f178ed4e","src/lib.rs":"8278d5f65db8081fa5ad3a0d17dac54d30de3d7a01b0dc4479927156e40b225c","src/naive.rs":"c7453bc99cc4e58eb37cf5a50c88688833e50a270ee1849baefddb8acc0ccd94","src/tests/iter.rs":"8d5999a2a5b8a3228c76cd82cd3ee86dfa6f7b4022405b1f06eedf7d74e4c704","src/tests/memchr.rs":"f30074eeab99a16ce5ca8a30f1890f86c43c0422523a7195cbb3ca5f3e465b67","src/tests/miri.rs":"27859a7ac1d0a9305b2d114e6dd8876f3d5e47fc46a81be96239c793ac6edb1f","src/tests/mod.rs":"2ad0c82d33b32562087254522641ea7bfa2a283130152be5e927a33f1978ebc7","src/x86/avx.rs":"b19987410e49a079f33162424c42494626c91303c41824961e478be3b537c9c9","src/x86/mod.rs":"0b13becaabc150a0099f7528226c82e288136cc7ebcdb8e96cf5ee9aae0f05b6","src/x86/sse2.rs":"7c1b8248a8cd48396cb70a862d77f9a972f1e16324d65c260f39d13af73bf638","src/x86/sse42.rs":"f671ae9dd2b518a823e499a09ce32d4957bc5ae043db90d61c027e32f688f2b2"},"package":"3728d817d99e5ac407411fa471ff9800a778d88a24685968b36824eaf4bee400"}
1111
1212 [package]
1313 name = "memchr"
14 version = "2.3.2"
14 version = "2.3.3"
1515 authors = ["Andrew Gallant <jamslam@gmail.com>", "bluss"]
1616 exclude = ["/ci/*", "/.travis.yml", "/Makefile", "/appveyor.yml"]
1717 description = "Safe interface to memchr."
3535 #[cfg(feature = "std")]
3636 extern crate core;
3737
38 #[cfg(all(test, not(miri)))]
38 #[cfg(all(test, all(not(miri), feature = "std")))]
3939 #[macro_use]
4040 extern crate quickcheck;
4141
5050 mod fallback;
5151 mod iter;
5252 mod naive;
53 #[cfg(all(test, not(miri)))]
53 #[cfg(all(test, all(not(miri), feature = "std")))]
5454 mod tests;
55 #[cfg(all(test, miri))]
55 #[cfg(all(test, any(miri, not(feature = "std"))))]
5656 #[path = "tests/miri.rs"]
5757 mod tests;
5858 #[cfg(all(not(miri), target_arch = "x86_64", memchr_runtime_simd))]
0 {"files":{"Cargo.toml":"312e04a1cb878b492475ae6a2ebc260c43c5b8f804e58a129800c42ae847e6de","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"6485b8ed310d3f0340bf1ad1f47645069ce4069dcc6bb46c7d5c6faf41de1fdb","README.md":"44e4759870c5e7b1b68d3ded60f655cac360e7614ad09d646cc2db35c47a502f","RELEASES.md":"4a9adcea77bb5e196a0c72d382b1c13da2aa036372002d285e4b75ca67827f2b","build.rs":"aba9dbc29eff865d95ce39cfe7cb20fde6137c7b7fae441d1b52ebb5087e402f","src/lib.rs":"0a96e23cdfafa420b620d032f93c53114d9cb1fb927f7442f13bea306ad6c56d"},"package":"da4dc79f9e6c81bef96148c8f6b8e72ad4541caa4a24373e900a36da07de03a3"}
0 {"files":{"Cargo.toml":"15b5b2c51cedb62324d85209347b1f104bc32fa3bb8c16a4a642f2b27e93d077","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"6485b8ed310d3f0340bf1ad1f47645069ce4069dcc6bb46c7d5c6faf41de1fdb","README.md":"44e4759870c5e7b1b68d3ded60f655cac360e7614ad09d646cc2db35c47a502f","RELEASES.md":"41de3744864404bfbb946e93e425a0615ae87b674ad93d27b191223b75909753","build.rs":"aba9dbc29eff865d95ce39cfe7cb20fde6137c7b7fae441d1b52ebb5087e402f","src/lib.rs":"3d47aadd8b47165ebee680250bfa097cced6b813e4ca06cb1a0e14d28501a531"},"package":"5c000134b5dbf44adc5cb772486d335293351644b801551abe8f75c84cfa4aef"}
1111
1212 [package]
1313 name = "num-rational"
14 version = "0.2.3"
14 version = "0.2.4"
1515 authors = ["The Rust Project Developers"]
1616 build = "build.rs"
1717 exclude = ["/ci/*", "/.travis.yml", "/bors.toml"]
0 # Release 0.2.4 (2020-03-17)
1
2 - [Fixed `CheckedDiv` when both dividend and divisor are 0][74].
3 - [Fixed `CheckedDiv` with `min_value()` numerators][76].
4
5 [74]: https://github.com/rust-num/num-rational/pull/74
6 [76]: https://github.com/rust-num/num-rational/pull/76
7
08 # Release 0.2.3 (2020-01-09)
19
210 - [`Ratio` now performs earlier reductions to avoid overflow with `+-*/%` operators][42].
107107 /// Creates a new `Ratio`. Fails if `denom` is zero.
108108 #[inline]
109109 pub fn new(numer: T, denom: T) -> Ratio<T> {
110 if denom.is_zero() {
111 panic!("denominator == 0");
112 }
113110 let mut ret = Ratio::new_raw(numer, denom);
114111 ret.reduce();
115112 ret
135132
136133 /// Puts self into lowest terms, with denom > 0.
137134 fn reduce(&mut self) {
135 if self.denom.is_zero() {
136 panic!("denominator == 0");
137 }
138 if self.numer.is_zero() {
139 self.denom.set_one();
140 return;
141 }
142 if self.numer == self.denom {
143 self.set_one();
144 return;
145 }
138146 let g: T = self.numer.gcd(&self.denom);
139147
140148 // FIXME(#5992): assignment operator overloads
871879 {
872880 #[inline]
873881 fn checked_div(&self, rhs: &Ratio<T>) -> Option<Ratio<T>> {
874 let gcd_ac = self.numer.gcd(&rhs.numer);
875 let gcd_bd = self.denom.gcd(&rhs.denom);
876 let denom = otry!((self.denom.clone() / gcd_bd.clone())
877 .checked_mul(&(rhs.numer.clone() / gcd_ac.clone())));
882 if rhs.is_zero() {
883 return None;
884 }
885 let (numer, denom) = if self.denom == rhs.denom {
886 (self.numer.clone(), rhs.numer.clone())
887 } else if self.numer == rhs.numer {
888 (rhs.denom.clone(), self.denom.clone())
889 } else {
890 let gcd_ac = self.numer.gcd(&rhs.numer);
891 let gcd_bd = self.denom.gcd(&rhs.denom);
892 let denom = otry!((self.denom.clone() / gcd_bd.clone())
893 .checked_mul(&(rhs.numer.clone() / gcd_ac.clone())));
894 (
895 otry!((self.numer.clone() / gcd_ac).checked_mul(&(rhs.denom.clone() / gcd_bd))),
896 denom,
897 )
898 };
899 // Manual `reduce()`, avoiding sharp edges
878900 if denom.is_zero() {
879 return None;
880 }
881 Some(Ratio::new(
882 otry!((self.numer.clone() / gcd_ac).checked_mul(&(rhs.denom.clone() / gcd_bd))),
883 denom,
884 ))
901 None
902 } else if numer.is_zero() {
903 Some(Self::zero())
904 } else if numer == denom {
905 Some(Self::one())
906 } else {
907 let g = numer.gcd(&denom);
908 let numer = numer / g.clone();
909 let denom = denom / g;
910 let raw = if denom < T::zero() {
911 // We need to keep denom positive, but 2's-complement MIN may
912 // overflow negation -- instead we can check multiplying -1.
913 let n1 = T::zero() - T::one();
914 Ratio::new_raw(otry!(numer.checked_mul(&n1)), otry!(denom.checked_mul(&n1)))
915 } else {
916 Ratio::new_raw(numer, denom)
917 };
918 Some(raw)
919 }
885920 }
886921 }
887922
10851120 fn from_str(s: &str) -> Result<Ratio<T>, ParseRatioError> {
10861121 let mut split = s.splitn(2, '/');
10871122
1088 let n = try!(split.next().ok_or(ParseRatioError {
1089 kind: RatioErrorKind::ParseError
1090 }));
1091 let num = try!(FromStr::from_str(n).map_err(|_| ParseRatioError {
1092 kind: RatioErrorKind::ParseError
1093 }));
1123 let n = split.next().ok_or(ParseRatioError {
1124 kind: RatioErrorKind::ParseError,
1125 })?;
1126 let num = FromStr::from_str(n).map_err(|_| ParseRatioError {
1127 kind: RatioErrorKind::ParseError,
1128 })?;
10941129
10951130 let d = split.next().unwrap_or("1");
1096 let den = try!(FromStr::from_str(d).map_err(|_| ParseRatioError {
1097 kind: RatioErrorKind::ParseError
1098 }));
1131 let den = FromStr::from_str(d).map_err(|_| ParseRatioError {
1132 kind: RatioErrorKind::ParseError,
1133 })?;
10991134
11001135 if Zero::is_zero(&den) {
11011136 Err(ParseRatioError {
14021437
14031438 use core::f64;
14041439 use core::i32;
1440 use core::isize;
14051441 use core::str::FromStr;
14061442 use integer::Integer;
14071443 use traits::{FromPrimitive, One, Pow, Signed, Zero};
14381474 numer: -2,
14391475 denom: 3,
14401476 };
1477 pub const _MIN: Rational = Ratio {
1478 numer: isize::MIN,
1479 denom: 1,
1480 };
1481 pub const _MIN_P1: Rational = Ratio {
1482 numer: isize::MIN + 1,
1483 denom: 1,
1484 };
1485 pub const _MAX: Rational = Ratio {
1486 numer: isize::MAX,
1487 denom: 1,
1488 };
1489 pub const _MAX_M1: Rational = Ratio {
1490 numer: isize::MAX - 1,
1491 denom: 1,
1492 };
14411493
14421494 #[cfg(feature = "bigint")]
14431495 pub fn to_big(n: Rational) -> BigRational {
14681520
14691521 #[test]
14701522 fn test_new_reduce() {
1471 let one22 = Ratio::new(2, 2);
1472
1473 assert_eq!(one22, One::one());
1523 assert_eq!(Ratio::new(2, 2), One::one());
1524 assert_eq!(Ratio::new(0, i32::MIN), Zero::zero());
1525 assert_eq!(Ratio::new(i32::MIN, i32::MIN), One::one());
14741526 }
14751527 #[test]
14761528 #[should_panic]
16271679
16281680 mod arith {
16291681 use super::super::{Ratio, Rational};
1630 use super::{to_big, _0, _1, _1_2, _2, _3_2, _5_2, _NEG1_2};
1682 use super::{to_big, _0, _1, _1_2, _2, _3_2, _5_2, _MAX, _MAX_M1, _MIN, _MIN_P1, _NEG1_2};
16311683 use core::fmt::Debug;
16321684 use integer::Integer;
16331685 use traits::{Bounded, CheckedAdd, CheckedDiv, CheckedMul, CheckedSub, NumAssign};
20602112 assert_eq!(small.checked_div(&big), None);
20612113 assert_eq!(_1.checked_div(&_0), None);
20622114 }
2115
2116 #[test]
2117 fn test_checked_zeros() {
2118 assert_eq!(_0.checked_add(&_0), Some(_0));
2119 assert_eq!(_0.checked_sub(&_0), Some(_0));
2120 assert_eq!(_0.checked_mul(&_0), Some(_0));
2121 assert_eq!(_0.checked_div(&_0), None);
2122 }
2123
2124 #[test]
2125 fn test_checked_min() {
2126 assert_eq!(_MIN.checked_add(&_MIN), None);
2127 assert_eq!(_MIN.checked_sub(&_MIN), Some(_0));
2128 assert_eq!(_MIN.checked_mul(&_MIN), None);
2129 assert_eq!(_MIN.checked_div(&_MIN), Some(_1));
2130 assert_eq!(_0.checked_add(&_MIN), Some(_MIN));
2131 assert_eq!(_0.checked_sub(&_MIN), None);
2132 assert_eq!(_0.checked_mul(&_MIN), Some(_0));
2133 assert_eq!(_0.checked_div(&_MIN), Some(_0));
2134 assert_eq!(_1.checked_add(&_MIN), Some(_MIN_P1));
2135 assert_eq!(_1.checked_sub(&_MIN), None);
2136 assert_eq!(_1.checked_mul(&_MIN), Some(_MIN));
2137 assert_eq!(_1.checked_div(&_MIN), None);
2138 assert_eq!(_MIN.checked_add(&_0), Some(_MIN));
2139 assert_eq!(_MIN.checked_sub(&_0), Some(_MIN));
2140 assert_eq!(_MIN.checked_mul(&_0), Some(_0));
2141 assert_eq!(_MIN.checked_div(&_0), None);
2142 assert_eq!(_MIN.checked_add(&_1), Some(_MIN_P1));
2143 assert_eq!(_MIN.checked_sub(&_1), None);
2144 assert_eq!(_MIN.checked_mul(&_1), Some(_MIN));
2145 assert_eq!(_MIN.checked_div(&_1), Some(_MIN));
2146 }
2147
2148 #[test]
2149 fn test_checked_max() {
2150 assert_eq!(_MAX.checked_add(&_MAX), None);
2151 assert_eq!(_MAX.checked_sub(&_MAX), Some(_0));
2152 assert_eq!(_MAX.checked_mul(&_MAX), None);
2153 assert_eq!(_MAX.checked_div(&_MAX), Some(_1));
2154 assert_eq!(_0.checked_add(&_MAX), Some(_MAX));
2155 assert_eq!(_0.checked_sub(&_MAX), Some(_MIN_P1));
2156 assert_eq!(_0.checked_mul(&_MAX), Some(_0));
2157 assert_eq!(_0.checked_div(&_MAX), Some(_0));
2158 assert_eq!(_1.checked_add(&_MAX), None);
2159 assert_eq!(_1.checked_sub(&_MAX), Some(-_MAX_M1));
2160 assert_eq!(_1.checked_mul(&_MAX), Some(_MAX));
2161 assert_eq!(_1.checked_div(&_MAX), Some(_MAX.recip()));
2162 assert_eq!(_MAX.checked_add(&_0), Some(_MAX));
2163 assert_eq!(_MAX.checked_sub(&_0), Some(_MAX));
2164 assert_eq!(_MAX.checked_mul(&_0), Some(_0));
2165 assert_eq!(_MAX.checked_div(&_0), None);
2166 assert_eq!(_MAX.checked_add(&_1), None);
2167 assert_eq!(_MAX.checked_sub(&_1), Some(_MAX_M1));
2168 assert_eq!(_MAX.checked_mul(&_1), Some(_MAX));
2169 assert_eq!(_MAX.checked_div(&_1), Some(_MAX));
2170 }
2171
2172 #[test]
2173 fn test_checked_min_max() {
2174 assert_eq!(_MIN.checked_add(&_MAX), Some(-_1));
2175 assert_eq!(_MIN.checked_sub(&_MAX), None);
2176 assert_eq!(_MIN.checked_mul(&_MAX), None);
2177 assert_eq!(
2178 _MIN.checked_div(&_MAX),
2179 Some(Ratio::new(_MIN.numer, _MAX.numer))
2180 );
2181 assert_eq!(_MAX.checked_add(&_MIN), Some(-_1));
2182 assert_eq!(_MAX.checked_sub(&_MIN), None);
2183 assert_eq!(_MAX.checked_mul(&_MIN), None);
2184 assert_eq!(_MAX.checked_div(&_MIN), None);
2185 }
20632186 }
20642187
20652188 #[test]
+0
-1
rust/vendor/redox_syscall/.cargo-checksum.json less more
0 {"files":{"Cargo.toml":"6a30685e5679812735444beae8fbf0637c43cf65d8d7e74a9a44b7172899edd9","LICENSE":"efcfee7981ff72431fffb06925cad00a23dce079ed4354f61030ad5abdb78829","README.md":"9161f18ba7f69b4ca51e844aee8ffb8237513a468c5c3b1f3a5f989044f895ac","src/arch/aarch64.rs":"3c36537214f8e10331d42ce4c7ac57a472db49fed029193c31982279d08bdad5","src/arch/arm.rs":"44ed9097879fce0ebe85d29e25ba378fb3ee7fcd649b569207495ed601c42a1c","src/arch/nonredox.rs":"de54557f642218b34d451fc52fe3cff97e3e4307304ae02a678a900cab96cdb0","src/arch/x86.rs":"e72a7f653c25b1ea5595af7ce991fe0e5c96547e127fc67e4967d60abbe1d3bd","src/arch/x86_64.rs":"4b809fde77985b335b2f53057d0f13debeb3edae2bc3b18bcc7eb0af4b6d8aef","src/call.rs":"b5b53aab18bb91bfef88d82f1708d05e210a30cde141fce0031dad543d988391","src/data.rs":"84f8beb9d40b753a8c1713b922e99ed9913d35e959694b2c849351b1a92d87c9","src/error.rs":"d832a641ccb1baf10315e2e1ce59b12c30d605a526fc65a31f63bb3a92c3a2f7","src/flag.rs":"1e944be3b134d3776725529e2190e2d1548dd67a631838281b8c5bc829523dbe","src/io/dma.rs":"740cd441f844718a14f77c2fe292d29b7c468d686505810d8b3281f9528a6fe7","src/io/io.rs":"1bcb36d1867e9bab6a8186cd6928efe70ae2655e9f9d0dd3def20bc0fb6a82f6","src/io/mmio.rs":"b9fdb37d37a25a48106d60f1a977c541cb5162b20b12507c7dcd6eb3dff0a2c8","src/io/mod.rs":"4df12af3e82e6b5fe22112c9f51552112ee4811b7d1131d2a43d608d8d1cac09","src/io/pio.rs":"219fcd317d6c490a14794ec4db9de3e305c722dda720043c67076bda60632bb8","src/lib.rs":"907de02434902d35346f7e3b03be652a62e9def472cd1845eeca3da7a0c6bbea","src/number.rs":"4718baa58a0f3e6b9b66d1f328cb2a145e9b1f807654c3079a13b226c4085a29","src/scheme/generate.sh":"b022adacb74f2af1470e691341c37acc1582f428e9b8b6b9dccb790dde594b40","src/scheme/mod.rs":"2679272397bf0247e1a4695853465243ca02960feb4ced1124969f67ebd3e3ce","src/scheme/scheme.rs":"879728e4d4e7d8f3057df5a3a6af1636079135652594ee50ca1b665e876be595","src/scheme/scheme_block.rs":"a8ea17b1101548e9b36f6c9000f68fd5438a796069252f948bde7dda44088a7f","src/scheme/scheme_block_mut.rs":"8b881f84a54e2477967d43eb68dac7c578ff6451dba59eba0d517037b2ac4def","src/scheme/scheme_mut.rs":"30f9b0750437b7f55d5bb24da546fd4afcb3c27b0af06d5f681b8f1c4877e7b4","src/tests.rs":"b9d60e419f7e57bb942756e8011e19704cfd46fb6ec96ffa925fb7deb35c5d43"},"package":"2439c63f3f6139d1b57529d16bc3b8bb855230c8efcc5d3a896c8bea7c3b1e84"}
+0
-23
rust/vendor/redox_syscall/Cargo.toml less more
0 # THIS FILE IS AUTOMATICALLY GENERATED BY CARGO
1 #
2 # When uploading crates to the registry Cargo will automatically
3 # "normalize" Cargo.toml files for maximal compatibility
4 # with all versions of Cargo and also rewrite `path` dependencies
5 # to registry (e.g., crates.io) dependencies
6 #
7 # If you believe there's an error in this file please file an
8 # issue against the rust-lang/cargo repository. If you're
9 # editing this file be aware that the upstream Cargo.toml
10 # will likely look very different (and much more reasonable)
11
12 [package]
13 name = "redox_syscall"
14 version = "0.1.56"
15 authors = ["Jeremy Soller <jackpot51@gmail.com>"]
16 description = "A Rust library to access raw Redox system calls"
17 documentation = "https://docs.rs/redox_syscall"
18 license = "MIT"
19 repository = "https://gitlab.redox-os.org/redox-os/syscall"
20
21 [lib]
22 name = "syscall"
+0
-22
rust/vendor/redox_syscall/LICENSE less more
0 Copyright (c) 2017 Redox OS Developers
1
2 MIT License
3
4 Permission is hereby granted, free of charge, to any person obtaining
5 a copy of this software and associated documentation files (the
6 "Software"), to deal in the Software without restriction, including
7 without limitation the rights to use, copy, modify, merge, publish,
8 distribute, sublicense, and/or sell copies of the Software, and to
9 permit persons to whom the Software is furnished to do so, subject to
10 the following conditions:
11
12 The above copyright notice and this permission notice shall be
13 included in all copies or substantial portions of the Software.
14
15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+0
-6
rust/vendor/redox_syscall/README.md less more
0 # syscall
1 [Redox OS](https://gitlab.redox-os.org/redox-os/redox)'s syscall API
2
3 [![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](./LICENSE)
4 [![crates.io](http://meritbadge.herokuapp.com/redox_syscall)](https://crates.io/crates/redox_syscall)
5 [![docs.rs](https://docs.rs/redox_syscall/badge.svg)](https://docs.rs/redox_syscall)
+0
-77
rust/vendor/redox_syscall/src/arch/aarch64.rs less more
0 use super::error::{Error, Result};
1
2 pub unsafe fn syscall0(mut a: usize) -> Result<usize> {
3 asm!("svc 0"
4 : "={x0}"(a)
5 : "{x8}"(a)
6 : "x0", "x8"
7 : "volatile");
8
9 Error::demux(a)
10 }
11
12 pub unsafe fn syscall1(mut a: usize, b: usize) -> Result<usize> {
13 asm!("svc 0"
14 : "={x0}"(a)
15 : "{x8}"(a), "{x0}"(b)
16 : "x0", "x8"
17 : "volatile");
18
19 Error::demux(a)
20 }
21
22 // Clobbers all registers - special for clone
23 pub unsafe fn syscall1_clobber(mut a: usize, b: usize) -> Result<usize> {
24 asm!("svc 0"
25 : "={x0}"(a)
26 : "{x8}"(a), "{x0}"(b)
27 : "memory",
28 "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7",
29 "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15",
30 "x16", "x17","x18", "x19", "x20", "x21", "x22", "x23",
31 "x24", "x25", "x26", "x27", "x28", "x29", "x30"
32 : "volatile");
33
34 Error::demux(a)
35 }
36
37 pub unsafe fn syscall2(mut a: usize, b: usize, c: usize) -> Result<usize> {
38 asm!("svc 0"
39 : "={x0}"(a)
40 : "{x8}"(a), "{x0}"(b), "{x1}"(c)
41 : "x0", "x1", "x8"
42 : "volatile");
43
44 Error::demux(a)
45 }
46
47 pub unsafe fn syscall3(mut a: usize, b: usize, c: usize, d: usize) -> Result<usize> {
48 asm!("svc 0"
49 : "={x0}"(a)
50 : "{x8}"(a), "{x0}"(b), "{x1}"(c), "{x2}"(d)
51 : "x0", "x1", "x2", "x8"
52 : "volatile");
53
54 Error::demux(a)
55 }
56
57 pub unsafe fn syscall4(mut a: usize, b: usize, c: usize, d: usize, e: usize) -> Result<usize> {
58 asm!("svc 0"
59 : "={x0}"(a)
60 : "{x8}"(a), "{x0}"(b), "{x1}"(c), "{x2}"(d), "{x3}"(e)
61 : "x0", "x1", "x2", "x3", "x8"
62 : "volatile");
63
64 Error::demux(a)
65 }
66
67 pub unsafe fn syscall5(mut a: usize, b: usize, c: usize, d: usize, e: usize, f: usize)
68 -> Result<usize> {
69 asm!("svc 0"
70 : "={x0}"(a)
71 : "{x8}"(a), "{x0}"(b), "{x1}"(c), "{x2}"(d), "{x3}"(e), "{x4}"(f)
72 : "x0", "x1", "x2", "x3", "x4", "x8"
73 : "volatile");
74
75 Error::demux(a)
76 }
+0
-73
rust/vendor/redox_syscall/src/arch/arm.rs less more
0 use super::error::{Error, Result};
1
2 pub unsafe fn syscall0(mut a: usize) -> Result<usize> {
3 asm!("swi $$0"
4 : "={r0}"(a)
5 : "{r7}"(a)
6 : "memory"
7 : "volatile");
8
9 Error::demux(a)
10 }
11
12 pub unsafe fn syscall1(mut a: usize, b: usize) -> Result<usize> {
13 asm!("swi $$0"
14 : "={r0}"(a)
15 : "{r7}"(a), "{r0}"(b)
16 : "memory"
17 : "volatile");
18
19 Error::demux(a)
20 }
21
22 // Clobbers all registers - special for clone
23 pub unsafe fn syscall1_clobber(mut a: usize, b: usize) -> Result<usize> {
24 asm!("swi $$0"
25 : "={r0}"(a)
26 : "{r7}"(a), "{r0}"(b)
27 : "memory", "r0", "r1", "r2", "r3", "r4"
28 : "volatile");
29
30 Error::demux(a)
31 }
32
33 pub unsafe fn syscall2(mut a: usize, b: usize, c: usize) -> Result<usize> {
34 asm!("swi $$0"
35 : "={r0}"(a)
36 : "{r7}"(a), "{r0}"(b), "{r1}"(c)
37 : "memory"
38 : "volatile");
39
40 Error::demux(a)
41 }
42
43 pub unsafe fn syscall3(mut a: usize, b: usize, c: usize, d: usize) -> Result<usize> {
44 asm!("swi $$0"
45 : "={r0}"(a)
46 : "{r7}"(a), "{r0}"(b), "{r1}"(c), "{r2}"(d)
47 : "memory"
48 : "volatile");
49
50 Error::demux(a)
51 }
52
53 pub unsafe fn syscall4(mut a: usize, b: usize, c: usize, d: usize, e: usize) -> Result<usize> {
54 asm!("swi $$0"
55 : "={r0}"(a)
56 : "{r7}"(a), "{r0}"(b), "{r1}"(c), "{r2}"(d), "{r3}"(e)
57 : "memory"
58 : "volatile");
59
60 Error::demux(a)
61 }
62
63 pub unsafe fn syscall5(mut a: usize, b: usize, c: usize, d: usize, e: usize, f: usize)
64 -> Result<usize> {
65 asm!("swi $$0"
66 : "={r0}"(a)
67 : "{r7}"(a), "{r0}"(b), "{r1}"(c), "{r2}"(d), "{r3}"(e), "{r4}"(f)
68 : "memory"
69 : "volatile");
70
71 Error::demux(a)
72 }
+0
-31
rust/vendor/redox_syscall/src/arch/nonredox.rs less more
0 use super::error::{Error, Result, ENOSYS};
1
2 pub unsafe fn syscall0(_a: usize) -> Result<usize> {
3 Err(Error::new(ENOSYS))
4 }
5
6 pub unsafe fn syscall1(_a: usize, _b: usize) -> Result<usize> {
7 Err(Error::new(ENOSYS))
8 }
9
10 // Clobbers all registers - special for clone
11 pub unsafe fn syscall1_clobber(_a: usize, _b: usize) -> Result<usize> {
12 Err(Error::new(ENOSYS))
13 }
14
15 pub unsafe fn syscall2(_a: usize, _b: usize, _c: usize) -> Result<usize> {
16 Err(Error::new(ENOSYS))
17 }
18
19 pub unsafe fn syscall3(_a: usize, _b: usize, _c: usize, _d: usize) -> Result<usize> {
20 Err(Error::new(ENOSYS))
21 }
22
23 pub unsafe fn syscall4(_a: usize, _b: usize, _c: usize, _d: usize, _e: usize) -> Result<usize> {
24 Err(Error::new(ENOSYS))
25 }
26
27 pub unsafe fn syscall5(_a: usize, _b: usize, _c: usize, _d: usize, _e: usize, _f: usize)
28 -> Result<usize> {
29 Err(Error::new(ENOSYS))
30 }
+0
-73
rust/vendor/redox_syscall/src/arch/x86.rs less more
0 use super::error::{Error, Result};
1
2 pub unsafe fn syscall0(mut a: usize) -> Result<usize> {
3 asm!("int 0x80"
4 : "={eax}"(a)
5 : "{eax}"(a)
6 : "memory"
7 : "intel", "volatile");
8
9 Error::demux(a)
10 }
11
12 pub unsafe fn syscall1(mut a: usize, b: usize) -> Result<usize> {
13 asm!("int 0x80"
14 : "={eax}"(a)
15 : "{eax}"(a), "{ebx}"(b)
16 : "memory"
17 : "intel", "volatile");
18
19 Error::demux(a)
20 }
21
22 // Clobbers all registers - special for clone
23 pub unsafe fn syscall1_clobber(mut a: usize, b: usize) -> Result<usize> {
24 asm!("int 0x80"
25 : "={eax}"(a)
26 : "{eax}"(a), "{ebx}"(b)
27 : "memory", "ebx", "ecx", "edx", "esi", "edi"
28 : "intel", "volatile");
29
30 Error::demux(a)
31 }
32
33 pub unsafe fn syscall2(mut a: usize, b: usize, c: usize) -> Result<usize> {
34 asm!("int 0x80"
35 : "={eax}"(a)
36 : "{eax}"(a), "{ebx}"(b), "{ecx}"(c)
37 : "memory"
38 : "intel", "volatile");
39
40 Error::demux(a)
41 }
42
43 pub unsafe fn syscall3(mut a: usize, b: usize, c: usize, d: usize) -> Result<usize> {
44 asm!("int 0x80"
45 : "={eax}"(a)
46 : "{eax}"(a), "{ebx}"(b), "{ecx}"(c), "{edx}"(d)
47 : "memory"
48 : "intel", "volatile");
49
50 Error::demux(a)
51 }
52
53 pub unsafe fn syscall4(mut a: usize, b: usize, c: usize, d: usize, e: usize) -> Result<usize> {
54 asm!("int 0x80"
55 : "={eax}"(a)
56 : "{eax}"(a), "{ebx}"(b), "{ecx}"(c), "{edx}"(d), "{esi}"(e)
57 : "memory"
58 : "intel", "volatile");
59
60 Error::demux(a)
61 }
62
63 pub unsafe fn syscall5(mut a: usize, b: usize, c: usize, d: usize, e: usize, f: usize)
64 -> Result<usize> {
65 asm!("int 0x80"
66 : "={eax}"(a)
67 : "{eax}"(a), "{ebx}"(b), "{ecx}"(c), "{edx}"(d), "{esi}"(e), "{edi}"(f)
68 : "memory"
69 : "intel", "volatile");
70
71 Error::demux(a)
72 }
+0
-74
rust/vendor/redox_syscall/src/arch/x86_64.rs less more
0 use super::error::{Error, Result};
1
2 pub unsafe fn syscall0(mut a: usize) -> Result<usize> {
3 asm!("syscall"
4 : "={rax}"(a)
5 : "{rax}"(a)
6 : "rcx", "r11", "memory"
7 : "intel", "volatile");
8
9 Error::demux(a)
10 }
11
12 pub unsafe fn syscall1(mut a: usize, b: usize) -> Result<usize> {
13 asm!("syscall"
14 : "={rax}"(a)
15 : "{rax}"(a), "{rdi}"(b)
16 : "rcx", "r11", "memory"
17 : "intel", "volatile");
18
19 Error::demux(a)
20 }
21
22 // Clobbers all registers - special for clone
23 pub unsafe fn syscall1_clobber(mut a: usize, b: usize) -> Result<usize> {
24 asm!("syscall"
25 : "={rax}"(a)
26 : "{rax}"(a), "{rdi}"(b)
27 : "memory", "rbx", "rcx", "rdx", "rsi", "rdi", "r8",
28 "r9", "r10", "r11", "r12", "r13", "r14", "r15"
29 : "intel", "volatile");
30
31 Error::demux(a)
32 }
33
34 pub unsafe fn syscall2(mut a: usize, b: usize, c: usize) -> Result<usize> {
35 asm!("syscall"
36 : "={rax}"(a)
37 : "{rax}"(a), "{rdi}"(b), "{rsi}"(c)
38 : "rcx", "r11", "memory"
39 : "intel", "volatile");
40
41 Error::demux(a)
42 }
43
44 pub unsafe fn syscall3(mut a: usize, b: usize, c: usize, d: usize) -> Result<usize> {
45 asm!("syscall"
46 : "={rax}"(a)
47 : "{rax}"(a), "{rdi}"(b), "{rsi}"(c), "{rdx}"(d)
48 : "rcx", "r11", "memory"
49 : "intel", "volatile");
50
51 Error::demux(a)
52 }
53
54 pub unsafe fn syscall4(mut a: usize, b: usize, c: usize, d: usize, e: usize) -> Result<usize> {
55 asm!("syscall"
56 : "={rax}"(a)
57 : "{rax}"(a), "{rdi}"(b), "{rsi}"(c), "{rdx}"(d), "{r10}"(e)
58 : "rcx", "r11", "memory"
59 : "intel", "volatile");
60
61 Error::demux(a)
62 }
63
64 pub unsafe fn syscall5(mut a: usize, b: usize, c: usize, d: usize, e: usize, f: usize)
65 -> Result<usize> {
66 asm!("syscall"
67 : "={rax}"(a)
68 : "{rax}"(a), "{rdi}"(b), "{rsi}"(c), "{rdx}"(d), "{r10}"(e), "{r8}"(f)
69 : "rcx", "r11", "memory"
70 : "intel", "volatile");
71
72 Error::demux(a)
73 }
+0
-393
rust/vendor/redox_syscall/src/call.rs less more
0 use super::arch::*;
1 use super::data::{Map, SigAction, Stat, StatVfs, TimeSpec};
2 use super::error::Result;
3 use super::number::*;
4
5 use core::{mem, ptr};
6
7 // Signal restorer
8 extern "C" fn restorer() -> ! {
9 sigreturn().unwrap();
10 unreachable!();
11 }
12
13 /// Set the end of the process's heap
14 ///
15 /// When `addr` is `0`, this function will return the current break.
16 ///
17 /// When `addr` is nonzero, this function will attempt to set the end of the process's
18 /// heap to `addr` and return the new program break. The new program break should be
19 /// checked by the allocator, it may not be exactly `addr`, as it may be aligned to a page
20 /// boundary.
21 ///
22 /// On error, `Err(ENOMEM)` will be returned indicating that no memory is available
23 pub unsafe fn brk(addr: usize) -> Result<usize> {
24 syscall1(SYS_BRK, addr)
25 }
26
27 /// Change the process's working directory
28 ///
29 /// This function will attempt to set the process's working directory to `path`, which can be
30 /// either a relative, scheme relative, or absolute path.
31 ///
32 /// On success, `Ok(0)` will be returned. On error, one of the following errors will be returned.
33 ///
34 /// # Errors
35 ///
36 /// * `EACCES` - permission is denied for one of the components of `path`, or `path`
37 /// * `EFAULT` - `path` does not point to the process's addressible memory
38 /// * `EIO` - an I/O error occurred
39 /// * `ENOENT` - `path` does not exit
40 /// * `ENOTDIR` - `path` is not a directory
41 pub fn chdir<T: AsRef<[u8]>>(path: T) -> Result<usize> {
42 unsafe { syscall2(SYS_CHDIR, path.as_ref().as_ptr() as usize, path.as_ref().len()) }
43 }
44
45 #[deprecated(
46 since = "0.1.55",
47 note = "use fchmod instead"
48 )]
49 pub fn chmod<T: AsRef<[u8]>>(path: T, mode: usize) -> Result<usize> {
50 unsafe { syscall3(SYS_CHMOD, path.as_ref().as_ptr() as usize, path.as_ref().len(), mode) }
51 }
52
53 /// Produce a fork of the current process, or a new process thread
54 pub unsafe fn clone(flags: usize) -> Result<usize> {
55 syscall1_clobber(SYS_CLONE, flags)
56 }
57
58 /// Close a file
59 pub fn close(fd: usize) -> Result<usize> {
60 unsafe { syscall1(SYS_CLOSE, fd) }
61 }
62
63 /// Get the current system time
64 pub fn clock_gettime(clock: usize, tp: &mut TimeSpec) -> Result<usize> {
65 unsafe { syscall2(SYS_CLOCK_GETTIME, clock, tp as *mut TimeSpec as usize) }
66 }
67
68 /// Copy and transform a file descriptor
69 pub fn dup(fd: usize, buf: &[u8]) -> Result<usize> {
70 unsafe { syscall3(SYS_DUP, fd, buf.as_ptr() as usize, buf.len()) }
71 }
72
73 /// Copy and transform a file descriptor
74 pub fn dup2(fd: usize, newfd: usize, buf: &[u8]) -> Result<usize> {
75 unsafe { syscall4(SYS_DUP2, fd, newfd, buf.as_ptr() as usize, buf.len()) }
76 }
77
78 /// Exit the current process
79 pub fn exit(status: usize) -> Result<usize> {
80 unsafe { syscall1(SYS_EXIT, status) }
81 }
82
83 /// Change file permissions
84 pub fn fchmod(fd: usize, mode: u16) -> Result<usize> {
85 unsafe { syscall2(SYS_FCHMOD, fd, mode as usize) }
86
87 }
88
89 /// Change file ownership
90 pub fn fchown(fd: usize, uid: u32, gid: u32) -> Result<usize> {
91 unsafe { syscall3(SYS_FCHOWN, fd, uid as usize, gid as usize) }
92
93 }
94
95 /// Change file descriptor flags
96 pub fn fcntl(fd: usize, cmd: usize, arg: usize) -> Result<usize> {
97 unsafe { syscall3(SYS_FCNTL, fd, cmd, arg) }
98 }
99
100 /// Replace the current process with a new executable
101 pub fn fexec(fd: usize, args: &[[usize; 2]], vars: &[[usize; 2]]) -> Result<usize> {
102 unsafe { syscall5(SYS_FEXEC, fd, args.as_ptr() as usize, args.len(), vars.as_ptr() as usize, vars.len()) }
103 }
104
105 /// Map a file into memory
106 pub unsafe fn fmap(fd: usize, map: &Map) -> Result<usize> {
107 syscall3(SYS_FMAP, fd, map as *const Map as usize, mem::size_of::<Map>())
108 }
109
110 /// Unmap a memory-mapped file
111 pub unsafe fn funmap(addr: usize) -> Result<usize> {
112 syscall1(SYS_FUNMAP, addr)
113 }
114
115 /// Retrieve the canonical path of a file
116 pub fn fpath(fd: usize, buf: &mut [u8]) -> Result<usize> {
117 unsafe { syscall3(SYS_FPATH, fd, buf.as_mut_ptr() as usize, buf.len()) }
118 }
119
120 /// Rename a file
121 pub fn frename<T: AsRef<[u8]>>(fd: usize, path: T) -> Result<usize> {
122 unsafe { syscall3(SYS_FRENAME, fd, path.as_ref().as_ptr() as usize, path.as_ref().len()) }
123 }
124
125 /// Get metadata about a file
126 pub fn fstat(fd: usize, stat: &mut Stat) -> Result<usize> {
127 unsafe { syscall3(SYS_FSTAT, fd, stat as *mut Stat as usize, mem::size_of::<Stat>()) }
128 }
129
130 /// Get metadata about a filesystem
131 pub fn fstatvfs(fd: usize, stat: &mut StatVfs) -> Result<usize> {
132 unsafe { syscall3(SYS_FSTATVFS, fd, stat as *mut StatVfs as usize, mem::size_of::<StatVfs>()) }
133 }
134
135 /// Sync a file descriptor to its underlying medium
136 pub fn fsync(fd: usize) -> Result<usize> {
137 unsafe { syscall1(SYS_FSYNC, fd) }
138 }
139
140 /// Truncate or extend a file to a specified length
141 pub fn ftruncate(fd: usize, len: usize) -> Result<usize> {
142 unsafe { syscall2(SYS_FTRUNCATE, fd, len) }
143 }
144
145 // Change modify and/or access times
146 pub fn futimens(fd: usize, times: &[TimeSpec]) -> Result<usize> {
147 unsafe { syscall3(SYS_FUTIMENS, fd, times.as_ptr() as usize, times.len() * mem::size_of::<TimeSpec>()) }
148 }
149
150 /// Fast userspace mutex
151 pub unsafe fn futex(addr: *mut i32, op: usize, val: i32, val2: usize, addr2: *mut i32)
152 -> Result<usize> {
153 syscall5(SYS_FUTEX, addr as usize, op, (val as isize) as usize, val2, addr2 as usize)
154 }
155
156 /// Get the current working directory
157 pub fn getcwd(buf: &mut [u8]) -> Result<usize> {
158 unsafe { syscall2(SYS_GETCWD, buf.as_mut_ptr() as usize, buf.len()) }
159 }
160
161 /// Get the effective group ID
162 pub fn getegid() -> Result<usize> {
163 unsafe { syscall0(SYS_GETEGID) }
164 }
165
166 /// Get the effective namespace
167 pub fn getens() -> Result<usize> {
168 unsafe { syscall0(SYS_GETENS) }
169 }
170
171 /// Get the effective user ID
172 pub fn geteuid() -> Result<usize> {
173 unsafe { syscall0(SYS_GETEUID) }
174 }
175
176 /// Get the current group ID
177 pub fn getgid() -> Result<usize> {
178 unsafe { syscall0(SYS_GETGID) }
179 }
180
181 /// Get the current namespace
182 pub fn getns() -> Result<usize> {
183 unsafe { syscall0(SYS_GETNS) }
184 }
185
186 /// Get the current process ID
187 pub fn getpid() -> Result<usize> {
188 unsafe { syscall0(SYS_GETPID) }
189 }
190
191 /// Get the process group ID
192 pub fn getpgid(pid: usize) -> Result<usize> {
193 unsafe { syscall1(SYS_GETPGID, pid) }
194 }
195
196 /// Get the parent process ID
197 pub fn getppid() -> Result<usize> {
198 unsafe { syscall0(SYS_GETPPID) }
199 }
200
201 /// Get the current user ID
202 pub fn getuid() -> Result<usize> {
203 unsafe { syscall0(SYS_GETUID) }
204 }
205
206 /// Set the I/O privilege level
207 ///
208 /// # Errors
209 ///
210 /// * `EPERM` - `uid != 0`
211 /// * `EINVAL` - `level > 3`
212 pub unsafe fn iopl(level: usize) -> Result<usize> {
213 syscall1(SYS_IOPL, level)
214 }
215
216 /// Send a signal `sig` to the process identified by `pid`
217 pub fn kill(pid: usize, sig: usize) -> Result<usize> {
218 unsafe { syscall2(SYS_KILL, pid, sig) }
219 }
220
221 /// Create a link to a file
222 pub unsafe fn link(old: *const u8, new: *const u8) -> Result<usize> {
223 syscall2(SYS_LINK, old as usize, new as usize)
224 }
225
226 /// Seek to `offset` bytes in a file descriptor
227 pub fn lseek(fd: usize, offset: isize, whence: usize) -> Result<usize> {
228 unsafe { syscall3(SYS_LSEEK, fd, offset as usize, whence) }
229 }
230
231 /// Make a new scheme namespace
232 pub fn mkns(schemes: &[[usize; 2]]) -> Result<usize> {
233 unsafe { syscall2(SYS_MKNS, schemes.as_ptr() as usize, schemes.len()) }
234 }
235
236 /// Change mapping flags
237 pub unsafe fn mprotect(addr: usize, size: usize, flags: usize) -> Result<usize> {
238 syscall3(SYS_MPROTECT, addr, size, flags)
239 }
240
241 /// Sleep for the time specified in `req`
242 pub fn nanosleep(req: &TimeSpec, rem: &mut TimeSpec) -> Result<usize> {
243 unsafe { syscall2(SYS_NANOSLEEP, req as *const TimeSpec as usize,
244 rem as *mut TimeSpec as usize) }
245 }
246
247 /// Open a file
248 pub fn open<T: AsRef<[u8]>>(path: T, flags: usize) -> Result<usize> {
249 unsafe { syscall3(SYS_OPEN, path.as_ref().as_ptr() as usize, path.as_ref().len(), flags) }
250 }
251
252 /// Allocate pages, linearly in physical memory
253 ///
254 /// # Errors
255 ///
256 /// * `EPERM` - `uid != 0`
257 /// * `ENOMEM` - the system has run out of available memory
258 pub unsafe fn physalloc(size: usize) -> Result<usize> {
259 syscall1(SYS_PHYSALLOC, size)
260 }
261
262 /// Free physically allocated pages
263 ///
264 /// # Errors
265 ///
266 /// * `EPERM` - `uid != 0`
267 pub unsafe fn physfree(physical_address: usize, size: usize) -> Result<usize> {
268 syscall2(SYS_PHYSFREE, physical_address, size)
269 }
270
271 /// Map physical memory to virtual memory
272 ///
273 /// # Errors
274 ///
275 /// * `EPERM` - `uid != 0`
276 pub unsafe fn physmap(physical_address: usize, size: usize, flags: usize) -> Result<usize> {
277 syscall3(SYS_PHYSMAP, physical_address, size, flags)
278 }
279
280 /// Unmap previously mapped physical memory
281 ///
282 /// # Errors
283 ///
284 /// * `EPERM` - `uid != 0`
285 /// * `EFAULT` - `virtual_address` has not been mapped
286 pub unsafe fn physunmap(virtual_address: usize) -> Result<usize> {
287 syscall1(SYS_PHYSUNMAP, virtual_address)
288 }
289
290 /// Create a pair of file descriptors referencing the read and write ends of a pipe
291 pub fn pipe2(fds: &mut [usize; 2], flags: usize) -> Result<usize> {
292 unsafe { syscall2(SYS_PIPE2, fds.as_ptr() as usize, flags) }
293 }
294
295 /// Read from a file descriptor into a buffer
296 pub fn read(fd: usize, buf: &mut [u8]) -> Result<usize> {
297 unsafe { syscall3(SYS_READ, fd, buf.as_mut_ptr() as usize, buf.len()) }
298 }
299
300 /// Remove a directory
301 pub fn rmdir<T: AsRef<[u8]>>(path: T) -> Result<usize> {
302 unsafe { syscall2(SYS_RMDIR, path.as_ref().as_ptr() as usize, path.as_ref().len()) }
303 }
304
305 /// Set the process group ID
306 pub fn setpgid(pid: usize, pgid: usize) -> Result<usize> {
307 unsafe { syscall2(SYS_SETPGID, pid, pgid) }
308 }
309
310 /// Set the current process group IDs
311 pub fn setregid(rgid: usize, egid: usize) -> Result<usize> {
312 unsafe { syscall2(SYS_SETREGID, rgid, egid) }
313 }
314
315 /// Make a new scheme namespace
316 pub fn setrens(rns: usize, ens: usize) -> Result<usize> {
317 unsafe { syscall2(SYS_SETRENS, rns, ens) }
318 }
319
320 /// Set the current process user IDs
321 pub fn setreuid(ruid: usize, euid: usize) -> Result<usize> {
322 unsafe { syscall2(SYS_SETREUID, ruid, euid) }
323 }
324
325 /// Set up a signal handler
326 pub fn sigaction(sig: usize, act: Option<&SigAction>, oldact: Option<&mut SigAction>) -> Result<usize> {
327 unsafe { syscall4(SYS_SIGACTION, sig,
328 act.map(|x| x as *const _).unwrap_or_else(ptr::null) as usize,
329 oldact.map(|x| x as *mut _).unwrap_or_else(ptr::null_mut) as usize,
330 restorer as usize) }
331 }
332
333 /// Get and/or set signal masks
334 pub fn sigprocmask(how: usize, set: Option<&[u64; 2]>, oldset: Option<&mut [u64; 2]>) -> Result<usize> {
335 unsafe { syscall3(SYS_SIGPROCMASK, how,
336 set.map(|x| x as *const _).unwrap_or_else(ptr::null) as usize,
337 oldset.map(|x| x as *mut _).unwrap_or_else(ptr::null_mut) as usize) }
338 }
339
340 // Return from signal handler
341 pub fn sigreturn() -> Result<usize> {
342 unsafe { syscall0(SYS_SIGRETURN) }
343 }
344
345 /// Set the file mode creation mask
346 pub fn umask(mask: usize) -> Result<usize> {
347 unsafe { syscall1(SYS_UMASK, mask) }
348 }
349
350 /// Remove a file
351 pub fn unlink<T: AsRef<[u8]>>(path: T) -> Result<usize> {
352 unsafe { syscall2(SYS_UNLINK, path.as_ref().as_ptr() as usize, path.as_ref().len()) }
353 }
354
355 /// Convert a virtual address to a physical one
356 ///
357 /// # Errors
358 ///
359 /// * `EPERM` - `uid != 0`
360 pub unsafe fn virttophys(virtual_address: usize) -> Result<usize> {
361 syscall1(SYS_VIRTTOPHYS, virtual_address)
362 }
363
364 /// Check if a child process has exited or received a signal
365 pub fn waitpid(pid: usize, status: &mut usize, options: usize) -> Result<usize> {
366 unsafe { syscall3(SYS_WAITPID, pid, status as *mut usize as usize, options) }
367 }
368
369 /// Write a buffer to a file descriptor
370 ///
371 /// The kernel will attempt to write the bytes in `buf` to the file descriptor `fd`, returning
372 /// either an `Err`, explained below, or `Ok(count)` where `count` is the number of bytes which
373 /// were written.
374 ///
375 /// # Errors
376 ///
377 /// * `EAGAIN` - the file descriptor was opened with `O_NONBLOCK` and writing would block
378 /// * `EBADF` - the file descriptor is not valid or is not open for writing
379 /// * `EFAULT` - `buf` does not point to the process's addressible memory
380 /// * `EIO` - an I/O error occurred
381 /// * `ENOSPC` - the device containing the file descriptor has no room for data
382 /// * `EPIPE` - the file descriptor refers to a pipe or socket whose reading end is closed
383 pub fn write(fd: usize, buf: &[u8]) -> Result<usize> {
384 unsafe { syscall3(SYS_WRITE, fd, buf.as_ptr() as usize, buf.len()) }
385 }
386
387 /// Yield the process's time slice to the kernel
388 ///
389 /// This function will return Ok(0) on success
390 pub fn sched_yield() -> Result<usize> {
391 unsafe { syscall0(SYS_YIELD) }
392 }
+0
-309
rust/vendor/redox_syscall/src/data.rs less more
0 use core::ops::{Deref, DerefMut};
1 use core::{mem, slice};
2
3 #[derive(Copy, Clone, Debug, Default)]
4 #[repr(C)]
5 pub struct Event {
6 pub id: usize,
7 pub flags: usize,
8 pub data: usize
9 }
10
11 impl Deref for Event {
12 type Target = [u8];
13 fn deref(&self) -> &[u8] {
14 unsafe {
15 slice::from_raw_parts(self as *const Event as *const u8, mem::size_of::<Event>()) as &[u8]
16 }
17 }
18 }
19
20 impl DerefMut for Event {
21 fn deref_mut(&mut self) -> &mut [u8] {
22 unsafe {
23 slice::from_raw_parts_mut(self as *mut Event as *mut u8, mem::size_of::<Event>()) as &mut [u8]
24 }
25 }
26 }
27
28 #[derive(Copy, Clone, Debug, Default)]
29 #[repr(C)]
30 pub struct ITimerSpec {
31 pub it_interval: TimeSpec,
32 pub it_value: TimeSpec,
33 }
34
35 impl Deref for ITimerSpec {
36 type Target = [u8];
37 fn deref(&self) -> &[u8] {
38 unsafe {
39 slice::from_raw_parts(self as *const ITimerSpec as *const u8,
40 mem::size_of::<ITimerSpec>()) as &[u8]
41 }
42 }
43 }
44
45 impl DerefMut for ITimerSpec {
46 fn deref_mut(&mut self) -> &mut [u8] {
47 unsafe {
48 slice::from_raw_parts_mut(self as *mut ITimerSpec as *mut u8,
49 mem::size_of::<ITimerSpec>()) as &mut [u8]
50 }
51 }
52 }
53
54 #[derive(Copy, Clone, Debug, Default)]
55 #[repr(C)]
56 pub struct Map {
57 pub offset: usize,
58 pub size: usize,
59 pub flags: usize,
60 }
61
62 impl Deref for Map {
63 type Target = [u8];
64 fn deref(&self) -> &[u8] {
65 unsafe {
66 slice::from_raw_parts(self as *const Map as *const u8, mem::size_of::<Map>()) as &[u8]
67 }
68 }
69 }
70
71 impl DerefMut for Map {
72 fn deref_mut(&mut self) -> &mut [u8] {
73 unsafe {
74 slice::from_raw_parts_mut(self as *mut Map as *mut u8, mem::size_of::<Map>()) as &mut [u8]
75 }
76 }
77 }
78
79 #[derive(Copy, Clone, Debug, Default)]
80 #[repr(C)]
81 pub struct Packet {
82 pub id: u64,
83 pub pid: usize,
84 pub uid: u32,
85 pub gid: u32,
86 pub a: usize,
87 pub b: usize,
88 pub c: usize,
89 pub d: usize
90 }
91
92 impl Deref for Packet {
93 type Target = [u8];
94 fn deref(&self) -> &[u8] {
95 unsafe {
96 slice::from_raw_parts(self as *const Packet as *const u8, mem::size_of::<Packet>()) as &[u8]
97 }
98 }
99 }
100
101 impl DerefMut for Packet {
102 fn deref_mut(&mut self) -> &mut [u8] {
103 unsafe {
104 slice::from_raw_parts_mut(self as *mut Packet as *mut u8, mem::size_of::<Packet>()) as &mut [u8]
105 }
106 }
107 }
108
109 #[derive(Copy, Clone, Debug)]
110 #[repr(C)]
111 pub struct SigAction {
112 pub sa_handler: extern "C" fn(usize),
113 pub sa_mask: [u64; 2],
114 pub sa_flags: usize,
115 }
116
117 impl Default for SigAction {
118 fn default() -> Self {
119 Self {
120 sa_handler: unsafe { mem::transmute(0usize) },
121 sa_mask: [0; 2],
122 sa_flags: 0,
123 }
124 }
125 }
126
127 #[derive(Copy, Clone, Debug, Default)]
128 #[repr(C)]
129 pub struct Stat {
130 pub st_dev: u64,
131 pub st_ino: u64,
132 pub st_mode: u16,
133 pub st_nlink: u32,
134 pub st_uid: u32,
135 pub st_gid: u32,
136 pub st_size: u64,
137 pub st_blksize: u32,
138 pub st_blocks: u64,
139 pub st_mtime: u64,
140 pub st_mtime_nsec: u32,
141 pub st_atime: u64,
142 pub st_atime_nsec: u32,
143 pub st_ctime: u64,
144 pub st_ctime_nsec: u32,
145 }
146
147 impl Deref for Stat {
148 type Target = [u8];
149 fn deref(&self) -> &[u8] {
150 unsafe {
151 slice::from_raw_parts(self as *const Stat as *const u8,
152 mem::size_of::<Stat>()) as &[u8]
153 }
154 }
155 }
156
157 impl DerefMut for Stat {
158 fn deref_mut(&mut self) -> &mut [u8] {
159 unsafe {
160 slice::from_raw_parts_mut(self as *mut Stat as *mut u8,
161 mem::size_of::<Stat>()) as &mut [u8]
162 }
163 }
164 }
165
166 #[derive(Copy, Clone, Debug, Default)]
167 #[repr(C)]
168 pub struct StatVfs {
169 pub f_bsize: u32,
170 pub f_blocks: u64,
171 pub f_bfree: u64,
172 pub f_bavail: u64,
173 }
174
175 impl Deref for StatVfs {
176 type Target = [u8];
177 fn deref(&self) -> &[u8] {
178 unsafe {
179 slice::from_raw_parts(self as *const StatVfs as *const u8,
180 mem::size_of::<StatVfs>()) as &[u8]
181 }
182 }
183 }
184
185 impl DerefMut for StatVfs {
186 fn deref_mut(&mut self) -> &mut [u8] {
187 unsafe {
188 slice::from_raw_parts_mut(self as *mut StatVfs as *mut u8,
189 mem::size_of::<StatVfs>()) as &mut [u8]
190 }
191 }
192 }
193
194 #[derive(Copy, Clone, Debug, Default, PartialEq)]
195 #[repr(C)]
196 pub struct TimeSpec {
197 pub tv_sec: i64,
198 pub tv_nsec: i32,
199 }
200
201 impl Deref for TimeSpec {
202 type Target = [u8];
203 fn deref(&self) -> &[u8] {
204 unsafe {
205 slice::from_raw_parts(self as *const TimeSpec as *const u8,
206 mem::size_of::<TimeSpec>()) as &[u8]
207 }
208 }
209 }
210
211 impl DerefMut for TimeSpec {
212 fn deref_mut(&mut self) -> &mut [u8] {
213 unsafe {
214 slice::from_raw_parts_mut(self as *mut TimeSpec as *mut u8,
215 mem::size_of::<TimeSpec>()) as &mut [u8]
216 }
217 }
218 }
219
220 #[derive(Copy, Clone, Debug, Default)]
221 #[repr(C)]
222 #[cfg(target_arch = "x86_64")]
223 pub struct IntRegisters {
224 pub r15: usize,
225 pub r14: usize,
226 pub r13: usize,
227 pub r12: usize,
228 pub rbp: usize,
229 pub rbx: usize,
230 pub r11: usize,
231 pub r10: usize,
232 pub r9: usize,
233 pub r8: usize,
234 pub rax: usize,
235 pub rcx: usize,
236 pub rdx: usize,
237 pub rsi: usize,
238 pub rdi: usize,
239 // pub orig_rax: usize,
240 pub rip: usize,
241 pub cs: usize,
242 pub eflags: usize,
243 pub rsp: usize,
244 pub ss: usize,
245 pub fs_base: usize,
246 pub gs_base: usize,
247 pub ds: usize,
248 pub es: usize,
249 pub fs: usize,
250 pub gs: usize
251 }
252
253 impl Deref for IntRegisters {
254 type Target = [u8];
255 fn deref(&self) -> &[u8] {
256 unsafe {
257 slice::from_raw_parts(self as *const IntRegisters as *const u8, mem::size_of::<IntRegisters>()) as &[u8]
258 }
259 }
260 }
261
262 impl DerefMut for IntRegisters {
263 fn deref_mut(&mut self) -> &mut [u8] {
264 unsafe {
265 slice::from_raw_parts_mut(self as *mut IntRegisters as *mut u8, mem::size_of::<IntRegisters>()) as &mut [u8]
266 }
267 }
268 }
269
270 #[derive(Clone, Copy)]
271 #[repr(C)]
272 #[cfg(target_arch = "x86_64")]
273 pub struct FloatRegisters {
274 pub cwd: u16,
275 pub swd: u16,
276 pub ftw: u16,
277 pub fop: u16,
278 pub rip: u64,
279 pub rdp: u64,
280 pub mxcsr: u32,
281 pub mxcr_mask: u32,
282 pub st_space: [u32; 32],
283 pub xmm_space: [u32; 64]
284 }
285
286 impl Default for FloatRegisters {
287 fn default() -> Self {
288 // xmm_space is not Default until const generics
289 unsafe { mem::zeroed() }
290 }
291 }
292
293 impl Deref for FloatRegisters {
294 type Target = [u8];
295 fn deref(&self) -> &[u8] {
296 unsafe {
297 slice::from_raw_parts(self as *const FloatRegisters as *const u8, mem::size_of::<FloatRegisters>()) as &[u8]
298 }
299 }
300 }
301
302 impl DerefMut for FloatRegisters {
303 fn deref_mut(&mut self) -> &mut [u8] {
304 unsafe {
305 slice::from_raw_parts_mut(self as *mut FloatRegisters as *mut u8, mem::size_of::<FloatRegisters>()) as &mut [u8]
306 }
307 }
308 }
+0
-311
rust/vendor/redox_syscall/src/error.rs less more
0 use core::{fmt, result};
1
2 #[derive(Eq, PartialEq)]
3 pub struct Error {
4 pub errno: i32,
5 }
6
7 pub type Result<T> = result::Result<T, Error>;
8
9 impl Error {
10 pub fn new(errno: i32) -> Error {
11 Error { errno: errno }
12 }
13
14 pub fn mux(result: Result<usize>) -> usize {
15 match result {
16 Ok(value) => value,
17 Err(error) => -error.errno as usize,
18 }
19 }
20
21 pub fn demux(value: usize) -> Result<usize> {
22 let errno = -(value as i32);
23 if errno >= 1 && errno < STR_ERROR.len() as i32 {
24 Err(Error::new(errno))
25 } else {
26 Ok(value)
27 }
28 }
29
30 pub fn text(&self) -> &'static str {
31 STR_ERROR.get(self.errno as usize).map(|&x| x).unwrap_or("Unknown Error")
32 }
33 }
34
35 impl fmt::Debug for Error {
36 fn fmt(&self, f: &mut fmt::Formatter) -> result::Result<(), fmt::Error> {
37 f.write_str(self.text())
38 }
39 }
40
41 impl fmt::Display for Error {
42 fn fmt(&self, f: &mut fmt::Formatter) -> result::Result<(), fmt::Error> {
43 f.write_str(self.text())
44 }
45 }
46
47 pub const EPERM: i32 = 1; /* Operation not permitted */
48 pub const ENOENT: i32 = 2; /* No such file or directory */
49 pub const ESRCH: i32 = 3; /* No such process */
50 pub const EINTR: i32 = 4; /* Interrupted system call */
51 pub const EIO: i32 = 5; /* I/O error */
52 pub const ENXIO: i32 = 6; /* No such device or address */
53 pub const E2BIG: i32 = 7; /* Argument list too long */
54 pub const ENOEXEC: i32 = 8; /* Exec format error */
55 pub const EBADF: i32 = 9; /* Bad file number */
56 pub const ECHILD: i32 = 10; /* No child processes */
57 pub const EAGAIN: i32 = 11; /* Try again */
58 pub const ENOMEM: i32 = 12; /* Out of memory */
59 pub const EACCES: i32 = 13; /* Permission denied */
60 pub const EFAULT: i32 = 14; /* Bad address */
61 pub const ENOTBLK: i32 = 15; /* Block device required */
62 pub const EBUSY: i32 = 16; /* Device or resource busy */
63 pub const EEXIST: i32 = 17; /* File exists */
64 pub const EXDEV: i32 = 18; /* Cross-device link */
65 pub const ENODEV: i32 = 19; /* No such device */
66 pub const ENOTDIR: i32 = 20; /* Not a directory */
67 pub const EISDIR: i32 = 21; /* Is a directory */
68 pub const EINVAL: i32 = 22; /* Invalid argument */
69 pub const ENFILE: i32 = 23; /* File table overflow */
70 pub const EMFILE: i32 = 24; /* Too many open files */
71 pub const ENOTTY: i32 = 25; /* Not a typewriter */
72 pub const ETXTBSY: i32 = 26; /* Text file busy */
73 pub const EFBIG: i32 = 27; /* File too large */
74 pub const ENOSPC: i32 = 28; /* No space left on device */
75 pub const ESPIPE: i32 = 29; /* Illegal seek */
76 pub const EROFS: i32 = 30; /* Read-only file system */
77 pub const EMLINK: i32 = 31; /* Too many links */
78 pub const EPIPE: i32 = 32; /* Broken pipe */
79 pub const EDOM: i32 = 33; /* Math argument out of domain of func */
80 pub const ERANGE: i32 = 34; /* Math result not representable */
81 pub const EDEADLK: i32 = 35; /* Resource deadlock would occur */
82 pub const ENAMETOOLONG: i32 = 36; /* File name too long */
83 pub const ENOLCK: i32 = 37; /* No record locks available */
84 pub const ENOSYS: i32 = 38; /* Function not implemented */
85 pub const ENOTEMPTY: i32 = 39; /* Directory not empty */
86 pub const ELOOP: i32 = 40; /* Too many symbolic links encountered */
87 pub const EWOULDBLOCK: i32 = 41; /* Operation would block */
88 pub const ENOMSG: i32 = 42; /* No message of desired type */
89 pub const EIDRM: i32 = 43; /* Identifier removed */
90 pub const ECHRNG: i32 = 44; /* Channel number out of range */
91 pub const EL2NSYNC: i32 = 45; /* Level 2 not synchronized */
92 pub const EL3HLT: i32 = 46; /* Level 3 halted */
93 pub const EL3RST: i32 = 47; /* Level 3 reset */
94 pub const ELNRNG: i32 = 48; /* Link number out of range */
95 pub const EUNATCH: i32 = 49; /* Protocol driver not attached */
96 pub const ENOCSI: i32 = 50; /* No CSI structure available */
97 pub const EL2HLT: i32 = 51; /* Level 2 halted */
98 pub const EBADE: i32 = 52; /* Invalid exchange */
99 pub const EBADR: i32 = 53; /* Invalid request descriptor */
100 pub const EXFULL: i32 = 54; /* Exchange full */
101 pub const ENOANO: i32 = 55; /* No anode */
102 pub const EBADRQC: i32 = 56; /* Invalid request code */
103 pub const EBADSLT: i32 = 57; /* Invalid slot */
104 pub const EDEADLOCK: i32 = 58; /* Resource deadlock would occur */
105 pub const EBFONT: i32 = 59; /* Bad font file format */
106 pub const ENOSTR: i32 = 60; /* Device not a stream */
107 pub const ENODATA: i32 = 61; /* No data available */
108 pub const ETIME: i32 = 62; /* Timer expired */
109 pub const ENOSR: i32 = 63; /* Out of streams resources */
110 pub const ENONET: i32 = 64; /* Machine is not on the network */
111 pub const ENOPKG: i32 = 65; /* Package not installed */
112 pub const EREMOTE: i32 = 66; /* Object is remote */
113 pub const ENOLINK: i32 = 67; /* Link has been severed */
114 pub const EADV: i32 = 68; /* Advertise error */
115 pub const ESRMNT: i32 = 69; /* Srmount error */
116 pub const ECOMM: i32 = 70; /* Communication error on send */
117 pub const EPROTO: i32 = 71; /* Protocol error */
118 pub const EMULTIHOP: i32 = 72; /* Multihop attempted */
119 pub const EDOTDOT: i32 = 73; /* RFS specific error */
120 pub const EBADMSG: i32 = 74; /* Not a data message */
121 pub const EOVERFLOW: i32 = 75; /* Value too large for defined data type */
122 pub const ENOTUNIQ: i32 = 76; /* Name not unique on network */
123 pub const EBADFD: i32 = 77; /* File descriptor in bad state */
124 pub const EREMCHG: i32 = 78; /* Remote address changed */
125 pub const ELIBACC: i32 = 79; /* Can not access a needed shared library */
126 pub const ELIBBAD: i32 = 80; /* Accessing a corrupted shared library */
127 pub const ELIBSCN: i32 = 81; /* .lib section in a.out corrupted */
128 pub const ELIBMAX: i32 = 82; /* Attempting to link in too many shared libraries */
129 pub const ELIBEXEC: i32 = 83; /* Cannot exec a shared library directly */
130 pub const EILSEQ: i32 = 84; /* Illegal byte sequence */
131 pub const ERESTART: i32 = 85; /* Interrupted system call should be restarted */
132 pub const ESTRPIPE: i32 = 86; /* Streams pipe error */
133 pub const EUSERS: i32 = 87; /* Too many users */
134 pub const ENOTSOCK: i32 = 88; /* Socket operation on non-socket */
135 pub const EDESTADDRREQ: i32 = 89; /* Destination address required */
136 pub const EMSGSIZE: i32 = 90; /* Message too long */
137 pub const EPROTOTYPE: i32 = 91; /* Protocol wrong type for socket */
138 pub const ENOPROTOOPT: i32 = 92; /* Protocol not available */
139 pub const EPROTONOSUPPORT: i32 = 93; /* Protocol not supported */
140 pub const ESOCKTNOSUPPORT: i32 = 94; /* Socket type not supported */
141 pub const EOPNOTSUPP: i32 = 95; /* Operation not supported on transport endpoint */
142 pub const EPFNOSUPPORT: i32 = 96; /* Protocol family not supported */
143 pub const EAFNOSUPPORT: i32 = 97; /* Address family not supported by protocol */
144 pub const EADDRINUSE: i32 = 98; /* Address already in use */
145 pub const EADDRNOTAVAIL: i32 = 99; /* Cannot assign requested address */
146 pub const ENETDOWN: i32 = 100; /* Network is down */
147 pub const ENETUNREACH: i32 = 101; /* Network is unreachable */
148 pub const ENETRESET: i32 = 102; /* Network dropped connection because of reset */
149 pub const ECONNABORTED: i32 = 103; /* Software caused connection abort */
150 pub const ECONNRESET: i32 = 104; /* Connection reset by peer */
151 pub const ENOBUFS: i32 = 105; /* No buffer space available */
152 pub const EISCONN: i32 = 106; /* Transport endpoint is already connected */
153 pub const ENOTCONN: i32 = 107; /* Transport endpoint is not connected */
154 pub const ESHUTDOWN: i32 = 108; /* Cannot send after transport endpoint shutdown */
155 pub const ETOOMANYREFS: i32 = 109; /* Too many references: cannot splice */
156 pub const ETIMEDOUT: i32 = 110; /* Connection timed out */
157 pub const ECONNREFUSED: i32 = 111; /* Connection refused */
158 pub const EHOSTDOWN: i32 = 112; /* Host is down */
159 pub const EHOSTUNREACH: i32 = 113; /* No route to host */
160 pub const EALREADY: i32 = 114; /* Operation already in progress */
161 pub const EINPROGRESS: i32 = 115; /* Operation now in progress */
162 pub const ESTALE: i32 = 116; /* Stale NFS file handle */
163 pub const EUCLEAN: i32 = 117; /* Structure needs cleaning */
164 pub const ENOTNAM: i32 = 118; /* Not a XENIX named type file */
165 pub const ENAVAIL: i32 = 119; /* No XENIX semaphores available */
166 pub const EISNAM: i32 = 120; /* Is a named type file */
167 pub const EREMOTEIO: i32 = 121; /* Remote I/O error */
168 pub const EDQUOT: i32 = 122; /* Quota exceeded */
169 pub const ENOMEDIUM: i32 = 123; /* No medium found */
170 pub const EMEDIUMTYPE: i32 = 124; /* Wrong medium type */
171 pub const ECANCELED: i32 = 125; /* Operation Canceled */
172 pub const ENOKEY: i32 = 126; /* Required key not available */
173 pub const EKEYEXPIRED: i32 = 127; /* Key has expired */
174 pub const EKEYREVOKED: i32 = 128; /* Key has been revoked */
175 pub const EKEYREJECTED: i32 = 129; /* Key was rejected by service */
176 pub const EOWNERDEAD: i32 = 130; /* Owner died */
177 pub const ENOTRECOVERABLE: i32 = 131; /* State not recoverable */
178
179 pub static STR_ERROR: [&'static str; 132] = ["Success",
180 "Operation not permitted",
181 "No such file or directory",
182 "No such process",
183 "Interrupted system call",
184 "I/O error",
185 "No such device or address",
186 "Argument list too long",
187 "Exec format error",
188 "Bad file number",
189 "No child processes",
190 "Try again",
191 "Out of memory",
192 "Permission denied",
193 "Bad address",
194 "Block device required",
195 "Device or resource busy",
196 "File exists",
197 "Cross-device link",
198 "No such device",
199 "Not a directory",
200 "Is a directory",
201 "Invalid argument",
202 "File table overflow",
203 "Too many open files",
204 "Not a typewriter",
205 "Text file busy",
206 "File too large",
207 "No space left on device",
208 "Illegal seek",
209 "Read-only file system",
210 "Too many links",
211 "Broken pipe",
212 "Math argument out of domain of func",
213 "Math result not representable",
214 "Resource deadlock would occur",
215 "File name too long",
216 "No record locks available",
217 "Function not implemented",
218 "Directory not empty",
219 "Too many symbolic links encountered",
220 "Operation would block",
221 "No message of desired type",
222 "Identifier removed",
223 "Channel number out of range",
224 "Level 2 not synchronized",
225 "Level 3 halted",
226 "Level 3 reset",
227 "Link number out of range",
228 "Protocol driver not attached",
229 "No CSI structure available",
230 "Level 2 halted",
231 "Invalid exchange",
232 "Invalid request descriptor",
233 "Exchange full",
234 "No anode",
235 "Invalid request code",
236 "Invalid slot",
237 "Resource deadlock would occur",
238 "Bad font file format",
239 "Device not a stream",
240 "No data available",
241 "Timer expired",
242 "Out of streams resources",
243 "Machine is not on the network",
244 "Package not installed",
245 "Object is remote",
246 "Link has been severed",
247 "Advertise error",
248 "Srmount error",
249 "Communication error on send",
250 "Protocol error",
251 "Multihop attempted",
252 "RFS specific error",
253 "Not a data message",
254 "Value too large for defined data type",
255 "Name not unique on network",
256 "File descriptor in bad state",
257 "Remote address changed",
258 "Can not access a needed shared library",
259 "Accessing a corrupted shared library",
260 ".lib section in a.out corrupted",
261 "Attempting to link in too many shared libraries",
262 "Cannot exec a shared library directly",
263 "Illegal byte sequence",
264 "Interrupted system call should be restarted",
265 "Streams pipe error",
266 "Too many users",
267 "Socket operation on non-socket",
268 "Destination address required",
269 "Message too long",
270 "Protocol wrong type for socket",
271 "Protocol not available",
272 "Protocol not supported",
273 "Socket type not supported",
274 "Operation not supported on transport endpoint",
275 "Protocol family not supported",
276 "Address family not supported by protocol",
277 "Address already in use",
278 "Cannot assign requested address",
279 "Network is down",
280 "Network is unreachable",
281 "Network dropped connection because of reset",
282 "Software caused connection abort",
283 "Connection reset by peer",
284 "No buffer space available",
285 "Transport endpoint is already connected",
286 "Transport endpoint is not connected",
287 "Cannot send after transport endpoint shutdown",
288 "Too many references: cannot splice",
289 "Connection timed out",
290 "Connection refused",
291 "Host is down",
292 "No route to host",
293 "Operation already in progress",
294 "Operation now in progress",
295 "Stale NFS file handle",
296 "Structure needs cleaning",
297 "Not a XENIX named type file",
298 "No XENIX semaphores available",
299 "Is a named type file",
300 "Remote I/O error",
301 "Quota exceeded",
302 "No medium found",
303 "Wrong medium type",
304 "Operation Canceled",
305 "Required key not available",
306 "Key has expired",
307 "Key has been revoked",
308 "Key was rejected by service",
309 "Owner died",
310 "State not recoverable"];
+0
-169
rust/vendor/redox_syscall/src/flag.rs less more
0 pub const CLONE_VM: usize = 0x100;
1 pub const CLONE_FS: usize = 0x200;
2 pub const CLONE_FILES: usize = 0x400;
3 pub const CLONE_SIGHAND: usize = 0x800;
4 pub const CLONE_VFORK: usize = 0x4000;
5 pub const CLONE_THREAD: usize = 0x10000;
6 pub const CLONE_STACK: usize = 0x1000_0000;
7
8 pub const CLOCK_REALTIME: usize = 1;
9 pub const CLOCK_MONOTONIC: usize = 4;
10
11 pub const EVENT_NONE: usize = 0;
12 pub const EVENT_READ: usize = 1;
13 pub const EVENT_WRITE: usize = 2;
14
15 pub const F_DUPFD: usize = 0;
16 pub const F_GETFD: usize = 1;
17 pub const F_SETFD: usize = 2;
18 pub const F_GETFL: usize = 3;
19 pub const F_SETFL: usize = 4;
20
21 pub const FUTEX_WAIT: usize = 0;
22 pub const FUTEX_WAKE: usize = 1;
23 pub const FUTEX_REQUEUE: usize = 2;
24
25 pub const MAP_SHARED: usize = 0x0001;
26 pub const MAP_PRIVATE: usize = 0x0002;
27
28 pub const MODE_TYPE: u16 = 0xF000;
29 pub const MODE_DIR: u16 = 0x4000;
30 pub const MODE_FILE: u16 = 0x8000;
31 pub const MODE_SYMLINK: u16 = 0xA000;
32 pub const MODE_FIFO: u16 = 0x1000;
33 pub const MODE_CHR: u16 = 0x2000;
34
35 pub const MODE_PERM: u16 = 0x0FFF;
36 pub const MODE_SETUID: u16 = 0o4000;
37 pub const MODE_SETGID: u16 = 0o2000;
38
39 pub const O_RDONLY: usize = 0x0001_0000;
40 pub const O_WRONLY: usize = 0x0002_0000;
41 pub const O_RDWR: usize = 0x0003_0000;
42 pub const O_NONBLOCK: usize = 0x0004_0000;
43 pub const O_APPEND: usize = 0x0008_0000;
44 pub const O_SHLOCK: usize = 0x0010_0000;
45 pub const O_EXLOCK: usize = 0x0020_0000;
46 pub const O_ASYNC: usize = 0x0040_0000;
47 pub const O_FSYNC: usize = 0x0080_0000;
48 pub const O_CLOEXEC: usize = 0x0100_0000;
49 pub const O_CREAT: usize = 0x0200_0000;
50 pub const O_TRUNC: usize = 0x0400_0000;
51 pub const O_EXCL: usize = 0x0800_0000;
52 pub const O_DIRECTORY: usize = 0x1000_0000;
53 pub const O_STAT: usize = 0x2000_0000;
54 pub const O_SYMLINK: usize = 0x4000_0000;
55 pub const O_NOFOLLOW: usize = 0x8000_0000;
56 pub const O_ACCMODE: usize = O_RDONLY | O_WRONLY | O_RDWR;
57
58 pub const PHYSMAP_WRITE: usize = 0x0000_0001;
59 pub const PHYSMAP_WRITE_COMBINE: usize = 0x0000_0002;
60 pub const PHYSMAP_NO_CACHE: usize = 0x0000_0004;
61
62 pub const PROT_NONE: usize = 0x0000_0000;
63 pub const PROT_EXEC: usize = 0x0001_0000;
64 pub const PROT_WRITE: usize = 0x0002_0000;
65 pub const PROT_READ: usize = 0x0004_0000;
66
67 pub const PTRACE_CONT: u8 = 0b0000_0001;
68 pub const PTRACE_SINGLESTEP: u8 = 0b0000_0010;
69 pub const PTRACE_SYSCALL: u8 = 0b0000_0011;
70 pub const PTRACE_WAIT: u8 = 0b0000_0100;
71 pub const PTRACE_OPERATIONMASK: u8 = 0b0000_1111;
72 pub const PTRACE_SYSEMU: u8 = 0b0001_0000;
73
74 pub const SEEK_SET: usize = 0;
75 pub const SEEK_CUR: usize = 1;
76 pub const SEEK_END: usize = 2;
77
78 pub const SIGHUP: usize = 1;
79 pub const SIGINT: usize = 2;
80 pub const SIGQUIT: usize = 3;
81 pub const SIGILL: usize = 4;
82 pub const SIGTRAP: usize = 5;
83 pub const SIGABRT: usize = 6;
84 pub const SIGBUS: usize = 7;
85 pub const SIGFPE: usize = 8;
86 pub const SIGKILL: usize = 9;
87 pub const SIGUSR1: usize = 10;
88 pub const SIGSEGV: usize = 11;
89 pub const SIGUSR2: usize = 12;
90 pub const SIGPIPE: usize = 13;
91 pub const SIGALRM: usize = 14;
92 pub const SIGTERM: usize = 15;
93 pub const SIGSTKFLT: usize= 16;
94 pub const SIGCHLD: usize = 17;
95 pub const SIGCONT: usize = 18;
96 pub const SIGSTOP: usize = 19;
97 pub const SIGTSTP: usize = 20;
98 pub const SIGTTIN: usize = 21;
99 pub const SIGTTOU: usize = 22;
100 pub const SIGURG: usize = 23;
101 pub const SIGXCPU: usize = 24;
102 pub const SIGXFSZ: usize = 25;
103 pub const SIGVTALRM: usize= 26;
104 pub const SIGPROF: usize = 27;
105 pub const SIGWINCH: usize = 28;
106 pub const SIGIO: usize = 29;
107 pub const SIGPWR: usize = 30;
108 pub const SIGSYS: usize = 31;
109
110 pub const SIG_DFL: usize = 0;
111 pub const SIG_IGN: usize = 1;
112
113 pub const SIG_BLOCK: usize = 0;
114 pub const SIG_UNBLOCK: usize = 1;
115 pub const SIG_SETMASK: usize = 2;
116
117 pub const SA_NOCLDSTOP: usize = 0x00000001;
118 pub const SA_NOCLDWAIT: usize = 0x00000002;
119 pub const SA_SIGINFO: usize = 0x00000004;
120 pub const SA_RESTORER: usize = 0x04000000;
121 pub const SA_ONSTACK: usize = 0x08000000;
122 pub const SA_RESTART: usize = 0x10000000;
123 pub const SA_NODEFER: usize = 0x40000000;
124 pub const SA_RESETHAND: usize = 0x80000000;
125
126 pub const WNOHANG: usize = 0x01;
127 pub const WUNTRACED: usize = 0x02;
128 pub const WCONTINUED: usize = 0x08;
129
130 /// True if status indicates the child is stopped.
131 pub fn wifstopped(status: usize) -> bool {
132 (status & 0xff) == 0x7f
133 }
134
135 /// If wifstopped(status), the signal that stopped the child.
136 pub fn wstopsig(status: usize) -> usize {
137 (status >> 8) & 0xff
138 }
139
140 /// True if status indicates the child continued after a stop.
141 pub fn wifcontinued(status: usize) -> bool {
142 status == 0xffff
143 }
144
145 /// True if STATUS indicates termination by a signal.
146 pub fn wifsignaled(status: usize) -> bool {
147 ((status & 0x7f) + 1) as i8 >= 2
148 }
149
150 /// If wifsignaled(status), the terminating signal.
151 pub fn wtermsig(status: usize) -> usize {
152 status & 0x7f
153 }
154
155 /// True if status indicates normal termination.
156 pub fn wifexited(status: usize) -> bool {
157 wtermsig(status) == 0
158 }
159
160 /// If wifexited(status), the exit status.
161 pub fn wexitstatus(status: usize) -> usize {
162 (status >> 8) & 0xff
163 }
164
165 /// True if status indicates a core dump was created.
166 pub fn wcoredump(status: usize) -> bool {
167 (status & 0x80) != 0
168 }
+0
-76
rust/vendor/redox_syscall/src/io/dma.rs less more
0 use core::{mem, ptr};
1 use core::ops::{Deref, DerefMut};
2
3 use Result;
4
5 struct PhysBox {
6 address: usize,
7 size: usize
8 }
9
10 impl PhysBox {
11 fn new(size: usize) -> Result<PhysBox> {
12 let address = unsafe { ::physalloc(size)? };
13 Ok(PhysBox {
14 address: address,
15 size: size
16 })
17 }
18 }
19
20 impl Drop for PhysBox {
21 fn drop(&mut self) {
22 let _ = unsafe { ::physfree(self.address, self.size) };
23 }
24 }
25
26 pub struct Dma<T> {
27 phys: PhysBox,
28 virt: *mut T
29 }
30
31 impl<T> Dma<T> {
32 pub fn new(value: T) -> Result<Dma<T>> {
33 let phys = PhysBox::new(mem::size_of::<T>())?;
34 let virt = unsafe { ::physmap(phys.address, phys.size, ::PHYSMAP_WRITE)? } as *mut T;
35 unsafe { ptr::write(virt, value); }
36 Ok(Dma {
37 phys: phys,
38 virt: virt
39 })
40 }
41
42 pub fn zeroed() -> Result<Dma<T>> {
43 let phys = PhysBox::new(mem::size_of::<T>())?;
44 let virt = unsafe { ::physmap(phys.address, phys.size, ::PHYSMAP_WRITE)? } as *mut T;
45 unsafe { ptr::write_bytes(virt as *mut u8, 0, phys.size); }
46 Ok(Dma {
47 phys: phys,
48 virt: virt
49 })
50 }
51
52 pub fn physical(&self) -> usize {
53 self.phys.address
54 }
55 }
56
57 impl<T> Deref for Dma<T> {
58 type Target = T;
59 fn deref(&self) -> &T {
60 unsafe { &*self.virt }
61 }
62 }
63
64 impl<T> DerefMut for Dma<T> {
65 fn deref_mut(&mut self) -> &mut T {
66 unsafe { &mut *self.virt }
67 }
68 }
69
70 impl<T> Drop for Dma<T> {
71 fn drop(&mut self) {
72 unsafe { drop(ptr::read(self.virt)); }
73 let _ = unsafe { ::physunmap(self.virt as usize) };
74 }
75 }
+0
-67
rust/vendor/redox_syscall/src/io/io.rs less more
0 use core::cmp::PartialEq;
1 use core::ops::{BitAnd, BitOr, Not};
2
3 pub trait Io {
4 type Value: Copy + PartialEq + BitAnd<Output = Self::Value> + BitOr<Output = Self::Value> + Not<Output = Self::Value>;
5
6 fn read(&self) -> Self::Value;
7 fn write(&mut self, value: Self::Value);
8
9 #[inline(always)]
10 fn readf(&self, flags: Self::Value) -> bool {
11 (self.read() & flags) as Self::Value == flags
12 }
13
14 #[inline(always)]
15 fn writef(&mut self, flags: Self::Value, value: bool) {
16 let tmp: Self::Value = match value {
17 true => self.read() | flags,
18 false => self.read() & !flags,
19 };
20 self.write(tmp);
21 }
22 }
23
24 pub struct ReadOnly<I: Io> {
25 inner: I
26 }
27
28 impl<I: Io> ReadOnly<I> {
29 pub const fn new(inner: I) -> ReadOnly<I> {
30 ReadOnly {
31 inner: inner
32 }
33 }
34
35 #[inline(always)]
36 pub fn read(&self) -> I::Value {
37 self.inner.read()
38 }
39
40 #[inline(always)]
41 pub fn readf(&self, flags: I::Value) -> bool {
42 self.inner.readf(flags)
43 }
44 }
45
46 pub struct WriteOnly<I: Io> {
47 inner: I
48 }
49
50 impl<I: Io> WriteOnly<I> {
51 pub const fn new(inner: I) -> WriteOnly<I> {
52 WriteOnly {
53 inner: inner
54 }
55 }
56
57 #[inline(always)]
58 pub fn write(&mut self, value: I::Value) {
59 self.inner.write(value)
60 }
61
62 #[inline(always)]
63 pub fn writef(&mut self, flags: I::Value, value: bool) {
64 self.inner.writef(flags, value)
65 }
66 }
+0
-31
rust/vendor/redox_syscall/src/io/mmio.rs less more
0 use core::ptr::{read_volatile, write_volatile};
1 use core::mem::uninitialized;
2 use core::ops::{BitAnd, BitOr, Not};
3
4 use super::io::Io;
5
6 #[repr(packed)]
7 pub struct Mmio<T> {
8 value: T,
9 }
10
11 impl<T> Mmio<T> {
12 /// Create a new Mmio without initializing
13 pub fn new() -> Self {
14 Mmio {
15 value: unsafe { uninitialized() }
16 }
17 }
18 }
19
20 impl<T> Io for Mmio<T> where T: Copy + PartialEq + BitAnd<Output = T> + BitOr<Output = T> + Not<Output = T> {
21 type Value = T;
22
23 fn read(&self) -> T {
24 unsafe { read_volatile(&self.value) }
25 }
26
27 fn write(&mut self, value: T) {
28 unsafe { write_volatile(&mut self.value, value) };
29 }
30 }
+0
-11
rust/vendor/redox_syscall/src/io/mod.rs less more
0 //! I/O functions
1
2 pub use self::dma::*;
3 pub use self::io::*;
4 pub use self::mmio::*;
5 pub use self::pio::*;
6
7 mod dma;
8 mod io;
9 mod mmio;
10 mod pio;
+0
-89
rust/vendor/redox_syscall/src/io/pio.rs less more
0 use core::marker::PhantomData;
1
2 use super::io::Io;
3
4 /// Generic PIO
5 #[derive(Copy, Clone)]
6 pub struct Pio<T> {
7 port: u16,
8 value: PhantomData<T>,
9 }
10
11 impl<T> Pio<T> {
12 /// Create a PIO from a given port
13 pub const fn new(port: u16) -> Self {
14 Pio::<T> {
15 port: port,
16 value: PhantomData,
17 }
18 }
19 }
20
21 /// Read/Write for byte PIO
22 impl Io for Pio<u8> {
23 type Value = u8;
24
25 /// Read
26 #[inline(always)]
27 fn read(&self) -> u8 {
28 let value: u8;
29 unsafe {
30 asm!("in $0, $1" : "={al}"(value) : "{dx}"(self.port) : "memory" : "intel", "volatile");
31 }
32 value
33 }
34
35 /// Write
36 #[inline(always)]
37 fn write(&mut self, value: u8) {
38 unsafe {
39 asm!("out $1, $0" : : "{al}"(value), "{dx}"(self.port) : "memory" : "intel", "volatile");
40 }
41 }
42 }
43
44 /// Read/Write for word PIO
45 impl Io for Pio<u16> {
46 type Value = u16;
47
48 /// Read
49 #[inline(always)]
50 fn read(&self) -> u16 {
51 let value: u16;
52 unsafe {
53 asm!("in $0, $1" : "={ax}"(value) : "{dx}"(self.port) : "memory" : "intel", "volatile");
54 }
55 value
56 }
57
58 /// Write
59 #[inline(always)]
60 fn write(&mut self, value: u16) {
61 unsafe {
62 asm!("out $1, $0" : : "{ax}"(value), "{dx}"(self.port) : "memory" : "intel", "volatile");
63 }
64 }
65 }
66
67 /// Read/Write for doubleword PIO
68 impl Io for Pio<u32> {
69 type Value = u32;
70
71 /// Read
72 #[inline(always)]
73 fn read(&self) -> u32 {
74 let value: u32;
75 unsafe {
76 asm!("in $0, $1" : "={eax}"(value) : "{dx}"(self.port) : "memory" : "intel", "volatile");
77 }
78 value
79 }
80
81 /// Write
82 #[inline(always)]
83 fn write(&mut self, value: u32) {
84 unsafe {
85 asm!("out $1, $0" : : "{eax}"(value), "{dx}"(self.port) : "memory" : "intel", "volatile");
86 }
87 }
88 }
+0
-59
rust/vendor/redox_syscall/src/lib.rs less more
0 #![feature(asm)]
1 #![feature(const_fn)]
2 #![cfg_attr(not(test), no_std)]
3
4 #[cfg(test)]
5 extern crate core;
6
7 pub use self::arch::*;
8 pub use self::call::*;
9 pub use self::data::*;
10 pub use self::error::*;
11 pub use self::flag::*;
12 pub use self::io::*;
13 pub use self::number::*;
14 pub use self::scheme::*;
15
16 #[cfg(all(target_os = "redox", target_arch = "arm"))]
17 #[path="arch/arm.rs"]
18 mod arch;
19
20 #[cfg(all(target_os = "redox", target_arch = "aarch64"))]
21 #[path="arch/aarch64.rs"]
22 mod arch;
23
24 #[cfg(all(target_os = "redox", target_arch = "x86"))]
25 #[path="arch/x86.rs"]
26 mod arch;
27
28 #[cfg(all(target_os = "redox", target_arch = "x86_64"))]
29 #[path="arch/x86_64.rs"]
30 mod arch;
31
32 #[cfg(not(target_os = "redox"))]
33 #[path="arch/nonredox.rs"]
34 mod arch;
35
36 /// Function definitions
37 pub mod call;
38
39 /// Complex structures that are used for some system calls
40 pub mod data;
41
42 /// All errors that can be generated by a system call
43 pub mod error;
44
45 /// Flags used as an argument to many system calls
46 pub mod flag;
47
48 /// Functions for low level hardware control
49 pub mod io;
50
51 /// Call numbers used by each system call
52 pub mod number;
53
54 /// A trait useful for scheme handlers
55 pub mod scheme;
56
57 #[cfg(test)]
58 mod tests;
+0
-76
rust/vendor/redox_syscall/src/number.rs less more
0 pub const SYS_CLASS: usize = 0xF000_0000;
1 pub const SYS_CLASS_PATH: usize=0x1000_0000;
2 pub const SYS_CLASS_FILE: usize=0x2000_0000;
3
4 pub const SYS_ARG: usize = 0x0F00_0000;
5 pub const SYS_ARG_SLICE: usize =0x0100_0000;
6 pub const SYS_ARG_MSLICE: usize=0x0200_0000;
7 pub const SYS_ARG_PATH: usize = 0x0300_0000;
8
9 pub const SYS_RET: usize = 0x00F0_0000;
10 pub const SYS_RET_FILE: usize = 0x0010_0000;
11
12 pub const SYS_LINK: usize = SYS_CLASS_PATH | SYS_ARG_PATH | 9;
13 pub const SYS_OPEN: usize = SYS_CLASS_PATH | SYS_RET_FILE | 5;
14 pub const SYS_CHMOD: usize = SYS_CLASS_PATH | 15;
15 pub const SYS_RMDIR: usize = SYS_CLASS_PATH | 84;
16 pub const SYS_UNLINK: usize = SYS_CLASS_PATH | 10;
17
18 pub const SYS_CLOSE: usize = SYS_CLASS_FILE | 6;
19 pub const SYS_DUP: usize = SYS_CLASS_FILE | SYS_RET_FILE | 41;
20 pub const SYS_DUP2: usize = SYS_CLASS_FILE | SYS_RET_FILE | 63;
21 pub const SYS_READ: usize = SYS_CLASS_FILE | SYS_ARG_MSLICE | 3;
22 pub const SYS_WRITE: usize = SYS_CLASS_FILE | SYS_ARG_SLICE | 4;
23 pub const SYS_LSEEK: usize = SYS_CLASS_FILE | 19;
24 pub const SYS_FCHMOD: usize = SYS_CLASS_FILE | 94;
25 pub const SYS_FCHOWN: usize = SYS_CLASS_FILE | 207;
26 pub const SYS_FCNTL: usize = SYS_CLASS_FILE | 55;
27 pub const SYS_FEVENT: usize = SYS_CLASS_FILE | 927;
28 pub const SYS_FEXEC: usize = SYS_CLASS_FILE | 11;
29 pub const SYS_FMAP: usize = SYS_CLASS_FILE | SYS_ARG_SLICE | 90;
30 pub const SYS_FUNMAP: usize = SYS_CLASS_FILE | 91;
31 pub const SYS_FPATH: usize = SYS_CLASS_FILE | SYS_ARG_MSLICE | 928;
32 pub const SYS_FRENAME: usize = SYS_CLASS_FILE | SYS_ARG_PATH | 38;
33 pub const SYS_FSTAT: usize = SYS_CLASS_FILE | SYS_ARG_MSLICE | 28;
34 pub const SYS_FSTATVFS: usize = SYS_CLASS_FILE | SYS_ARG_MSLICE | 100;
35 pub const SYS_FSYNC: usize = SYS_CLASS_FILE | 118;
36 pub const SYS_FTRUNCATE: usize =SYS_CLASS_FILE | 93;
37 pub const SYS_FUTIMENS: usize = SYS_CLASS_FILE | SYS_ARG_SLICE | 320;
38
39 pub const SYS_BRK: usize = 45;
40 pub const SYS_CHDIR: usize = 12;
41 pub const SYS_CLOCK_GETTIME: usize = 265;
42 pub const SYS_CLONE: usize = 120;
43 pub const SYS_EXIT: usize = 1;
44 pub const SYS_FUTEX: usize = 240;
45 pub const SYS_GETCWD: usize = 183;
46 pub const SYS_GETEGID: usize = 202;
47 pub const SYS_GETENS: usize = 951;
48 pub const SYS_GETEUID: usize = 201;
49 pub const SYS_GETGID: usize = 200;
50 pub const SYS_GETNS: usize = 950;
51 pub const SYS_GETPID: usize = 20;
52 pub const SYS_GETPGID: usize = 132;
53 pub const SYS_GETPPID: usize = 64;
54 pub const SYS_GETUID: usize = 199;
55 pub const SYS_IOPL: usize = 110;
56 pub const SYS_KILL: usize = 37;
57 pub const SYS_MPROTECT: usize = 125;
58 pub const SYS_MKNS: usize = 984;
59 pub const SYS_NANOSLEEP: usize =162;
60 pub const SYS_PHYSALLOC: usize =945;
61 pub const SYS_PHYSFREE: usize = 946;
62 pub const SYS_PHYSMAP: usize = 947;
63 pub const SYS_PHYSUNMAP: usize =948;
64 pub const SYS_VIRTTOPHYS: usize=949;
65 pub const SYS_PIPE2: usize = 331;
66 pub const SYS_SETPGID: usize = 57;
67 pub const SYS_SETREGID: usize = 204;
68 pub const SYS_SETRENS: usize = 952;
69 pub const SYS_SETREUID: usize = 203;
70 pub const SYS_SIGACTION: usize =67;
71 pub const SYS_SIGPROCMASK:usize=126;
72 pub const SYS_SIGRETURN: usize =119;
73 pub const SYS_UMASK: usize = 60;
74 pub const SYS_WAITPID: usize = 7;
75 pub const SYS_YIELD: usize = 158;
+0
-20
rust/vendor/redox_syscall/src/scheme/generate.sh less more
0 #!/usr/bin/env bash
1
2 set -e
3
4 echo "Generating SchemeMut from Scheme"
5 sed 's/trait Scheme/trait SchemeMut/' scheme.rs \
6 | sed 's/\&self/\&mut self/g' \
7 > scheme_mut.rs
8
9 echo "Generating SchemeBlock from Scheme"
10 sed 's/trait Scheme/trait SchemeBlock/' scheme.rs \
11 | sed 's/fn handle(\&self, packet: \&mut Packet)/fn handle(\&self, packet: \&Packet) -> Option<usize>/' \
12 | sed 's/packet.a = Error::mux(res);/res.transpose().map(Error::mux)/' \
13 | sed 's/Result<usize>/Result<Option<usize>>/g' \
14 > scheme_block.rs
15
16 echo "Generating SchemeBlockMut from SchemeBlock"
17 sed 's/trait SchemeBlock/trait SchemeBlockMut/' scheme_block.rs \
18 | sed 's/\&self/\&mut self/g' \
19 > scheme_block_mut.rs
+0
-9
rust/vendor/redox_syscall/src/scheme/mod.rs less more
0 pub use self::scheme::Scheme;
1 pub use self::scheme_mut::SchemeMut;
2 pub use self::scheme_block::SchemeBlock;
3 pub use self::scheme_block_mut::SchemeBlockMut;
4
5 mod scheme;
6 mod scheme_mut;
7 mod scheme_block;
8 mod scheme_block_mut;
+0
-167
rust/vendor/redox_syscall/src/scheme/scheme.rs less more
0 use core::{mem, slice};
1
2 use data::*;
3 use error::*;
4 use number::*;
5
6 pub trait Scheme {
7 fn handle(&self, packet: &mut Packet) {
8 let res = match packet.a {
9 SYS_OPEN => self.open(unsafe { slice::from_raw_parts(packet.b as *const u8, packet.c) }, packet.d, packet.uid, packet.gid),
10 SYS_CHMOD => self.chmod(unsafe { slice::from_raw_parts(packet.b as *const u8, packet.c) }, packet.d as u16, packet.uid, packet.gid),
11 SYS_RMDIR => self.rmdir(unsafe { slice::from_raw_parts(packet.b as *const u8, packet.c) }, packet.uid, packet.gid),
12 SYS_UNLINK => self.unlink(unsafe { slice::from_raw_parts(packet.b as *const u8, packet.c) }, packet.uid, packet.gid),
13
14 SYS_DUP => self.dup(packet.b, unsafe { slice::from_raw_parts(packet.c as *const u8, packet.d) }),
15 SYS_READ => self.read(packet.b, unsafe { slice::from_raw_parts_mut(packet.c as *mut u8, packet.d) }),
16 SYS_WRITE => self.write(packet.b, unsafe { slice::from_raw_parts(packet.c as *const u8, packet.d) }),
17 SYS_LSEEK => self.seek(packet.b, packet.c, packet.d),
18 SYS_FCHMOD => self.fchmod(packet.b, packet.c as u16),
19 SYS_FCHOWN => self.fchown(packet.b, packet.c as u32, packet.d as u32),
20 SYS_FCNTL => self.fcntl(packet.b, packet.c, packet.d),
21 SYS_FEVENT => self.fevent(packet.b, packet.c),
22 SYS_FMAP => if packet.d >= mem::size_of::<Map>() {
23 self.fmap(packet.b, unsafe { &*(packet.c as *const Map) })
24 } else {
25 Err(Error::new(EFAULT))
26 },
27 SYS_FUNMAP => self.funmap(packet.b),
28 SYS_FPATH => self.fpath(packet.b, unsafe { slice::from_raw_parts_mut(packet.c as *mut u8, packet.d) }),
29 SYS_FRENAME => self.frename(packet.b, unsafe { slice::from_raw_parts(packet.c as *const u8, packet.d) }, packet.uid, packet.gid),
30 SYS_FSTAT => if packet.d >= mem::size_of::<Stat>() {
31 self.fstat(packet.b, unsafe { &mut *(packet.c as *mut Stat) })
32 } else {
33 Err(Error::new(EFAULT))
34 },
35 SYS_FSTATVFS => if packet.d >= mem::size_of::<StatVfs>() {
36 self.fstatvfs(packet.b, unsafe { &mut *(packet.c as *mut StatVfs) })
37 } else {
38 Err(Error::new(EFAULT))
39 },
40 SYS_FSYNC => self.fsync(packet.b),
41 SYS_FTRUNCATE => self.ftruncate(packet.b, packet.c),
42 SYS_FUTIMENS => if packet.d >= mem::size_of::<TimeSpec>() {
43 self.futimens(packet.b, unsafe { slice::from_raw_parts(packet.c as *const TimeSpec, packet.d / mem::size_of::<TimeSpec>()) })
44 } else {
45 Err(Error::new(EFAULT))
46 },
47 SYS_CLOSE => self.close(packet.b),
48 _ => Err(Error::new(ENOSYS))
49 };
50
51 packet.a = Error::mux(res);
52 }
53
54 /* Scheme operations */
55
56 #[allow(unused_variables)]
57 fn open(&self, path: &[u8], flags: usize, uid: u32, gid: u32) -> Result<usize> {
58 Err(Error::new(ENOENT))
59 }
60
61 #[allow(unused_variables)]
62 fn chmod(&self, path: &[u8], mode: u16, uid: u32, gid: u32) -> Result<usize> {
63 Err(Error::new(ENOENT))
64 }
65
66 #[allow(unused_variables)]
67 fn rmdir(&self, path: &[u8], uid: u32, gid: u32) -> Result<usize> {
68 Err(Error::new(ENOENT))
69 }
70
71 #[allow(unused_variables)]
72 fn unlink(&self, path: &[u8], uid: u32, gid: u32) -> Result<usize> {
73 Err(Error::new(ENOENT))
74 }
75
76 /* Resource operations */
77 #[allow(unused_variables)]
78 fn dup(&self, old_id: usize, buf: &[u8]) -> Result<usize> {
79 Err(Error::new(EBADF))
80 }
81
82 #[allow(unused_variables)]
83 fn read(&self, id: usize, buf: &mut [u8]) -> Result<usize> {
84 Err(Error::new(EBADF))
85 }
86
87 #[allow(unused_variables)]
88 fn write(&self, id: usize, buf: &[u8]) -> Result<usize> {
89 Err(Error::new(EBADF))
90 }
91
92 #[allow(unused_variables)]
93 fn seek(&self, id: usize, pos: usize, whence: usize) -> Result<usize> {
94 Err(Error::new(EBADF))
95 }
96
97 #[allow(unused_variables)]
98 fn fchmod(&self, id: usize, mode: u16) -> Result<usize> {
99 Err(Error::new(EBADF))
100 }
101
102 #[allow(unused_variables)]
103 fn fchown(&self, id: usize, uid: u32, gid: u32) -> Result<usize> {
104 Err(Error::new(EBADF))
105 }
106
107 #[allow(unused_variables)]
108 fn fcntl(&self, id: usize, cmd: usize, arg: usize) -> Result<usize> {
109 Err(Error::new(EBADF))
110 }
111
112 #[allow(unused_variables)]
113 fn fevent(&self, id: usize, flags: usize) -> Result<usize> {
114 Err(Error::new(EBADF))
115 }
116
117 #[allow(unused_variables)]
118 fn fmap(&self, id: usize, map: &Map) -> Result<usize> {
119 Err(Error::new(EBADF))
120 }
121
122 #[allow(unused_variables)]
123 fn funmap(&self, address: usize) -> Result<usize> {
124 Err(Error::new(EBADF))
125 }
126
127 #[allow(unused_variables)]
128 fn fpath(&self, id: usize, buf: &mut [u8]) -> Result<usize> {
129 Err(Error::new(EBADF))
130 }
131
132 #[allow(unused_variables)]
133 fn frename(&self, id: usize, path: &[u8], uid: u32, gid: u32) -> Result<usize> {
134 Err(Error::new(EBADF))
135 }
136
137 #[allow(unused_variables)]
138 fn fstat(&self, id: usize, stat: &mut Stat) -> Result<usize> {
139 Err(Error::new(EBADF))
140 }
141
142 #[allow(unused_variables)]
143 fn fstatvfs(&self, id: usize, stat: &mut StatVfs) -> Result<usize> {
144 Err(Error::new(EBADF))
145 }
146
147 #[allow(unused_variables)]
148 fn fsync(&self, id: usize) -> Result<usize> {
149 Err(Error::new(EBADF))
150 }
151
152 #[allow(unused_variables)]
153 fn ftruncate(&self, id: usize, len: usize) -> Result<usize> {
154 Err(Error::new(EBADF))
155 }
156
157 #[allow(unused_variables)]
158 fn futimens(&self, id: usize, times: &[TimeSpec]) -> Result<usize> {
159 Err(Error::new(EBADF))
160 }
161
162 #[allow(unused_variables)]
163 fn close(&self, id: usize) -> Result<usize> {
164 Err(Error::new(EBADF))
165 }
166 }
+0
-167
rust/vendor/redox_syscall/src/scheme/scheme_block.rs less more
0 use core::{mem, slice};
1
2 use data::*;
3 use error::*;
4 use number::*;
5
6 pub trait SchemeBlock {
7 fn handle(&self, packet: &Packet) -> Option<usize> {
8 let res = match packet.a {
9 SYS_OPEN => self.open(unsafe { slice::from_raw_parts(packet.b as *const u8, packet.c) }, packet.d, packet.uid, packet.gid),
10 SYS_CHMOD => self.chmod(unsafe { slice::from_raw_parts(packet.b as *const u8, packet.c) }, packet.d as u16, packet.uid, packet.gid),
11 SYS_RMDIR => self.rmdir(unsafe { slice::from_raw_parts(packet.b as *const u8, packet.c) }, packet.uid, packet.gid),
12 SYS_UNLINK => self.unlink(unsafe { slice::from_raw_parts(packet.b as *const u8, packet.c) }, packet.uid, packet.gid),
13
14 SYS_DUP => self.dup(packet.b, unsafe { slice::from_raw_parts(packet.c as *const u8, packet.d) }),
15 SYS_READ => self.read(packet.b, unsafe { slice::from_raw_parts_mut(packet.c as *mut u8, packet.d) }),
16 SYS_WRITE => self.write(packet.b, unsafe { slice::from_raw_parts(packet.c as *const u8, packet.d) }),
17 SYS_LSEEK => self.seek(packet.b, packet.c, packet.d),
18 SYS_FCHMOD => self.fchmod(packet.b, packet.c as u16),
19 SYS_FCHOWN => self.fchown(packet.b, packet.c as u32, packet.d as u32),
20 SYS_FCNTL => self.fcntl(packet.b, packet.c, packet.d),
21 SYS_FEVENT => self.fevent(packet.b, packet.c),
22 SYS_FMAP => if packet.d >= mem::size_of::<Map>() {
23 self.fmap(packet.b, unsafe { &*(packet.c as *const Map) })
24 } else {
25 Err(Error::new(EFAULT))
26 },
27 SYS_FUNMAP => self.funmap(packet.b),
28 SYS_FPATH => self.fpath(packet.b, unsafe { slice::from_raw_parts_mut(packet.c as *mut u8, packet.d) }),
29 SYS_FRENAME => self.frename(packet.b, unsafe { slice::from_raw_parts(packet.c as *const u8, packet.d) }, packet.uid, packet.gid),
30 SYS_FSTAT => if packet.d >= mem::size_of::<Stat>() {
31 self.fstat(packet.b, unsafe { &mut *(packet.c as *mut Stat) })
32 } else {
33 Err(Error::new(EFAULT))
34 },
35 SYS_FSTATVFS => if packet.d >= mem::size_of::<StatVfs>() {
36 self.fstatvfs(packet.b, unsafe { &mut *(packet.c as *mut StatVfs) })
37 } else {
38 Err(Error::new(EFAULT))
39 },
40 SYS_FSYNC => self.fsync(packet.b),
41 SYS_FTRUNCATE => self.ftruncate(packet.b, packet.c),
42 SYS_FUTIMENS => if packet.d >= mem::size_of::<TimeSpec>() {
43 self.futimens(packet.b, unsafe { slice::from_raw_parts(packet.c as *const TimeSpec, packet.d / mem::size_of::<TimeSpec>()) })
44 } else {
45 Err(Error::new(EFAULT))
46 },
47 SYS_CLOSE => self.close(packet.b),
48 _ => Err(Error::new(ENOSYS))
49 };
50
51 res.transpose().map(Error::mux)
52 }
53
54 /* Scheme operations */
55
56 #[allow(unused_variables)]
57 fn open(&self, path: &[u8], flags: usize, uid: u32, gid: u32) -> Result<Option<usize>> {
58 Err(Error::new(ENOENT))
59 }
60
61 #[allow(unused_variables)]
62 fn chmod(&self, path: &[u8], mode: u16, uid: u32, gid: u32) -> Result<Option<usize>> {
63 Err(Error::new(ENOENT))
64 }
65
66 #[allow(unused_variables)]
67 fn rmdir(&self, path: &[u8], uid: u32, gid: u32) -> Result<Option<usize>> {
68 Err(Error::new(ENOENT))
69 }
70
71 #[allow(unused_variables)]
72 fn unlink(&self, path: &[u8], uid: u32, gid: u32) -> Result<Option<usize>> {
73 Err(Error::new(ENOENT))
74 }
75
76 /* Resource operations */
77 #[allow(unused_variables)]
78 fn dup(&self, old_id: usize, buf: &[u8]) -> Result<Option<usize>> {
79 Err(Error::new(EBADF))
80 }
81
82 #[allow(unused_variables)]
83 fn read(&self, id: usize, buf: &mut [u8]) -> Result<Option<usize>> {
84 Err(Error::new(EBADF))
85 }
86
87 #[allow(unused_variables)]
88 fn write(&self, id: usize, buf: &[u8]) -> Result<Option<usize>> {
89 Err(Error::new(EBADF))
90 }
91
92 #[allow(unused_variables)]
93 fn seek(&self, id: usize, pos: usize, whence: usize) -> Result<Option<usize>> {
94 Err(Error::new(EBADF))
95 }
96
97 #[allow(unused_variables)]
98 fn fchmod(&self, id: usize, mode: u16) -> Result<Option<usize>> {
99 Err(Error::new(EBADF))
100 }
101
102 #[allow(unused_variables)]
103 fn fchown(&self, id: usize, uid: u32, gid: u32) -> Result<Option<usize>> {
104 Err(Error::new(EBADF))
105 }
106
107 #[allow(unused_variables)]
108 fn fcntl(&self, id: usize, cmd: usize, arg: usize) -> Result<Option<usize>> {
109 Err(Error::new(EBADF))
110 }
111
112 #[allow(unused_variables)]
113 fn fevent(&self, id: usize, flags: usize) -> Result<Option<usize>> {
114 Err(Error::new(EBADF))
115 }
116
117 #[allow(unused_variables)]
118 fn fmap(&self, id: usize, map: &Map) -> Result<Option<usize>> {
119 Err(Error::new(EBADF))
120 }
121
122 #[allow(unused_variables)]
123 fn funmap(&self, address: usize) -> Result<Option<usize>> {
124 Err(Error::new(EBADF))
125 }
126
127 #[allow(unused_variables)]
128 fn fpath(&self, id: usize, buf: &mut [u8]) -> Result<Option<usize>> {
129 Err(Error::new(EBADF))
130 }
131
132 #[allow(unused_variables)]
133 fn frename(&self, id: usize, path: &[u8], uid: u32, gid: u32) -> Result<Option<usize>> {
134 Err(Error::new(EBADF))
135 }
136
137 #[allow(unused_variables)]
138 fn fstat(&self, id: usize, stat: &mut Stat) -> Result<Option<usize>> {
139 Err(Error::new(EBADF))
140 }
141
142 #[allow(unused_variables)]
143 fn fstatvfs(&self, id: usize, stat: &mut StatVfs) -> Result<Option<usize>> {
144 Err(Error::new(EBADF))
145 }
146
147 #[allow(unused_variables)]
148 fn fsync(&self, id: usize) -> Result<Option<usize>> {
149 Err(Error::new(EBADF))
150 }
151
152 #[allow(unused_variables)]
153 fn ftruncate(&self, id: usize, len: usize) -> Result<Option<usize>> {
154 Err(Error::new(EBADF))
155 }
156
157 #[allow(unused_variables)]
158 fn futimens(&self, id: usize, times: &[TimeSpec]) -> Result<Option<usize>> {
159 Err(Error::new(EBADF))
160 }
161
162 #[allow(unused_variables)]
163 fn close(&self, id: usize) -> Result<Option<usize>> {
164 Err(Error::new(EBADF))
165 }
166 }
+0
-167
rust/vendor/redox_syscall/src/scheme/scheme_block_mut.rs less more
0 use core::{mem, slice};
1
2 use data::*;
3 use error::*;
4 use number::*;
5
6 pub trait SchemeBlockMut {
7 fn handle(&mut self, packet: &Packet) -> Option<usize> {
8 let res = match packet.a {
9 SYS_OPEN => self.open(unsafe { slice::from_raw_parts(packet.b as *const u8, packet.c) }, packet.d, packet.uid, packet.gid),
10 SYS_CHMOD => self.chmod(unsafe { slice::from_raw_parts(packet.b as *const u8, packet.c) }, packet.d as u16, packet.uid, packet.gid),
11 SYS_RMDIR => self.rmdir(unsafe { slice::from_raw_parts(packet.b as *const u8, packet.c) }, packet.uid, packet.gid),
12 SYS_UNLINK => self.unlink(unsafe { slice::from_raw_parts(packet.b as *const u8, packet.c) }, packet.uid, packet.gid),
13
14 SYS_DUP => self.dup(packet.b, unsafe { slice::from_raw_parts(packet.c as *const u8, packet.d) }),
15 SYS_READ => self.read(packet.b, unsafe { slice::from_raw_parts_mut(packet.c as *mut u8, packet.d) }),
16 SYS_WRITE => self.write(packet.b, unsafe { slice::from_raw_parts(packet.c as *const u8, packet.d) }),
17 SYS_LSEEK => self.seek(packet.b, packet.c, packet.d),
18 SYS_FCHMOD => self.fchmod(packet.b, packet.c as u16),
19 SYS_FCHOWN => self.fchown(packet.b, packet.c as u32, packet.d as u32),
20 SYS_FCNTL => self.fcntl(packet.b, packet.c, packet.d),
21 SYS_FEVENT => self.fevent(packet.b, packet.c),
22 SYS_FMAP => if packet.d >= mem::size_of::<Map>() {
23 self.fmap(packet.b, unsafe { &*(packet.c as *const Map) })
24 } else {
25 Err(Error::new(EFAULT))
26 },
27 SYS_FUNMAP => self.funmap(packet.b),
28 SYS_FPATH => self.fpath(packet.b, unsafe { slice::from_raw_parts_mut(packet.c as *mut u8, packet.d) }),
29 SYS_FRENAME => self.frename(packet.b, unsafe { slice::from_raw_parts(packet.c as *const u8, packet.d) }, packet.uid, packet.gid),
30 SYS_FSTAT => if packet.d >= mem::size_of::<Stat>() {
31 self.fstat(packet.b, unsafe { &mut *(packet.c as *mut Stat) })
32 } else {
33 Err(Error::new(EFAULT))
34 },
35 SYS_FSTATVFS => if packet.d >= mem::size_of::<StatVfs>() {
36 self.fstatvfs(packet.b, unsafe { &mut *(packet.c as *mut StatVfs) })
37 } else {
38 Err(Error::new(EFAULT))
39 },
40 SYS_FSYNC => self.fsync(packet.b),
41 SYS_FTRUNCATE => self.ftruncate(packet.b, packet.c),
42 SYS_FUTIMENS => if packet.d >= mem::size_of::<TimeSpec>() {
43 self.futimens(packet.b, unsafe { slice::from_raw_parts(packet.c as *const TimeSpec, packet.d / mem::size_of::<TimeSpec>()) })
44 } else {
45 Err(Error::new(EFAULT))
46 },
47 SYS_CLOSE => self.close(packet.b),
48 _ => Err(Error::new(ENOSYS))
49 };
50
51 res.transpose().map(Error::mux)
52 }
53
54 /* Scheme operations */
55
56 #[allow(unused_variables)]
57 fn open(&mut self, path: &[u8], flags: usize, uid: u32, gid: u32) -> Result<Option<usize>> {
58 Err(Error::new(ENOENT))
59 }
60
61 #[allow(unused_variables)]
62 fn chmod(&mut self, path: &[u8], mode: u16, uid: u32, gid: u32) -> Result<Option<usize>> {
63 Err(Error::new(ENOENT))
64 }
65
66 #[allow(unused_variables)]
67 fn rmdir(&mut self, path: &[u8], uid: u32, gid: u32) -> Result<Option<usize>> {
68 Err(Error::new(ENOENT))
69 }
70
71 #[allow(unused_variables)]
72 fn unlink(&mut self, path: &[u8], uid: u32, gid: u32) -> Result<Option<usize>> {
73 Err(Error::new(ENOENT))
74 }
75
76 /* Resource operations */
77 #[allow(unused_variables)]
78 fn dup(&mut self, old_id: usize, buf: &[u8]) -> Result<Option<usize>> {
79 Err(Error::new(EBADF))
80 }
81
82 #[allow(unused_variables)]
83 fn read(&mut self, id: usize, buf: &mut [u8]) -> Result<Option<usize>> {
84 Err(Error::new(EBADF))
85 }
86
87 #[allow(unused_variables)]
88 fn write(&mut self, id: usize, buf: &[u8]) -> Result<Option<usize>> {
89 Err(Error::new(EBADF))
90 }
91
92 #[allow(unused_variables)]
93 fn seek(&mut self, id: usize, pos: usize, whence: usize) -> Result<Option<usize>> {
94 Err(Error::new(EBADF))
95 }
96
97 #[allow(unused_variables)]
98 fn fchmod(&mut self, id: usize, mode: u16) -> Result<Option<usize>> {
99 Err(Error::new(EBADF))
100 }
101
102 #[allow(unused_variables)]
103 fn fchown(&mut self, id: usize, uid: u32, gid: u32) -> Result<Option<usize>> {
104 Err(Error::new(EBADF))
105 }
106
107 #[allow(unused_variables)]
108 fn fcntl(&mut self, id: usize, cmd: usize, arg: usize) -> Result<Option<usize>> {
109 Err(Error::new(EBADF))
110 }
111
112 #[allow(unused_variables)]
113 fn fevent(&mut self, id: usize, flags: usize) -> Result<Option<usize>> {
114 Err(Error::new(EBADF))
115 }
116
117 #[allow(unused_variables)]
118 fn fmap(&mut self, id: usize, map: &Map) -> Result<Option<usize>> {
119 Err(Error::new(EBADF))
120 }
121
122 #[allow(unused_variables)]
123 fn funmap(&mut self, address: usize) -> Result<Option<usize>> {
124 Err(Error::new(EBADF))
125 }
126
127 #[allow(unused_variables)]
128 fn fpath(&mut self, id: usize, buf: &mut [u8]) -> Result<Option<usize>> {
129 Err(Error::new(EBADF))
130 }
131
132 #[allow(unused_variables)]
133 fn frename(&mut self, id: usize, path: &[u8], uid: u32, gid: u32) -> Result<Option<usize>> {
134 Err(Error::new(EBADF))
135 }
136
137 #[allow(unused_variables)]
138 fn fstat(&mut self, id: usize, stat: &mut Stat) -> Result<Option<usize>> {
139 Err(Error::new(EBADF))
140 }
141
142 #[allow(unused_variables)]
143 fn fstatvfs(&mut self, id: usize, stat: &mut StatVfs) -> Result<Option<usize>> {
144 Err(Error::new(EBADF))
145 }
146
147 #[allow(unused_variables)]
148 fn fsync(&mut self, id: usize) -> Result<Option<usize>> {
149 Err(Error::new(EBADF))
150 }
151
152 #[allow(unused_variables)]
153 fn ftruncate(&mut self, id: usize, len: usize) -> Result<Option<usize>> {
154 Err(Error::new(EBADF))
155 }
156
157 #[allow(unused_variables)]
158 fn futimens(&mut self, id: usize, times: &[TimeSpec]) -> Result<Option<usize>> {
159 Err(Error::new(EBADF))
160 }
161
162 #[allow(unused_variables)]
163 fn close(&mut self, id: usize) -> Result<Option<usize>> {
164 Err(Error::new(EBADF))
165 }
166 }
+0
-167
rust/vendor/redox_syscall/src/scheme/scheme_mut.rs less more
0 use core::{mem, slice};
1
2 use data::*;
3 use error::*;
4 use number::*;
5
6 pub trait SchemeMut {
7 fn handle(&mut self, packet: &mut Packet) {
8 let res = match packet.a {
9 SYS_OPEN => self.open(unsafe { slice::from_raw_parts(packet.b as *const u8, packet.c) }, packet.d, packet.uid, packet.gid),
10 SYS_CHMOD => self.chmod(unsafe { slice::from_raw_parts(packet.b as *const u8, packet.c) }, packet.d as u16, packet.uid, packet.gid),
11 SYS_RMDIR => self.rmdir(unsafe { slice::from_raw_parts(packet.b as *const u8, packet.c) }, packet.uid, packet.gid),
12 SYS_UNLINK => self.unlink(unsafe { slice::from_raw_parts(packet.b as *const u8, packet.c) }, packet.uid, packet.gid),
13
14 SYS_DUP => self.dup(packet.b, unsafe { slice::from_raw_parts(packet.c as *const u8, packet.d) }),
15 SYS_READ => self.read(packet.b, unsafe { slice::from_raw_parts_mut(packet.c as *mut u8, packet.d) }),
16 SYS_WRITE => self.write(packet.b, unsafe { slice::from_raw_parts(packet.c as *const u8, packet.d) }),
17 SYS_LSEEK => self.seek(packet.b, packet.c, packet.d),
18 SYS_FCHMOD => self.fchmod(packet.b, packet.c as u16),
19 SYS_FCHOWN => self.fchown(packet.b, packet.c as u32, packet.d as u32),
20 SYS_FCNTL => self.fcntl(packet.b, packet.c, packet.d),
21 SYS_FEVENT => self.fevent(packet.b, packet.c),
22 SYS_FMAP => if packet.d >= mem::size_of::<Map>() {
23 self.fmap(packet.b, unsafe { &*(packet.c as *const Map) })
24 } else {
25 Err(Error::new(EFAULT))
26 },
27 SYS_FUNMAP => self.funmap(packet.b),
28 SYS_FPATH => self.fpath(packet.b, unsafe { slice::from_raw_parts_mut(packet.c as *mut u8, packet.d) }),
29 SYS_FRENAME => self.frename(packet.b, unsafe { slice::from_raw_parts(packet.c as *const u8, packet.d) }, packet.uid, packet.gid),
30 SYS_FSTAT => if packet.d >= mem::size_of::<Stat>() {
31 self.fstat(packet.b, unsafe { &mut *(packet.c as *mut Stat) })
32 } else {
33 Err(Error::new(EFAULT))
34 },
35 SYS_FSTATVFS => if packet.d >= mem::size_of::<StatVfs>() {
36 self.fstatvfs(packet.b, unsafe { &mut *(packet.c as *mut StatVfs) })
37 } else {
38 Err(Error::new(EFAULT))
39 },
40 SYS_FSYNC => self.fsync(packet.b),
41 SYS_FTRUNCATE => self.ftruncate(packet.b, packet.c),
42 SYS_FUTIMENS => if packet.d >= mem::size_of::<TimeSpec>() {
43 self.futimens(packet.b, unsafe { slice::from_raw_parts(packet.c as *const TimeSpec, packet.d / mem::size_of::<TimeSpec>()) })
44 } else {
45 Err(Error::new(EFAULT))
46 },
47 SYS_CLOSE => self.close(packet.b),
48 _ => Err(Error::new(ENOSYS))
49 };
50
51 packet.a = Error::mux(res);
52 }
53
54 /* Scheme operations */
55
56 #[allow(unused_variables)]
57 fn open(&mut self, path: &[u8], flags: usize, uid: u32, gid: u32) -> Result<usize> {
58 Err(Error::new(ENOENT))
59 }
60
61 #[allow(unused_variables)]
62 fn chmod(&mut self, path: &[u8], mode: u16, uid: u32, gid: u32) -> Result<usize> {
63 Err(Error::new(ENOENT))
64 }
65
66 #[allow(unused_variables)]
67 fn rmdir(&mut self, path: &[u8], uid: u32, gid: u32) -> Result<usize> {
68 Err(Error::new(ENOENT))
69 }
70
71 #[allow(unused_variables)]
72 fn unlink(&mut self, path: &[u8], uid: u32, gid: u32) -> Result<usize> {
73 Err(Error::new(ENOENT))
74 }
75
76 /* Resource operations */
77 #[allow(unused_variables)]
78 fn dup(&mut self, old_id: usize, buf: &[u8]) -> Result<usize> {
79 Err(Error::new(EBADF))
80 }
81
82 #[allow(unused_variables)]
83 fn read(&mut self, id: usize, buf: &mut [u8]) -> Result<usize> {
84 Err(Error::new(EBADF))
85 }
86
87 #[allow(unused_variables)]
88 fn write(&mut self, id: usize, buf: &[u8]) -> Result<usize> {
89 Err(Error::new(EBADF))
90 }
91
92 #[allow(unused_variables)]
93 fn seek(&mut self, id: usize, pos: usize, whence: usize) -> Result<usize> {
94 Err(Error::new(EBADF))
95 }
96
97 #[allow(unused_variables)]
98 fn fchmod(&mut self, id: usize, mode: u16) -> Result<usize> {
99 Err(Error::new(EBADF))
100 }
101
102 #[allow(unused_variables)]
103 fn fchown(&mut self, id: usize, uid: u32, gid: u32) -> Result<usize> {
104 Err(Error::new(EBADF))
105 }
106
107 #[allow(unused_variables)]
108 fn fcntl(&mut self, id: usize, cmd: usize, arg: usize) -> Result<usize> {
109 Err(Error::new(EBADF))
110 }
111
112 #[allow(unused_variables)]
113 fn fevent(&mut self, id: usize, flags: usize) -> Result<usize> {
114 Err(Error::new(EBADF))
115 }
116
117 #[allow(unused_variables)]
118 fn fmap(&mut self, id: usize, map: &Map) -> Result<usize> {
119 Err(Error::new(EBADF))
120 }
121
122 #[allow(unused_variables)]
123 fn funmap(&mut self, address: usize) -> Result<usize> {
124 Err(Error::new(EBADF))
125 }
126
127 #[allow(unused_variables)]
128 fn fpath(&mut self, id: usize, buf: &mut [u8]) -> Result<usize> {
129 Err(Error::new(EBADF))
130 }
131
132 #[allow(unused_variables)]
133 fn frename(&mut self, id: usize, path: &[u8], uid: u32, gid: u32) -> Result<usize> {
134 Err(Error::new(EBADF))
135 }
136
137 #[allow(unused_variables)]
138 fn fstat(&mut self, id: usize, stat: &mut Stat) -> Result<usize> {
139 Err(Error::new(EBADF))
140 }
141
142 #[allow(unused_variables)]
143 fn fstatvfs(&mut self, id: usize, stat: &mut StatVfs) -> Result<usize> {
144 Err(Error::new(EBADF))
145 }
146
147 #[allow(unused_variables)]
148 fn fsync(&mut self, id: usize) -> Result<usize> {
149 Err(Error::new(EBADF))
150 }
151
152 #[allow(unused_variables)]
153 fn ftruncate(&mut self, id: usize, len: usize) -> Result<usize> {
154 Err(Error::new(EBADF))
155 }
156
157 #[allow(unused_variables)]
158 fn futimens(&mut self, id: usize, times: &[TimeSpec]) -> Result<usize> {
159 Err(Error::new(EBADF))
160 }
161
162 #[allow(unused_variables)]
163 fn close(&mut self, id: usize) -> Result<usize> {
164 Err(Error::new(EBADF))
165 }
166 }
+0
-129
rust/vendor/redox_syscall/src/tests.rs less more
0 #[test]
1 fn brk() {
2 unsafe {
3 let start = dbg!(crate::brk(0)).unwrap();
4 let end = start + 4 * 1024 * 1024;
5 assert_eq!(dbg!(crate::brk(end)), Ok(end));
6 }
7 }
8
9 #[test]
10 fn chdir() {
11 //TODO: Verify CWD
12 assert_eq!(dbg!(crate::chdir("file:/")), Ok(0));
13 assert_eq!(dbg!(crate::chdir("file:/root")), Ok(0));
14 }
15
16 //TODO: chmod
17
18 #[test]
19 fn clone() {
20 let expected_status = 42;
21 let pid_res = unsafe { crate::clone(0) };
22 if pid_res == Ok(0) {
23 crate::exit(expected_status).unwrap();
24 panic!("failed to exit");
25 } else {
26 let pid = dbg!(pid_res).unwrap();
27 let mut status = 0;
28 assert_eq!(dbg!(crate::waitpid(pid, &mut status, 0)), Ok(pid));
29 assert_eq!(dbg!(crate::wifexited(status)), true);
30 assert_eq!(dbg!(crate::wexitstatus(status)), expected_status);
31 }
32 }
33
34 //TODO: close
35
36 #[test]
37 fn clock_gettime() {
38 let mut tp = crate::TimeSpec::default();
39 assert_eq!(dbg!(
40 crate::clock_gettime(crate::CLOCK_MONOTONIC, &mut tp)
41 ), Ok(0));
42 assert_ne!(dbg!(tp), crate::TimeSpec::default());
43
44 tp = crate::TimeSpec::default();
45 assert_eq!(dbg!(
46 crate::clock_gettime(crate::CLOCK_REALTIME, &mut tp)
47 ), Ok(0));
48 assert_ne!(dbg!(tp), crate::TimeSpec::default());
49 }
50
51 //TODO: dup
52
53 //TODO: dup2
54
55 //TODO: exit (handled by clone?)
56
57 //TODO: fchmod
58
59 //TODO: fcntl
60
61 #[test]
62 fn fexec() {
63 let name = "/bin/ls";
64
65 let fd = dbg!(
66 crate::open(name, crate::O_RDONLY | crate::O_CLOEXEC)
67 ).unwrap();
68
69 let args = &[
70 [name.as_ptr() as usize, name.len()]
71 ];
72
73 let vars = &[];
74
75 let pid_res = unsafe { crate::clone(0) };
76 if pid_res == Ok(0) {
77 crate::fexec(fd, args, vars).unwrap();
78 panic!("failed to fexec");
79 } else {
80 assert_eq!(dbg!(crate::close(fd)), Ok(0));
81
82 let pid = dbg!(pid_res).unwrap();
83 let mut status = 0;
84 assert_eq!(dbg!(crate::waitpid(pid, &mut status, 0)), Ok(pid));
85 assert_eq!(dbg!(crate::wifexited(status)), true);
86 assert_eq!(dbg!(crate::wexitstatus(status)), 0);
87 }
88 }
89
90 #[test]
91 fn fmap() {
92 use std::slice;
93
94 let fd = dbg!(
95 crate::open(
96 "/tmp/syscall-tests-fmap",
97 crate::O_CREAT | crate::O_RDWR | crate::O_CLOEXEC
98 )
99 ).unwrap();
100
101 let map = unsafe {
102 slice::from_raw_parts_mut(
103 dbg!(
104 crate::fmap(fd, &crate::Map {
105 offset: 0,
106 size: 128,
107 flags: crate::PROT_READ | crate::PROT_WRITE
108 })
109 ).unwrap() as *mut u8,
110 128
111 )
112 };
113
114 // Maps should be available after closing
115 assert_eq!(dbg!(crate::close(fd)), Ok(0));
116
117 for i in 0..128 {
118 map[i as usize] = i;
119 assert_eq!(map[i as usize], i);
120 }
121
122 //TODO: add msync
123 unsafe {
124 assert_eq!(dbg!(
125 crate::funmap(map.as_mut_ptr() as usize)
126 ), Ok(0));
127 }
128 }
0 {"files":{"Cargo.toml":"c3302c69e6aac4b0578e36115e2cf66e1e97bf6d8650e7de6e524441f8b38500","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"6485b8ed310d3f0340bf1ad1f47645069ce4069dcc6bb46c7d5c6faf41de1fdb","README.md":"2c17f942c4a797f6f491c6d40570f904f35047531884ded3244438832b3d6f0a","appveyor.yml":"da991211b72fa6f231af7adb84c9fb72f5a9131d1c0a3d47b8ceffe5a82c8542","benches/precise_time_ns.rs":"06206c16764c6cef71da645ddb1aa7476dff7697e38d0742b3c907be9f00dadf","src/display.rs":"b79a81b4f068e44934ad3398ba0259120cc30cf0855ac5108c4569e320fd7f1d","src/duration.rs":"a3661c6618316f2999a7eca53e0da2d06e0a12b6ab990650a68b0d4d094e5f69","src/lib.rs":"964e46bf4b351f1bca3ef8357696ad21355e6bf9bd31f197299f6785ac02a0b4","src/parse.rs":"717ae5735dfdaaba513f2a54a179e73bb2a48f8d4fb8787740d4662d6ff3389c","src/sys.rs":"4f6bc5c6300c2d49da7d21615152872e16d53c0f02540824f48c45edd4d3140f"},"package":"db8dcfca086c1143c9270ac42a2bbd8a7ee477b78ac8e45b19abfb0cbede4b6f"}
0 {"files":{"Cargo.toml":"ddebccd9128093c3fdf84b4f6a131fe634c85e8fc2059afed9ea30e02fe22c58","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"6485b8ed310d3f0340bf1ad1f47645069ce4069dcc6bb46c7d5c6faf41de1fdb","README.md":"35b591c7481ec3ae59210fa4f9b7cecb1b16e632bfd6193b032239e74f9bfdb8","src/display.rs":"52d16abaa37b3ab577747c7d9d2ed6ded1b126458e980dc3e1a571fa6e1f9fda","src/duration.rs":"c706d392bdb7f65b23fcc20189a9a77c50b765b9c548e247238424ed6fb56a46","src/lib.rs":"720e380829cda276466bce34d6a29a2f7aec1f750e4b4522b217c57930380545","src/parse.rs":"65bd9142d8c15eb54a8d4db6e2c48bf1adbcc875953141c17e07ba58f356a027","src/sys.rs":"851994516ff29dd9f5749fa19b1db13b7afe484e4bd1d279b420fda7ed8404ab"},"package":"ca8a50ef2360fbd1eeb0ecd46795a87a19024eb4b53c5dc916ca1fd95fe62438"}
22 # When uploading crates to the registry Cargo will automatically
33 # "normalize" Cargo.toml files for maximal compatibility
44 # with all versions of Cargo and also rewrite `path` dependencies
5 # to registry (e.g. crates.io) dependencies
5 # to registry (e.g., crates.io) dependencies
66 #
77 # If you believe there's an error in this file please file an
88 # issue against the rust-lang/cargo repository. If you're
1111
1212 [package]
1313 name = "time"
14 version = "0.1.42"
14 version = "0.1.43"
1515 authors = ["The Rust Project Developers"]
16 exclude = [".github", "benches"]
1617 description = "Utilities for working with time-related functions in Rust.\n"
17 homepage = "https://github.com/rust-lang/time"
18 documentation = "https://doc.rust-lang.org/time"
18 homepage = "https://github.com/time-rs/time"
19 documentation = "https://docs.rs/time/~0.1"
20 readme = "README.md"
1921 license = "MIT/Apache-2.0"
20 repository = "https://github.com/rust-lang/time"
22 repository = "https://github.com/time-rs/time"
2123 [dependencies.libc]
22 version = "0.2.1"
24 version = "0.2.69"
2325
2426 [dependencies.rustc-serialize]
2527 version = "0.3"
3032 [dev-dependencies.winapi]
3133 version = "0.3.0"
3234 features = ["std", "processthreadsapi", "winbase"]
33 [target."cfg(target_os = \"redox\")".dependencies.redox_syscall]
34 version = "0.1"
3535 [target."cfg(windows)".dependencies.winapi]
3636 version = "0.3.0"
3737 features = ["std", "minwinbase", "minwindef", "ntdef", "profileapi", "sysinfoapi", "timezoneapi"]
38 [badges.appveyor]
39 repository = "alexcrichton/time"
40
41 [badges.travis-ci]
42 repository = "rust-lang-deprecated/time"
22
33 Utilities for working with time-related functions in Rust
44
5 [![Build Status](https://travis-ci.org/rust-lang-deprecated/time.svg?branch=master)](https://travis-ci.org/rust-lang-deprecated/time)
6 [![Build status](https://ci.appveyor.com/api/projects/status/55m7rbaj9a5v3ad7?svg=true)](https://ci.appveyor.com/project/alexcrichton/time)
5 [![build status](https://github.com/time-rs/time/workflows/Build/badge.svg?branch=v0.1)](https://github.com/time-rs/time/actions?query=branch%3Av0.1)
6 [![Documentation](https://docs.rs/time/badge.svg?version=0.1)](https://docs.rs/time/~0.1)
7 ![rustc 1.21.0](https://img.shields.io/badge/rustc-1.21.0-blue)
78
8 [Documentation](https://doc.rust-lang.org/time)
9 ## time v0.1.x is Deprecated
910
10 ## Notes
11 The 0.1.x series of this library is deprecated and in maintenance mode. No new
12 features will be added. Active development now occurs in the 0.2.x series.
1113
12 This library is no longer actively maintained, but bugfixes will be added ([details](https://github.com/rust-lang-deprecated/time/issues/136)).
13
14 In case you're looking for something a little fresher and more actively maintained have a look at the [`chrono`](https://github.com/lifthrasiir/rust-chrono) crate.
14 If you need additional functionality that this crate does not provide, check
15 out the [`chrono`](https://github.com/chronotope/chrono) crate.
1516
1617 ## Usage
1718
+0
-17
rust/vendor/time/appveyor.yml less more
0 environment:
1 matrix:
2 - TARGET: x86_64-pc-windows-msvc
3 - TARGET: i686-pc-windows-msvc
4 - TARGET: i686-pc-windows-gnu
5 install:
6 - ps: Start-FileDownload "https://static.rust-lang.org/dist/rust-nightly-${env:TARGET}.exe"
7 - rust-nightly-%TARGET%.exe /VERYSILENT /NORESTART /DIR="C:\Program Files (x86)\Rust"
8 - SET PATH=%PATH%;C:\Program Files (x86)\Rust\bin
9 - SET PATH=%PATH%;C:\MinGW\bin
10 - rustc -V
11 - cargo -V
12
13 build: false
14
15 test_script:
16 - cargo test --verbose
+0
-14
rust/vendor/time/benches/precise_time_ns.rs less more
0 #![feature(test)]
1
2 extern crate test;
3 extern crate time;
4
5 use test::Bencher;
6
7 #[bench]
8 fn bench_precise_time_ns(b: &mut Bencher) {
9 b.iter(|| {
10 time::precise_time_ns();
11 time::precise_time_ns();
12 });
13 }
1010 if ch == '%' {
1111 // we've already validated that % always precedes
1212 // another char
13 try!(parse_type(fmt, chars.next().unwrap(), self.tm));
13 parse_type(fmt, chars.next().unwrap(), self.tm)?;
1414 } else {
15 try!(fmt.write_char(ch));
15 fmt.write_char(ch)?;
1616 }
1717 }
1818
147147 }),
148148 'C' => write!(fmt, "{:02}", (tm.tm_year + 1900) / 100),
149149 'c' => {
150 try!(parse_type(fmt, 'a', tm));
151 try!(fmt.write_str(" "));
152 try!(parse_type(fmt, 'b', tm));
153 try!(fmt.write_str(" "));
154 try!(parse_type(fmt, 'e', tm));
155 try!(fmt.write_str(" "));
156 try!(parse_type(fmt, 'T', tm));
157 try!(fmt.write_str(" "));
150 parse_type(fmt, 'a', tm)?;
151 fmt.write_str(" ")?;
152 parse_type(fmt, 'b', tm)?;
153 fmt.write_str(" ")?;
154 parse_type(fmt, 'e', tm)?;
155 fmt.write_str(" ")?;
156 parse_type(fmt, 'T', tm)?;
157 fmt.write_str(" ")?;
158158 parse_type(fmt, 'Y', tm)
159159 }
160160 'D' | 'x' => {
161 try!(parse_type(fmt, 'm', tm));
162 try!(fmt.write_str("/"));
163 try!(parse_type(fmt, 'd', tm));
164 try!(fmt.write_str("/"));
161 parse_type(fmt, 'm', tm)?;
162 fmt.write_str("/")?;
163 parse_type(fmt, 'd', tm)?;
164 fmt.write_str("/")?;
165165 parse_type(fmt, 'y', tm)
166166 }
167167 'd' => write!(fmt, "{:02}", tm.tm_mday),
168168 'e' => write!(fmt, "{:2}", tm.tm_mday),
169169 'f' => write!(fmt, "{:09}", tm.tm_nsec),
170170 'F' => {
171 try!(parse_type(fmt, 'Y', tm));
172 try!(fmt.write_str("-"));
173 try!(parse_type(fmt, 'm', tm));
174 try!(fmt.write_str("-"));
171 parse_type(fmt, 'Y', tm)?;
172 fmt.write_str("-")?;
173 parse_type(fmt, 'm', tm)?;
174 fmt.write_str("-")?;
175175 parse_type(fmt, 'd', tm)
176176 }
177177 'G' => iso_week(fmt, 'G', tm),
197197 'P' => fmt.write_str(if tm.tm_hour < 12 { "am" } else { "pm" }),
198198 'p' => fmt.write_str(if (tm.tm_hour) < 12 { "AM" } else { "PM" }),
199199 'R' => {
200 try!(parse_type(fmt, 'H', tm));
201 try!(fmt.write_str(":"));
200 parse_type(fmt, 'H', tm)?;
201 fmt.write_str(":")?;
202202 parse_type(fmt, 'M', tm)
203203 }
204204 'r' => {
205 try!(parse_type(fmt, 'I', tm));
206 try!(fmt.write_str(":"));
207 try!(parse_type(fmt, 'M', tm));
208 try!(fmt.write_str(":"));
209 try!(parse_type(fmt, 'S', tm));
210 try!(fmt.write_str(" "));
205 parse_type(fmt, 'I', tm)?;
206 fmt.write_str(":")?;
207 parse_type(fmt, 'M', tm)?;
208 fmt.write_str(":")?;
209 parse_type(fmt, 'S', tm)?;
210 fmt.write_str(" ")?;
211211 parse_type(fmt, 'p', tm)
212212 }
213213 'S' => write!(fmt, "{:02}", tm.tm_sec),
214214 's' => write!(fmt, "{}", tm.to_timespec().sec),
215215 'T' | 'X' => {
216 try!(parse_type(fmt, 'H', tm));
217 try!(fmt.write_str(":"));
218 try!(parse_type(fmt, 'M', tm));
219 try!(fmt.write_str(":"));
216 parse_type(fmt, 'H', tm)?;
217 fmt.write_str(":")?;
218 parse_type(fmt, 'M', tm)?;
219 fmt.write_str(":")?;
220220 parse_type(fmt, 'S', tm)
221221 }
222222 't' => fmt.write_str("\t"),
227227 }
228228 'V' => iso_week(fmt, 'V', tm),
229229 'v' => {
230 try!(parse_type(fmt, 'e', tm));
231 try!(fmt.write_str("-"));
232 try!(parse_type(fmt, 'b', tm));
233 try!(fmt.write_str("-"));
230 parse_type(fmt, 'e', tm)?;
231 fmt.write_str("-")?;
232 parse_type(fmt, 'b', tm)?;
233 fmt.write_str("-")?;
234234 parse_type(fmt, 'Y', tm)
235235 }
236236 'W' => {
8282 /// Panics when the duration is out of bounds.
8383 #[inline]
8484 pub fn hours(hours: i64) -> Duration {
85 let secs = hours.checked_mul(SECS_PER_HOUR).expect("Duration::hours ouf of bounds");
85 let secs = hours.checked_mul(SECS_PER_HOUR).expect("Duration::hours out of bounds");
8686 Duration::seconds(secs)
8787 }
8888
376376 let hasdate = days != 0;
377377 let hastime = (secs != 0 || abs.nanos != 0) || !hasdate;
378378
379 try!(write!(f, "{}P", sign));
379 write!(f, "{}P", sign)?;
380380
381381 if hasdate {
382 try!(write!(f, "{}D", days));
382 write!(f, "{}D", days)?;
383383 }
384384 if hastime {
385385 if abs.nanos == 0 {
386 try!(write!(f, "T{}S", secs));
386 write!(f, "T{}S", secs)?;
387387 } else if abs.nanos % NANOS_PER_MILLI == 0 {
388 try!(write!(f, "T{}.{:03}S", secs, abs.nanos / NANOS_PER_MILLI));
388 write!(f, "T{}.{:03}S", secs, abs.nanos / NANOS_PER_MILLI)?;
389389 } else if abs.nanos % NANOS_PER_MICRO == 0 {
390 try!(write!(f, "T{}.{:06}S", secs, abs.nanos / NANOS_PER_MICRO));
390 write!(f, "T{}.{:06}S", secs, abs.nanos / NANOS_PER_MICRO)?;
391391 } else {
392 try!(write!(f, "T{}.{:09}S", secs, abs.nanos));
392 write!(f, "T{}.{:09}S", secs, abs.nanos)?;
393393 }
394394 }
395395 Ok(())
406406 pub struct OutOfRangeError(());
407407
408408 impl fmt::Display for OutOfRangeError {
409 #[allow(deprecated)]
409410 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
410411 write!(f, "{}", self.description())
411412 }
3232 #![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
3333 html_favicon_url = "https://www.rust-lang.org/favicon.ico",
3434 html_root_url = "https://doc.rust-lang.org/time/")]
35 #![allow(unknown_lints)]
36 #![allow(ellipsis_inclusive_range_patterns)] // `..=` requires Rust 1.26
3537 #![allow(trivial_numeric_casts)]
3638 #![cfg_attr(test, deny(warnings))]
3739
38 #[cfg(target_os = "redox")] extern crate syscall;
3940 #[cfg(unix)] extern crate libc;
4041 #[cfg(windows)] extern crate winapi;
4142 #[cfg(feature = "rustc-serialize")] extern crate rustc_serialize;
550551
551552 impl fmt::Display for ParseError {
552553 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
554 #[allow(deprecated)]
553555 match *self {
554556 InvalidFormatSpecifier(ch) => {
555557 write!(f, "{}: %{}", self.description(), ch)
651653 use super::ParseError::{InvalidTime, InvalidYear, MissingFormatConverter,
652654 InvalidFormatSpecifier};
653655
654 use std::sync::{Once, ONCE_INIT, Mutex, MutexGuard, LockResult};
656 #[allow(deprecated)] // `Once::new` is const starting in Rust 1.32
657 use std::sync::ONCE_INIT;
658 use std::sync::{Once, Mutex, MutexGuard, LockResult};
659 use std::i32;
655660 use std::mem;
656661
657662 struct TzReset {
663668 // Lock manages current timezone because some tests require LA some
664669 // London
665670 static mut LOCK: *mut Mutex<()> = 0 as *mut _;
671 #[allow(deprecated)] // `Once::new` is const starting in Rust 1.32
666672 static INIT: Once = ONCE_INIT;
667673
668674 unsafe {
693699
694700 #[test]
695701 fn test_get_time() {
696 static SOME_RECENT_DATE: i64 = 1325376000i64; // 2012-01-01T00:00:00Z
697 static SOME_FUTURE_DATE: i64 = 1577836800i64; // 2020-01-01T00:00:00Z
702 static SOME_RECENT_DATE: i64 = 1577836800i64; // 2020-01-01T00:00:00Z
703 static SOME_FUTURE_DATE: i64 = i32::MAX as i64; // Y2038
698704
699705 let tv1 = get_time();
700706 debug!("tv1={} sec + {} nsec", tv1.sec, tv1.nsec);
1919 while let Some(ch) = chars.next() {
2020 if ch == '%' {
2121 if let Some(ch) = chars.next() {
22 try!(parse_type(&mut s, ch, &mut tm));
22 parse_type(&mut s, ch, &mut tm)?;
2323 }
2424 } else {
25 try!(parse_char(&mut s, ch));
25 parse_char(&mut s, ch)?;
2626 }
2727 }
2828
325325 let mut value : i64 = 0;
326326 let mut n = 0;
327327 if ws {
328 #[allow(deprecated)] // use `trim_start_matches` starting in 1.30
328329 let s2 = ss.trim_left_matches(" ");
329330 n = ss.len() - s2.len();
330331 if n > max_digits { return None }
33
44 #[cfg(any(
55 all(target_arch = "wasm32", not(target_os = "emscripten")),
6 target_os = "redox",
76 target_env = "sgx"
87 ))]
98 mod common {
133132 }
134133 }
135134
136 #[cfg(target_os = "redox")]
137 mod inner {
138 use std::fmt;
139 use std::cmp::Ordering;
140 use std::ops::{Add, Sub};
141 use syscall;
142 use super::common::{time_to_tm, tm_to_time};
143
144 use Duration;
145 use Tm;
146
147 pub fn time_to_utc_tm(sec: i64, tm: &mut Tm) {
148 time_to_tm(sec, tm);
149 }
150
151 pub fn time_to_local_tm(sec: i64, tm: &mut Tm) {
152 // FIXME: Add timezone logic
153 time_to_tm(sec, tm);
154 }
155
156 pub fn utc_tm_to_time(tm: &Tm) -> i64 {
157 tm_to_time(tm)
158 }
159
160 pub fn local_tm_to_time(tm: &Tm) -> i64 {
161 // FIXME: Add timezone logic
162 tm_to_time(tm)
163 }
164
165 pub fn get_time() -> (i64, i32) {
166 let mut tv = syscall::TimeSpec { tv_sec: 0, tv_nsec: 0 };
167 syscall::clock_gettime(syscall::CLOCK_REALTIME, &mut tv).unwrap();
168 (tv.tv_sec as i64, tv.tv_nsec as i32)
169 }
170
171 pub fn get_precise_ns() -> u64 {
172 let mut ts = syscall::TimeSpec { tv_sec: 0, tv_nsec: 0 };
173 syscall::clock_gettime(syscall::CLOCK_MONOTONIC, &mut ts).unwrap();
174 (ts.tv_sec as u64) * 1000000000 + (ts.tv_nsec as u64)
175 }
176
177 #[derive(Copy)]
178 pub struct SteadyTime {
179 t: syscall::TimeSpec,
180 }
181
182 impl fmt::Debug for SteadyTime {
183 fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
184 write!(fmt, "SteadyTime {{ tv_sec: {:?}, tv_nsec: {:?} }}",
185 self.t.tv_sec, self.t.tv_nsec)
186 }
187 }
188
189 impl Clone for SteadyTime {
190 fn clone(&self) -> SteadyTime {
191 SteadyTime { t: self.t }
192 }
193 }
194
195 impl SteadyTime {
196 pub fn now() -> SteadyTime {
197 let mut t = SteadyTime {
198 t: syscall::TimeSpec {
199 tv_sec: 0,
200 tv_nsec: 0,
201 }
202 };
203 syscall::clock_gettime(syscall::CLOCK_MONOTONIC, &mut t.t).unwrap();
204 t
205 }
206 }
207
208 impl Sub for SteadyTime {
209 type Output = Duration;
210 fn sub(self, other: SteadyTime) -> Duration {
211 if self.t.tv_nsec >= other.t.tv_nsec {
212 Duration::seconds(self.t.tv_sec as i64 - other.t.tv_sec as i64) +
213 Duration::nanoseconds(self.t.tv_nsec as i64 - other.t.tv_nsec as i64)
214 } else {
215 Duration::seconds(self.t.tv_sec as i64 - 1 - other.t.tv_sec as i64) +
216 Duration::nanoseconds(self.t.tv_nsec as i64 + ::NSEC_PER_SEC as i64 -
217 other.t.tv_nsec as i64)
218 }
219 }
220 }
221
222 impl Sub<Duration> for SteadyTime {
223 type Output = SteadyTime;
224 fn sub(self, other: Duration) -> SteadyTime {
225 self + -other
226 }
227 }
228
229 impl Add<Duration> for SteadyTime {
230 type Output = SteadyTime;
231 fn add(mut self, other: Duration) -> SteadyTime {
232 let seconds = other.num_seconds();
233 let nanoseconds = other - Duration::seconds(seconds);
234 let nanoseconds = nanoseconds.num_nanoseconds().unwrap();
235 self.t.tv_sec += seconds;
236 self.t.tv_nsec += nanoseconds as i32;
237 if self.t.tv_nsec >= ::NSEC_PER_SEC {
238 self.t.tv_nsec -= ::NSEC_PER_SEC;
239 self.t.tv_sec += 1;
240 } else if self.t.tv_nsec < 0 {
241 self.t.tv_sec -= 1;
242 self.t.tv_nsec += ::NSEC_PER_SEC;
243 }
244 self
245 }
246 }
247
248 impl PartialOrd for SteadyTime {
249 fn partial_cmp(&self, other: &SteadyTime) -> Option<Ordering> {
250 Some(self.cmp(other))
251 }
252 }
253
254 impl Ord for SteadyTime {
255 fn cmp(&self, other: &SteadyTime) -> Ordering {
256 match self.t.tv_sec.cmp(&other.t.tv_sec) {
257 Ordering::Equal => self.t.tv_nsec.cmp(&other.t.tv_nsec),
258 ord => ord
259 }
260 }
261 }
262
263 impl PartialEq for SteadyTime {
264 fn eq(&self, other: &SteadyTime) -> bool {
265 self.t.tv_sec == other.t.tv_sec &&
266 self.t.tv_nsec == other.t.tv_nsec
267 }
268 }
269
270 impl Eq for SteadyTime {}
271 }
272
273135 #[cfg(target_env = "sgx")]
274136 mod inner {
275137 use std::ops::{Add, Sub};
309171 }
310172
311173 pub fn get_precise_ns() -> u64 {
312 // This unwrap is safe because current time is well ahead of UNIX_EPOCH, unless system clock is adjusted backward.
174 // This unwrap is safe because current time is well ahead of UNIX_EPOCH, unless system
175 // clock is adjusted backward.
313176 let std_duration = SystemTime::now().duration_since(SystemTime::UNIX_EPOCH).unwrap();
314177 std_duration.as_secs() * NANOS_PER_SEC + std_duration.subsec_nanos() as u64
315178 }
316179
317180 impl SteadyTime {
318181 pub fn now() -> SteadyTime {
319 // This unwrap is safe because current time is well ahead of UNIX_EPOCH, unless system clock is adjusted backward.
182 // This unwrap is safe because current time is well ahead of UNIX_EPOCH, unless system
183 // clock is adjusted backward.
320184 let std_duration = SystemTime::now().duration_since(SystemTime::UNIX_EPOCH).unwrap();
321185 // This unwrap is safe because duration is well within the limits of i64.
322186 let duration = Duration::from_std(std_duration).unwrap();
358222 #[cfg(all(not(target_os = "macos"), not(target_os = "ios")))]
359223 pub use self::unix::*;
360224
361 #[cfg(target_os = "solaris")]
225 #[cfg(any(target_os = "solaris", target_os = "illumos"))]
362226 extern {
363227 static timezone: time_t;
364228 static altzone: time_t;
389253 rust_tm.tm_utcoff = utcoff;
390254 }
391255
392 #[cfg(any(target_os = "nacl", target_os = "solaris"))]
256 #[cfg(any(target_os = "nacl", target_os = "solaris", target_os = "illumos"))]
393257 unsafe fn timegm(tm: *mut libc::tm) -> time_t {
394258 use std::env::{set_var, var_os, remove_var};
395259 extern {
432296 if libc::localtime_r(&sec, &mut out).is_null() {
433297 panic!("localtime_r failed: {}", io::Error::last_os_error());
434298 }
435 #[cfg(target_os = "solaris")]
299 #[cfg(any(target_os = "solaris", target_os = "illumos"))]
436300 let gmtoff = {
437301 ::tzset();
438302 // < 0 means we don't know; assume we're not in DST.
445309 -timezone
446310 }
447311 };
448 #[cfg(not(target_os = "solaris"))]
312 #[cfg(not(any(target_os = "solaris", target_os = "illumos")))]
449313 let gmtoff = out.tm_gmtoff;
450314 tm_to_rust_tm(&out, gmtoff as i32, tm);
451315 }
454318 pub fn utc_tm_to_time(rust_tm: &Tm) -> i64 {
455319 #[cfg(all(target_os = "android", target_pointer_width = "32"))]
456320 use libc::timegm64 as timegm;
457 #[cfg(not(any(all(target_os = "android", target_pointer_width = "32"), target_os = "nacl", target_os = "solaris")))]
321 #[cfg(not(any(
322 all(target_os = "android", target_pointer_width = "32"),
323 target_os = "nacl",
324 target_os = "solaris",
325 target_os = "illumos"
326 )))]
458327 use libc::timegm;
459328
460329 let mut tm = unsafe { mem::zeroed() };
470339
471340 #[cfg(any(target_os = "macos", target_os = "ios"))]
472341 mod mac {
342 #[allow(deprecated)]
473343 use libc::{self, timeval, mach_timebase_info};
344 #[allow(deprecated)]
474345 use std::sync::{Once, ONCE_INIT};
475346 use std::ops::{Add, Sub};
476347 use Duration;
477348
349 #[allow(deprecated)]
478350 fn info() -> &'static mach_timebase_info {
479351 static mut INFO: mach_timebase_info = mach_timebase_info {
480352 numer: 0,
497369 (tv.tv_sec as i64, tv.tv_usec * 1000)
498370 }
499371
372 #[allow(deprecated)]
500373 #[inline]
501374 pub fn get_precise_ns() -> u64 {
502375 unsafe {
691564 mod inner {
692565 use std::io;
693566 use std::mem;
567 #[allow(deprecated)]
694568 use std::sync::{Once, ONCE_INIT};
695569 use std::ops::{Add, Sub};
696570 use {Tm, Duration};
704578
705579 fn frequency() -> i64 {
706580 static mut FREQUENCY: i64 = 0;
581 #[allow(deprecated)]
707582 static ONCE: Once = ONCE_INIT;
708583
709584 unsafe {
979854 // https://msdn.microsoft.com/en-us/library/windows/desktop/ms724944%28v=vs.85%29.aspx
980855 #[cfg(test)]
981856 fn acquire_privileges() {
982 use std::sync::{ONCE_INIT, Once};
983857 use winapi::um::processthreadsapi::*;
984858 use winapi::um::winbase::LookupPrivilegeValueA;
985859 const SE_PRIVILEGE_ENABLED: DWORD = 2;
860 #[allow(deprecated)]
986861 static INIT: Once = ONCE_INIT;
987862
988863 // TODO: FIXME
993868 ) -> BOOL;
994869 }
995870
996 #[repr(C)]
997 struct TKP {
998 tkp: TOKEN_PRIVILEGES,
999 laa: LUID_AND_ATTRIBUTES,
1000 }
1001
1002871 INIT.call_once(|| unsafe {
1003872 let mut hToken = 0 as *mut _;
1004873 call!(OpenProcessToken(GetCurrentProcess(),
1005874 TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY,
1006875 &mut hToken));
1007876
1008 let mut tkp = mem::zeroed::<TKP>();
1009 assert_eq!(tkp.tkp.Privileges.len(), 0);
877 let mut tkp = mem::zeroed::<TOKEN_PRIVILEGES>();
878 assert_eq!(tkp.Privileges.len(), 1);
1010879 let c = ::std::ffi::CString::new("SeTimeZonePrivilege").unwrap();
1011880 call!(LookupPrivilegeValueA(0 as *const _, c.as_ptr(),
1012 &mut tkp.laa.Luid));
1013 tkp.tkp.PrivilegeCount = 1;
1014 tkp.laa.Attributes = SE_PRIVILEGE_ENABLED;
1015 call!(AdjustTokenPrivileges(hToken, FALSE, &mut tkp.tkp, 0,
881 &mut tkp.Privileges[0].Luid));
882 tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
883 tkp.PrivilegeCount = 1;
884 call!(AdjustTokenPrivileges(hToken, FALSE, &mut tkp, 0,
1016885 0 as *mut _, 0 as *mut _));
1017886 });
1018887 }
237237 }
238238
239239 OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
240 if (unlikely(output_ctx == NULL))
241 return result;
240 if (unlikely(output_ctx == NULL)) {
241 LogFileFreeCtx(logfile_ctx);
242 return result;
243 }
244
242245 output_ctx->data = logfile_ctx;
243246 output_ctx->DeInit = AlertFastLogDeInitCtx;
244247
392392 SCLogDebug("length too small to be a ENIP header");
393393 return ALPROTO_UNKNOWN;
394394 }
395
396 return ALPROTO_ENIP;
395 uint16_t cmd;
396 int ret = ByteExtractUint16(&cmd, BYTE_LITTLE_ENDIAN, sizeof(uint16_t),
397 (const uint8_t *) (input));
398 if(ret < 0) {
399 return ALPROTO_FAILED;
400 }
401 //ok for all the known commands
402 switch(cmd) {
403 case NOP:
404 case LIST_SERVICES:
405 case LIST_IDENTITY:
406 case LIST_INTERFACES:
407 case REGISTER_SESSION:
408 case UNREGISTER_SESSION:
409 case SEND_RR_DATA:
410 case SEND_UNIT_DATA:
411 case INDICATE_STATUS:
412 case CANCEL:
413 return ALPROTO_ENIP;
414 }
415 return ALPROTO_FAILED;
397416 }
398417
399418 /**
0 /* Copyright (C) 2017 Open Information Security Foundation
0 /* Copyright (C) 2017-2020 Open Information Security Foundation
11 *
22 * You can copy, redistribute or modify this Program under the terms of
33 * the GNU General Public License version 2 as published by the Free
6060 #include "app-layer-expectation.h"
6161
6262 #include "util-print.h"
63 #include "queue.h"
6364
6465 static int g_expectation_id = -1;
6566 static int g_expectation_data_id = -1;
6768 SC_ATOMIC_DECLARE(uint32_t, expectation_count);
6869
6970 #define EXPECTATION_TIMEOUT 30
71 #define EXPECTATION_MAX_LEVEL 10
7072
7173 typedef struct Expectation_ {
7274 struct timeval ts;
7476 Port dp;
7577 AppProto alproto;
7678 int direction;
79 /* use pointer to Flow as identifier of the Flow the expectation is linked to */
80 void *orig_f;
7781 void *data;
78 struct Expectation_ *next;
82 CIRCLEQ_ENTRY(Expectation_) entries;
7983 } Expectation;
8084
8185 typedef struct ExpectationData_ {
8387 * to free function. Set to NULL to use SCFree() */
8488 void (*DFree)(void *);
8589 } ExpectationData;
90
91 typedef struct ExpectationList_ {
92 CIRCLEQ_HEAD(EList, Expectation_) list;
93 uint8_t length;
94 } ExpectationList;
8695
8796 static void ExpectationDataFree(void *e)
8897 {
95104 }
96105 }
97106
98 static void ExpectationListFree(void *e)
99 {
100 Expectation *exp = (Expectation *)e;
101 Expectation *lexp;
102 while (exp) {
103 lexp = exp->next;
104 if (exp->data) {
105 ExpectationData *expdata = (ExpectationData *) exp->data;
106 if (expdata->DFree) {
107 expdata->DFree(exp->data);
108 } else {
109 SCFree(exp->data);
110 }
111 }
112 SCFree(exp);
113 exp = lexp;
114 }
107 /**
108 * Free expectation
109 */
110 static void AppLayerFreeExpectation(Expectation *exp)
111 {
112 if (exp->data) {
113 ExpectationData *expdata = (ExpectationData *)exp->data;
114 if (expdata->DFree) {
115 expdata->DFree(exp->data);
116 } else {
117 SCFree(exp->data);
118 }
119 }
120 SCFree(exp);
121 }
122
123 static void ExpectationListFree(void *el)
124 {
125 ExpectationList *exp_list = (ExpectationList *)el;
126 Expectation *exp, *pexp;
127 if (exp_list == NULL)
128 return;
129
130 if (exp_list->length > 0) {
131 CIRCLEQ_FOREACH_SAFE(exp, &exp_list->list, entries, pexp) {
132 CIRCLEQ_REMOVE(&exp_list->list, exp, entries);
133 exp_list->length--;
134 AppLayerFreeExpectation(exp);
135 }
136 }
137 SCFree(exp_list);
115138 }
116139
117140 uint64_t ExpectationGetCounter(void)
143166 return 0;
144167 }
145168
146 static Expectation *AppLayerExpectationLookup(Flow *f, int direction, IPPair **ipp)
169 static ExpectationList *AppLayerExpectationLookup(Flow *f, IPPair **ipp)
147170 {
148171 Address ip_src, ip_dst;
149172 if (GetFlowAddresses(f, &ip_src, &ip_dst) == -1)
156179 return IPPairGetStorageById(*ipp, g_expectation_id);
157180 }
158181
182
183 static ExpectationList *AppLayerExpectationRemove(IPPair *ipp,
184 ExpectationList *exp_list,
185 Expectation *exp)
186 {
187 CIRCLEQ_REMOVE(&exp_list->list, exp, entries);
188 AppLayerFreeExpectation(exp);
189 SC_ATOMIC_SUB(expectation_count, 1);
190 exp_list->length--;
191 if (exp_list->length == 0) {
192 IPPairSetStorageById(ipp, g_expectation_id, NULL);
193 ExpectationListFree(exp_list);
194 exp_list = NULL;
195 }
196 return exp_list;
197 }
198
159199 /**
160200 * Create an entry in expectation list
161201 *
162202 * Create a expectation from an existing Flow. Currently, only Flow between
163 * the two original IP addresses are supported.
203 * the two original IP addresses are supported. In case of success, the
204 * ownership of the data pointer is taken. In case of error, the pointer
205 * to data has to be freed by the caller.
164206 *
165207 * \param f a pointer to the original Flow
166208 * \param direction the direction of the data in the expectation flow
175217 int AppLayerExpectationCreate(Flow *f, int direction, Port src, Port dst,
176218 AppProto alproto, void *data)
177219 {
178 Expectation *iexp = NULL;
220 ExpectationList *exp_list = NULL;
179221 IPPair *ipp;
180222 Address ip_src, ip_dst;
181223
187229 exp->dp = dst;
188230 exp->alproto = alproto;
189231 exp->ts = f->lastts;
232 exp->orig_f = (void *)f;
190233 exp->data = data;
191234 exp->direction = direction;
192235
196239 if (ipp == NULL)
197240 goto error;
198241
199 iexp = IPPairGetStorageById(ipp, g_expectation_id);
200 exp->next = iexp;
201 IPPairSetStorageById(ipp, g_expectation_id, exp);
202
242 exp_list = IPPairGetStorageById(ipp, g_expectation_id);
243 if (exp_list) {
244 CIRCLEQ_INSERT_HEAD(&exp_list->list, exp, entries);
245 /* In case there is already EXPECTATION_MAX_LEVEL expectations waiting to be fullfill,
246 * we remove the older expectation to limit the total number of expectations */
247 if (exp_list->length >= EXPECTATION_MAX_LEVEL) {
248 Expectation *last_exp = CIRCLEQ_LAST(&exp_list->list);
249 CIRCLEQ_REMOVE(&exp_list->list, last_exp, entries);
250 AppLayerFreeExpectation(last_exp);
251 /* We keep the same amount of expectation so we fully release
252 * the IP pair */
253 f->flags |= FLOW_HAS_EXPECTATION;
254 IPPairRelease(ipp);
255 return 0;
256 }
257 } else {
258 exp_list = SCCalloc(1, sizeof(*exp_list));
259 if (exp_list == NULL)
260 goto error;
261 exp_list->length = 0;
262 CIRCLEQ_INIT(&exp_list->list);
263 CIRCLEQ_INSERT_HEAD(&exp_list->list, exp, entries);
264 IPPairSetStorageById(ipp, g_expectation_id, exp_list);
265 }
266
267 exp_list->length += 1;
203268 SC_ATOMIC_ADD(expectation_count, 1);
269 f->flags |= FLOW_HAS_EXPECTATION;
204270 /* As we are creating the expectation, we release lock on IPPair without
205271 * setting the ref count to 0. This way the IPPair will be kept till
206272 * cleanup */
223289 }
224290
225291 /**
226 *
227 * Remove expectation and return next one
228 *
229 * \param ipp an IPPair
230 * \param pexp pointer to previous Expectation
231 * \param exp pointer to Expectation to remove
232 * \param lexp pointer to head of Expectation ist
233 * \return expectation
234 */
235 static Expectation * RemoveExpectationAndGetNext(IPPair *ipp,
236 Expectation *pexp, Expectation *exp,
237 Expectation *lexp)
238 {
239 /* we remove the object so we get ref count down by 1 to remove reference
240 * hold by the expectation
241 */
242 (void) IPPairDecrUsecnt(ipp);
243 SC_ATOMIC_SUB(expectation_count, 1);
244 if (pexp == NULL) {
245 IPPairSetStorageById(ipp, g_expectation_id, lexp);
246 } else {
247 pexp->next = lexp;
248 }
249 if (exp->data) {
250 ExpectationData *expdata = (ExpectationData *)exp->data;
251 if (expdata->DFree) {
252 expdata->DFree(exp->data);
253 } else {
254 SCFree(exp->data);
255 }
256 }
257 SCFree(exp);
258 return lexp;
259 }
260
261 /**
262292 * Function doing a lookup in expectation list and updating Flow if needed.
263293 *
264294 * This function lookup for a existing expectation that could match the Flow.
273303 AppProto alproto = ALPROTO_UNKNOWN;
274304 IPPair *ipp = NULL;
275305 Expectation *lexp = NULL;
276 Expectation *pexp = NULL;
306 Expectation *exp = NULL;
277307
278308 int x = SC_ATOMIC_GET(expectation_count);
279309 if (x == 0) {
281311 }
282312
283313 /* Call will take reference of the ip pair in 'ipp' */
284 Expectation *exp = AppLayerExpectationLookup(f, direction, &ipp);
285 if (exp == NULL)
314 ExpectationList *exp_list = AppLayerExpectationLookup(f, &ipp);
315 if (exp_list == NULL)
286316 goto out;
287317
288318 time_t ctime = f->lastts.tv_sec;
289319
290 pexp = NULL;
291 while (exp) {
292 lexp = exp->next;
293 if ( (exp->direction & direction) &&
320 CIRCLEQ_FOREACH_SAFE(exp, &exp_list->list, entries, lexp) {
321 if ((exp->direction & direction) &&
294322 ((exp->sp == 0) || (exp->sp == f->sp)) &&
295323 ((exp->dp == 0) || (exp->dp == f->dp))) {
296324 alproto = exp->alproto;
307335 }
308336 }
309337 exp->data = NULL;
310 exp = RemoveExpectationAndGetNext(ipp, pexp, exp, lexp);
338 exp_list = AppLayerExpectationRemove(ipp, exp_list, exp);
339 if (exp_list == NULL)
340 goto out;
311341 continue;
312342 }
313343 /* Cleaning remove old entries */
314 if (exp && (ctime > exp->ts.tv_sec + EXPECTATION_TIMEOUT)) {
315 exp = RemoveExpectationAndGetNext(ipp, pexp, exp, lexp);
344 if (ctime > exp->ts.tv_sec + EXPECTATION_TIMEOUT) {
345 exp_list = AppLayerExpectationRemove(ipp, exp_list, exp);
346 if (exp_list == NULL)
347 goto out;
316348 continue;
317349 }
318 pexp = exp;
319 exp = lexp;
320350 }
321351
322352 out:
325355 return alproto;
326356 }
327357
358 void AppLayerExpectationClean(Flow *f)
359 {
360 IPPair *ipp = NULL;
361 Expectation *exp = NULL;
362 Expectation *pexp = NULL;
363
364 int x = SC_ATOMIC_GET(expectation_count);
365 if (x == 0) {
366 return;
367 }
368
369 /* Call will take reference of the ip pair in 'ipp' */
370 ExpectationList *exp_list = AppLayerExpectationLookup(f, &ipp);
371 if (exp_list == NULL)
372 goto out;
373
374 CIRCLEQ_FOREACH_SAFE(exp, &exp_list->list, entries, pexp) {
375 /* Cleaning remove old entries */
376 if (exp->orig_f == (void *)f) {
377 exp_list = AppLayerExpectationRemove(ipp, exp_list, exp);
378 if (exp_list == NULL)
379 goto out;
380 }
381 }
382
383 out:
384 if (ipp)
385 IPPairRelease(ipp);
386 return;
387 }
388
328389 /**
329390 * @}
330391 */
2929 AppProto AppLayerExpectationHandle(Flow *f, int direction);
3030 int AppLayerExpectationGetDataId(void);
3131
32 void AppLayerExpectationClean(Flow *f);
33
3234 uint64_t ExpectationGetCounter(void);
3335
3436 #endif /* __APP_LAYER_EXPECTATION__H__ */
344344 FTPStringFree(str);
345345 }
346346
347 SCFree(tx);
347 FTPFree(tx, sizeof(*tx));
348348 }
349349
350350 static int FTPGetLineForDirection(FtpState *state, FtpLineState *line_state)
513513 if (cmd == NULL)
514514 return;
515515 if (cmd->file_name) {
516 FTPFree(cmd->file_name, cmd->file_len);
516 FTPFree(cmd->file_name, cmd->file_len + 1);
517517 }
518518 FTPFree(cmd, sizeof(struct FtpTransferCmd));
519519 }
536536 *dest = where;
537537 }
538538 /* either 0 or actual */
539 return length;
539 return length ? length + 1 : 0;
540540 }
541541
542542
734734 if (unlikely(input_len == 0)) {
735735 return 1;
736736 }
737
738 FTPTransaction *tx = FTPGetOldestTx(state);
739 if (tx == NULL) {
740 tx = FTPTransactionCreate(state);
741 }
742 if (unlikely(tx == NULL)) {
743 return -1;
744 }
745 if (state->command == FTP_COMMAND_UNKNOWN || tx->command_descriptor == NULL) {
746 /* unknown */
747 tx->command_descriptor = &FtpCommands[FTP_COMMAND_MAX -1];
748 }
749
750 state->curr_tx = tx;
751 if (state->command == FTP_COMMAND_AUTH_TLS) {
752 if (input_len >= 4 && SCMemcmp("234 ", input, 4) == 0) {
753 AppLayerRequestProtocolTLSUpgrade(f);
754 }
755 }
756
757 if (state->command == FTP_COMMAND_EPRT) {
758 uint16_t dyn_port = rs_ftp_active_eprt(state->port_line, state->port_line_len);
759 if (dyn_port == 0) {
760 retcode = 0;
761 goto tx_complete;
762 }
763 state->dyn_port = dyn_port;
764 state->active = true;
765 tx->dyn_port = dyn_port;
766 tx->active = true;
767 SCLogDebug("FTP active mode (v6): dynamic port %"PRIu16"", dyn_port);
768 }
769
770 if (state->command == FTP_COMMAND_PORT) {
771 if ((flags & STREAM_TOCLIENT)) {
772 uint16_t dyn_port = rs_ftp_active_port(state->port_line, state->port_line_len);
737 state->input = input;
738 state->input_len = input_len;
739 /* toclient stream */
740 state->direction = 1;
741
742 while (FTPGetLine(state) >= 0) {
743 FTPTransaction *tx = FTPGetOldestTx(state);
744 if (tx == NULL) {
745 tx = FTPTransactionCreate(state);
746 }
747 if (unlikely(tx == NULL)) {
748 return -1;
749 }
750 if (state->command == FTP_COMMAND_UNKNOWN || tx->command_descriptor == NULL) {
751 /* unknown */
752 tx->command_descriptor = &FtpCommands[FTP_COMMAND_MAX -1];
753 }
754
755 state->curr_tx = tx;
756 if (state->command == FTP_COMMAND_AUTH_TLS) {
757 if (state->current_line_len >= 4 && SCMemcmp("234 ", state->current_line, 4) == 0) {
758 AppLayerRequestProtocolTLSUpgrade(f);
759 }
760 }
761
762 if (state->command == FTP_COMMAND_EPRT) {
763 uint16_t dyn_port = rs_ftp_active_eprt(state->port_line, state->port_line_len);
773764 if (dyn_port == 0) {
774 retcode = 0;
775765 goto tx_complete;
776766 }
777767 state->dyn_port = dyn_port;
778768 state->active = true;
779 tx->dyn_port = state->dyn_port;
769 tx->dyn_port = dyn_port;
780770 tx->active = true;
781 SCLogDebug("FTP active mode (v4): dynamic port %"PRIu16"", dyn_port);
782 }
783 }
784
785 if (state->command == FTP_COMMAND_PASV) {
786 if (input_len >= 4 && SCMemcmp("227 ", input, 4) == 0) {
787 FTPParsePassiveResponse(f, ftp_state, input, input_len);
788 }
789 }
790
791 if (state->command == FTP_COMMAND_EPSV) {
792 if (input_len >= 4 && SCMemcmp("229 ", input, 4) == 0) {
793 FTPParsePassiveResponseV6(f, ftp_state, input, input_len);
794 }
795 }
796
797 if (likely(input_len)) {
798 FTPString *response = FTPStringAlloc();
799 if (likely(response)) {
800 response->len = CopyCommandLine(&response->str, input, input_len);
801 TAILQ_INSERT_TAIL(&tx->response_list, response, next);
802 }
803 }
804
805 /* Handle preliminary replies -- keep tx open */
806 if (FTPIsPPR(input, input_len)) {
807 return retcode;
808 }
809
810 tx_complete:
811 tx->done = true;
771 SCLogDebug("FTP active mode (v6): dynamic port %"PRIu16"", dyn_port);
772 }
773
774 if (state->command == FTP_COMMAND_PORT) {
775 if ((flags & STREAM_TOCLIENT)) {
776 uint16_t dyn_port = rs_ftp_active_port(state->port_line, state->port_line_len);
777 if (dyn_port == 0) {
778 goto tx_complete;
779 }
780 state->dyn_port = dyn_port;
781 state->active = true;
782 tx->dyn_port = state->dyn_port;
783 tx->active = true;
784 SCLogDebug("FTP active mode (v4): dynamic port %"PRIu16"", dyn_port);
785 }
786 }
787
788 if (state->command == FTP_COMMAND_PASV) {
789 if (state->current_line_len >= 4 && SCMemcmp("227 ", state->current_line, 4) == 0) {
790 FTPParsePassiveResponse(f, ftp_state, state->current_line, state->current_line_len);
791 }
792 }
793
794 if (state->command == FTP_COMMAND_EPSV) {
795 if (state->current_line_len >= 4 && SCMemcmp("229 ", state->current_line, 4) == 0) {
796 FTPParsePassiveResponseV6(f, ftp_state, state->current_line, state->current_line_len);
797 }
798 }
799
800 if (likely(state->current_line_len)) {
801 FTPString *response = FTPStringAlloc();
802 if (likely(response)) {
803 response->len = CopyCommandLine(&response->str, state->current_line, state->current_line_len);
804 TAILQ_INSERT_TAIL(&tx->response_list, response, next);
805 }
806 }
807
808 /* Handle preliminary replies -- keep tx open */
809 if (FTPIsPPR(state->current_line, state->current_line_len)) {
810 continue;
811 }
812 tx_complete:
813 tx->done = true;
814 }
815
812816 return retcode;
813817 }
814818
990994 SCLogDebug("tx %p", vtx);
991995 FTPTransaction *tx = vtx;
992996
993 if (direction == STREAM_TOSERVER &&
994 tx->command_descriptor->command == FTP_COMMAND_PORT) {
995 return FTP_STATE_PORT_DONE;
996 }
997
998 if (!tx->done)
997 if (!tx->done) {
998 if (direction == STREAM_TOSERVER &&
999 tx->command_descriptor->command == FTP_COMMAND_PORT) {
1000 return FTP_STATE_PORT_DONE;
1001 }
9991002 return FTP_STATE_IN_PROGRESS;
1003 }
10001004
10011005 return FTP_STATE_FINISHED;
10021006 }
11831187 DetectEngineStateFree(fstate->de_state);
11841188 }
11851189 if (fstate->file_name != NULL) {
1186 FTPFree(fstate->file_name, fstate->file_len);
1190 FTPFree(fstate->file_name, fstate->file_len + 1);
11871191 }
11881192
11891193 FileContainerFree(fstate->files);
11901194
1191 SCFree(s);
1195 FTPFree(s, sizeof(FtpDataState));
11921196 #ifdef DEBUG
11931197 SCMutexLock(&ftpdata_state_mem_lock);
11941198 ftpdata_state_memcnt--;
35113511 }
35123512
35133513 htp_tx_t *tx = HTPStateGetTx(http_state, 0);
3514 FAIL_IF_NULL(tx);
35143515 htp_header_t *h = htp_table_get_index(tx->request_headers, 0, NULL);
3515 if ((tx->request_method) != NULL || h != NULL)
3516 {
3517 printf("expected method NULL, got %s \n", bstr_util_strdup_to_c(tx->request_method));
3518 goto end;
3519 }
3516 FAIL_IF_NOT_NULL(h);
3517
3518 FAIL_IF_NULL(tx->request_method);
3519 char *method = bstr_util_strdup_to_c(tx->request_method);
3520 FAIL_IF_NULL(method);
3521
3522 FAIL_IF(strcmp(method, "POST") != 0);
3523 SCFree(method);
3524
35203525 result = 1;
35213526 end:
35223527 if (alp_tctx != NULL)
0 /* Copyright (C) 2007-2012 Open Information Security Foundation
0 /* Copyright (C) 2007-2020 Open Information Security Foundation
11 *
22 * You can copy, redistribute or modify this Program under the terms of
33 * the GNU General Public License version 2 as published by the Free
100100 #define SMTP_COMMAND_DATA_MODE 4
101101 /* All other commands are represented by this var */
102102 #define SMTP_COMMAND_OTHER_CMD 5
103 #define SMTP_COMMAND_RSET 6
103104
104105 /* Different EHLO extensions. Not used now. */
105106 #define SMTP_EHLO_EXTENSION_PIPELINING
146147 SMTP_DECODER_EVENT_MIME_LONG_HEADER_VALUE },
147148 { "MIME_LONG_BOUNDARY",
148149 SMTP_DECODER_EVENT_MIME_BOUNDARY_TOO_LONG },
150 { "MIME_LONG_FILENAME",
151 SMTP_DECODER_EVENT_MIME_LONG_FILENAME },
149152
150153 /* Invalid behavior or content */
151154 { "DUPLICATE_FIELDS",
557560 *
558561 * \param state The smtp state.
559562 *
560 * \retval 0 On suceess.
563 * \retval 0 On success.
561564 * \retval -1 Either when we don't have any new lines to supply anymore or
562565 * on failure.
563566 */
872875 if (msg->anomaly_flags & ANOM_LONG_BOUNDARY) {
873876 SMTPSetEvent(state, SMTP_DECODER_EVENT_MIME_BOUNDARY_TOO_LONG);
874877 }
878 if (msg->anomaly_flags & ANOM_LONG_FILENAME) {
879 SMTPSetEvent(state, SMTP_DECODER_EVENT_MIME_LONG_FILENAME);
880 }
881 }
882
883 static inline void SMTPTransactionComplete(SMTPState *state)
884 {
885 DEBUG_VALIDATE_BUG_ON(state->curr_tx == NULL);
886 if (state->curr_tx)
887 state->curr_tx->done = 1;
875888 }
876889
877890 /**
884897 SCEnter();
885898
886899 if (!(state->parser_state & SMTP_PARSER_STATE_COMMAND_DATA_MODE)) {
887 /* looks like are still waiting for a confirmination from the server */
900 /* looks like are still waiting for a confirmation from the server */
888901 return 0;
889902 }
890903
910923 /* Generate decoder events */
911924 SetMimeEvents(state);
912925 }
913 state->curr_tx->done = 1;
926 SMTPTransactionComplete(state);
914927 SCLogDebug("marked tx as done");
915928 } else if (smtp_config.raw_extraction) {
916929 // message not over, store the line. This is a substitution of
948961 AppLayerParserState *pstate)
949962 {
950963 return 0;
964 }
965
966 static inline bool IsReplyToCommand(const SMTPState *state, const uint8_t cmd)
967 {
968 return (state->cmds_idx < state->cmds_buffer_len &&
969 state->cmds[state->cmds_idx] == cmd);
951970 }
952971
953972 static int SMTPProcessReply(SMTPState *state, Flow *f,
10201039
10211040 if (state->cmds_cnt == 0) {
10221041 /* reply but not a command we have stored, fall through */
1023 } else if (state->cmds[state->cmds_idx] == SMTP_COMMAND_STARTTLS) {
1042 } else if (IsReplyToCommand(state, SMTP_COMMAND_STARTTLS)) {
10241043 if (reply_code == SMTP_REPLY_220) {
10251044 /* we are entering STARRTTLS data mode */
10261045 state->parser_state |= SMTP_PARSER_STATE_COMMAND_DATA_MODE;
10271046 AppLayerRequestProtocolTLSUpgrade(f);
1028 state->curr_tx->done = 1;
1047 SMTPTransactionComplete(state);
10291048 } else {
10301049 /* decoder event */
10311050 SMTPSetEvent(state, SMTP_DECODER_EVENT_TLS_REJECTED);
10321051 }
1033 } else if (state->cmds[state->cmds_idx] == SMTP_COMMAND_DATA) {
1052 } else if (IsReplyToCommand(state, SMTP_COMMAND_DATA)) {
10341053 if (reply_code == SMTP_REPLY_354) {
10351054 /* Next comes the mail for the DATA command in toserver direction */
10361055 state->parser_state |= SMTP_PARSER_STATE_COMMAND_DATA_MODE;
10381057 /* decoder event */
10391058 SMTPSetEvent(state, SMTP_DECODER_EVENT_DATA_COMMAND_REJECTED);
10401059 }
1060 } else if (IsReplyToCommand(state, SMTP_COMMAND_RSET)) {
1061 if (reply_code == SMTP_REPLY_250) {
1062 SMTPTransactionComplete(state);
1063 }
10411064 } else {
10421065 /* we don't care for any other command for now */
1043 /* check if reply falls in the valid list of replies for SMTP. If not
1044 * decoder event */
10451066 }
10461067
10471068 /* if it is a multi-line reply, we need to move the index only once for all
13151336 SCMemcmpLowercase("rset", state->current_line, 4) == 0) {
13161337 // Resets chunk index in case of connection reuse
13171338 state->bdat_chunk_idx = 0;
1318 state->curr_tx->done = 1;
1339 state->current_command = SMTP_COMMAND_RSET;
13191340 } else {
13201341 state->current_command = SMTP_COMMAND_OTHER_CMD;
13211342 }
30483069 }
30493070
30503071 /*
3051 * \test Test smtp with just <LF> delimter instead of <CR><LF>.
3072 * \test Test smtp with just <LF> delimiter instead of <CR><LF>.
30523073 */
30533074 static int SMTPParserTest04(void)
30543075 {
4949 SMTP_DECODER_EVENT_MIME_LONG_HEADER_NAME,
5050 SMTP_DECODER_EVENT_MIME_LONG_HEADER_VALUE,
5151 SMTP_DECODER_EVENT_MIME_BOUNDARY_TOO_LONG,
52 SMTP_DECODER_EVENT_MIME_LONG_FILENAME,
5253
5354 /* Invalid behavior or content */
5455 SMTP_DECODER_EVENT_DUPLICATE_FIELDS,
508508 return 0;
509509 }
510510
511 /** \retval consumed bytes consumed or -1 on error */
511512 static int TlsDecodeHSCertificate(SSLState *ssl_state,
512513 const uint8_t * const initial_input,
513514 const uint32_t input_len)
517518 Asn1Generic *cert = NULL;
518519
519520 if (!(HAS_SPACE(3)))
520 return 1;
521 return 0;
521522
522523 uint32_t cert_chain_len = *input << 16 | *(input + 1) << 8 | *(input + 2);
523524 input += 3;
14351436 if (ssl_state->curr_connp->trec_pos + input_len >=
14361437 ssl_state->curr_connp->trec_len) {
14371438 ssl_state->curr_connp->trec_len =
1438 ssl_state->curr_connp->trec_len + 2 * input_len + 1;
1439 ssl_state->curr_connp->trec_pos + 2 * input_len + 1;
14391440 ptmp = SCRealloc(ssl_state->curr_connp->trec,
14401441 ssl_state->curr_connp->trec_len);
14411442
198198 static void TCPProtoDetectCheckBailConditions(ThreadVars *tv,
199199 Flow *f, TcpSession *ssn, Packet *p)
200200 {
201 if (ssn->state < TCP_ESTABLISHED) {
202 SCLogDebug("skip as long as TCP is not ESTABLISHED (TCP fast open)");
203 return;
204 }
205
201206 uint32_t size_ts = ssn->client.last_ack - ssn->client.isn - 1;
202207 uint32_t size_tc = ssn->server.last_ack - ssn->server.isn - 1;
203208 SCLogDebug("size_ts %u, size_tc %u", size_ts, size_tc);
3333 #define YAML_VERSION_MAJOR 1
3434 #define YAML_VERSION_MINOR 1
3535
36 /* The maximum level of recursion allowed while parsing the YAML
37 * file. */
38 #define RECURSION_LIMIT 128
39
3640 /* Sometimes we'll have to create a node name on the fly (integer
3741 * conversion, etc), so this is a default length to allocate that will
3842 * work most of the time. */
4347
4448 static char *conf_dirname = NULL;
4549
46 static int ConfYamlParse(yaml_parser_t *parser, ConfNode *parent, int inseq);
50 static int ConfYamlParse(yaml_parser_t *parser, ConfNode *parent, int inseq, int rlevel);
4751
4852 /* Configuration processing states. */
4953 enum conf_state {
143147
144148 yaml_parser_set_input_file(&parser, file);
145149
146 if (ConfYamlParse(&parser, parent, 0) != 0) {
150 if (ConfYamlParse(&parser, parent, 0, 0) != 0) {
147151 SCLogError(SC_ERR_CONF_YAML_ERROR,
148152 "Failed to include configuration file %s", filename);
149153 goto done;
169173 * \retval 0 on success, -1 on failure.
170174 */
171175 static int
172 ConfYamlParse(yaml_parser_t *parser, ConfNode *parent, int inseq)
176 ConfYamlParse(yaml_parser_t *parser, ConfNode *parent, int inseq, int rlevel)
173177 {
174178 ConfNode *node = parent;
175179 yaml_event_t event;
177181 int done = 0;
178182 int state = 0;
179183 int seq_idx = 0;
184 int retval = 0;
185
186 if (rlevel++ > RECURSION_LIMIT) {
187 SCLogError(SC_ERR_CONF_YAML_ERROR, "Recursion limit reached while parsing "
188 "configuration file, aborting.");
189 return -1;
190 }
180191
181192 while (!done) {
182193 if (!yaml_parser_parse(parser, &event)) {
183194 SCLogError(SC_ERR_CONF_YAML_ERROR,
184195 "Failed to parse configuration file at line %" PRIuMAX ": %s\n",
185196 (uintmax_t)parser->problem_mark.line, parser->problem);
186 return -1;
197 retval = -1;
198 break;
187199 }
188200
189201 if (event.type == YAML_DOCUMENT_START_EVENT) {
234246 else {
235247 seq_node = ConfNodeNew();
236248 if (unlikely(seq_node == NULL)) {
237 return -1;
249 goto fail;
238250 }
239251 seq_node->name = SCStrdup(sequence_node_name);
240252 if (unlikely(seq_node->name == NULL)) {
241253 SCFree(seq_node);
242 return -1;
254 goto fail;
243255 }
244256 seq_node->val = SCStrdup(value);
245257 if (unlikely(seq_node->val == NULL)) {
246258 SCFree(seq_node->name);
247 return -1;
259 goto fail;
248260 }
249261 }
250262 TAILQ_INSERT_TAIL(&parent->head, seq_node, next);
321333 }
322334 else if (event.type == YAML_SEQUENCE_START_EVENT) {
323335 SCLogDebug("event.type=YAML_SEQUENCE_START_EVENT; state=%d", state);
324 if (ConfYamlParse(parser, node, 1) != 0)
336 if (ConfYamlParse(parser, node, 1, rlevel) != 0)
325337 goto fail;
326338 node->is_seq = 1;
327339 state = CONF_KEY;
328340 }
329341 else if (event.type == YAML_SEQUENCE_END_EVENT) {
330342 SCLogDebug("event.type=YAML_SEQUENCE_END_EVENT; state=%d", state);
331 return 0;
343 done = 1;
332344 }
333345 else if (event.type == YAML_MAPPING_START_EVENT) {
334346 SCLogDebug("event.type=YAML_MAPPING_START_EVENT; state=%d", state);
347359 else {
348360 seq_node = ConfNodeNew();
349361 if (unlikely(seq_node == NULL)) {
350 return -1;
362 goto fail;
351363 }
352364 seq_node->name = SCStrdup(sequence_node_name);
353365 if (unlikely(seq_node->name == NULL)) {
354366 SCFree(seq_node);
355 return -1;
367 goto fail;
356368 }
357369 }
358370 seq_node->is_seq = 1;
359371 TAILQ_INSERT_TAIL(&node->head, seq_node, next);
360 if (ConfYamlParse(parser, seq_node, 0) != 0)
372 if (ConfYamlParse(parser, seq_node, 0, rlevel) != 0)
361373 goto fail;
362374 }
363375 else {
364 if (ConfYamlParse(parser, node, inseq) != 0)
376 if (ConfYamlParse(parser, node, inseq, rlevel) != 0)
365377 goto fail;
366378 }
367379 state = CONF_KEY;
381393
382394 fail:
383395 yaml_event_delete(&event);
384 return -1;
385 }
386
387 return 0;
396 retval = -1;
397 break;
398 }
399
400 rlevel--;
401 return retval;
388402 }
389403
390404 /**
436450 }
437451
438452 yaml_parser_set_input_file(&parser, infile);
439 ret = ConfYamlParse(&parser, root, 0);
453 ret = ConfYamlParse(&parser, root, 0, 0);
440454 yaml_parser_delete(&parser);
441455 fclose(infile);
442456
458472 exit(EXIT_FAILURE);
459473 }
460474 yaml_parser_set_input_string(&parser, (const unsigned char *)string, len);
461 ret = ConfYamlParse(&parser, root, 0);
475 ret = ConfYamlParse(&parser, root, 0, 0);
462476 yaml_parser_delete(&parser);
463477
464478 return ret;
524538 }
525539 }
526540 yaml_parser_set_input_file(&parser, infile);
527 ret = ConfYamlParse(&parser, root, 0);
541 ret = ConfYamlParse(&parser, root, 0, 0);
528542 yaml_parser_delete(&parser);
529543 fclose(infile);
530544
249249 if (gstats == NULL) {
250250 SCLogWarning(SC_ERR_STATS_LOG_GENERIC, "global stats config is missing. "
251251 "Stats enabled through legacy stats.log. "
252 "See %s%s/configuration/suricata-yaml.html#stats", DOC_URL, DOC_VERSION);
252 "See %s/configuration/suricata-yaml.html#stats", GetDocURL());
253253 }
254254
255255 const char *interval = ConfNodeLookupChildValue(stats, "interval");
0 /* Copyright (C) 2017-2019 Open Information Security Foundation
0 /* Copyright (C) 2017-2020 Open Information Security Foundation
11 *
22 * You can copy, redistribute or modify this Program under the terms of
33 * the GNU General Public License version 2 as published by the Free
3131 #include "util-print.h"
3232 #include "util-crypt.h" // encode base64
3333 #include "util-base64.h" // decode base64
34 #include "util-byte.h"
3435
3536 SCMutex sets_lock = SCMUTEX_INITIALIZER;
3637 static Dataset *sets = NULL;
3940
4041 static int DatasetAddwRep(Dataset *set, const uint8_t *data, const uint32_t data_len,
4142 DataRepType *rep);
43
44 static inline void DatasetUnlockData(THashData *d)
45 {
46 (void) THashDecrUsecnt(d);
47 THashDataUnlock(d);
48 }
4249
4350 enum DatasetTypes DatasetGetTypeFromString(const char *s)
4451 {
131138 return -1;
132139 }
133140
134 int v = atoi(ptrs[0]);
135 if (v < 0 || v > USHRT_MAX) {
136 SCLogDebug("v %d", v);
137 return -1;
138 }
139 SCLogDebug("v %d raw %s", v, ptrs[0]);
140
141 rep_out->value = v;
141 uint64_t v = 0;
142 size_t r = ByteExtractString(&v, 10, strlen(ptrs[0]), ptrs[0]);
143 if (r != strlen(ptrs[0]) || v > (uint64_t)USHRT_MAX) {
144 SCLogError(SC_ERR_INVALID_NUMERIC_VALUE,
145 "'%s' is not a valid reputation value (0-65535)", ptrs[0]);
146 return -1;
147 }
148 SCLogDebug("v %"PRIu64" raw %s", v, ptrs[0]);
149
150 rep_out->value = (uint16_t)v;
142151 return 0;
143152 }
144153
361370 {
362371 char path[PATH_MAX];
363372 struct stat st;
364 int ret;
365373
366374 if (PathIsAbsolute(in_path)) {
367375 strlcpy(path, in_path, sizeof(path));
370378 }
371379
372380 const char *data_dir = ConfigGetDataDirectory();
373 if ((ret = stat(data_dir, &st)) != 0) {
381 if (stat(data_dir, &st) != 0) {
374382 SCLogDebug("data-dir '%s': %s", data_dir, strerror(errno));
375383 return;
376384 }
378386 snprintf(path, sizeof(path), "%s/%s", data_dir, in_path); // TODO WINDOWS
379387
380388 if (type == TYPE_LOAD) {
381 if ((ret = stat(path, &st)) != 0) {
389 if (stat(path, &st) != 0) {
382390 SCLogDebug("path %s: %s", path, strerror(errno));
383391 if (!g_system) {
384392 snprintf(path, sizeof(path), "%s", in_path);
716724 StringType *found = rdata->data;
717725 rrep.found = true;
718726 rrep.rep = found->rep;
719 THashDataUnlock(rdata);
727 DatasetUnlockData(rdata);
720728 return rrep;
721729 }
722730 return rrep;
734742 memcpy(lookup.md5, data, data_len);
735743 THashData *rdata = THashLookupFromHash(set->hash, &lookup);
736744 if (rdata) {
737 THashDataUnlock(rdata);
745 DatasetUnlockData(rdata);
738746 return 1;
739747 }
740748 return 0;
758766 Md5Type *found = rdata->data;
759767 rrep.found = true;
760768 rrep.rep = found->rep;
761 THashDataUnlock(rdata);
769 DatasetUnlockData(rdata);
762770 return rrep;
763771 }
764772 return rrep;
776784 memcpy(lookup.sha256, data, data_len);
777785 THashData *rdata = THashLookupFromHash(set->hash, &lookup);
778786 if (rdata) {
779 THashDataUnlock(rdata);
787 DatasetUnlockData(rdata);
780788 return 1;
781789 }
782790 return 0;
800808 Sha256Type *found = rdata->data;
801809 rrep.found = true;
802810 rrep.rep = found->rep;
803 THashDataUnlock(rdata);
811 DatasetUnlockData(rdata);
804812 return rrep;
805813 }
806814 return rrep;
863871 .rep.value = 0 };
864872 struct THashDataGetResult res = THashGetFromHash(set->hash, &lookup);
865873 if (res.data) {
866 THashDataUnlock(res.data);
874 DatasetUnlockData(res.data);
867875 return res.is_new ? 1 : 0;
868876 }
869877 return -1;
884892 .rep = *rep };
885893 struct THashDataGetResult res = THashGetFromHash(set->hash, &lookup);
886894 if (res.data) {
887 THashDataUnlock(res.data);
895 DatasetUnlockData(res.data);
888896 return res.is_new ? 1 : 0;
889897 }
890898 return -1;
896904 return -1;
897905
898906 if (data_len != 16)
899 return -1;
907 return -2;
900908
901909 Md5Type lookup = { .rep.value = 0 };
902910 memcpy(lookup.md5, data, 16);
903911 struct THashDataGetResult res = THashGetFromHash(set->hash, &lookup);
904912 if (res.data) {
905 THashDataUnlock(res.data);
913 DatasetUnlockData(res.data);
906914 return res.is_new ? 1 : 0;
907915 }
908916 return -1;
915923 return -1;
916924
917925 if (data_len != 16)
918 return -1;
926 return -2;
919927
920928 Md5Type lookup = { .rep = *rep };
921929 memcpy(lookup.md5, data, 16);
922930 struct THashDataGetResult res = THashGetFromHash(set->hash, &lookup);
923931 if (res.data) {
924 THashDataUnlock(res.data);
932 DatasetUnlockData(res.data);
925933 return res.is_new ? 1 : 0;
926934 }
927935 return -1;
934942 return -1;
935943
936944 if (data_len != 32)
937 return 0;
945 return -2;
938946
939947 Sha256Type lookup = { .rep = *rep };
940948 memcpy(lookup.sha256, data, 32);
941949 struct THashDataGetResult res = THashGetFromHash(set->hash, &lookup);
942950 if (res.data) {
943 THashDataUnlock(res.data);
951 DatasetUnlockData(res.data);
944952 return res.is_new ? 1 : 0;
945953 }
946954 return -1;
952960 return -1;
953961
954962 if (data_len != 32)
955 return 0;
963 return -2;
956964
957965 Sha256Type lookup = { .rep.value = 0 };
958966 memcpy(lookup.sha256, data, 32);
959967 struct THashDataGetResult res = THashGetFromHash(set->hash, &lookup);
960968 if (res.data) {
961 THashDataUnlock(res.data);
969 DatasetUnlockData(res.data);
962970 return res.is_new ? 1 : 0;
963971 }
964972 return -1;
9971005 return -1;
9981006 }
9991007
1000 /** \brief add serialized data to set */
1008 /** \brief add serialized data to set
1009 * \retval int 1 added
1010 * \retval int 0 already in hash
1011 * \retval int -1 API error (not added)
1012 * \retval int -2 DATA error
1013 */
10011014 int DatasetAddSerialized(Dataset *set, const char *string)
10021015 {
10031016 if (set == NULL)
10081021 uint8_t decoded[strlen(string)];
10091022 uint32_t len = DecodeBase64(decoded, (const uint8_t *)string, strlen(string), 1);
10101023 if (len == 0) {
1011 return -1;
1024 return -2;
10121025 }
10131026
10141027 return DatasetAddString(set, decoded, len);
10151028 }
10161029 case DATASET_TYPE_MD5: {
10171030 if (strlen(string) != 32)
1018 return -1;
1031 return -2;
10191032 uint8_t hash[16];
10201033 if (HexToRaw((const uint8_t *)string, 32, hash, sizeof(hash)) < 0)
1021 return -1;
1034 return -2;
10221035 return DatasetAddMd5(set, hash, 16);
10231036 }
10241037 case DATASET_TYPE_SHA256: {
10251038 if (strlen(string) != 64)
1026 return -1;
1039 return -2;
10271040 uint8_t hash[32];
10281041 if (HexToRaw((const uint8_t *)string, 64, hash, sizeof(hash)) < 0)
1029 return -1;
1042 return -2;
10301043 return DatasetAddSha256(set, hash, 32);
10311044 }
10321045 }
10331046 return -1;
10341047 }
1048
1049 /**
1050 * \retval 1 data was removed from the hash
1051 * \retval 0 data not removed (busy)
1052 * \retval -1 data not found
1053 */
1054 static int DatasetRemoveString(Dataset *set, const uint8_t *data, const uint32_t data_len)
1055 {
1056 if (set == NULL)
1057 return -1;
1058
1059 StringType lookup = { .ptr = (uint8_t *)data, .len = data_len,
1060 .rep.value = 0 };
1061 return THashRemoveFromHash(set->hash, &lookup);
1062 }
1063
1064 static int DatasetRemoveMd5(Dataset *set, const uint8_t *data, const uint32_t data_len)
1065 {
1066 if (set == NULL)
1067 return -1;
1068
1069 if (data_len != 16)
1070 return -2;
1071
1072 Md5Type lookup = { .rep.value = 0 };
1073 memcpy(lookup.md5, data, 16);
1074 return THashRemoveFromHash(set->hash, &lookup);
1075 }
1076
1077 static int DatasetRemoveSha256(Dataset *set, const uint8_t *data, const uint32_t data_len)
1078 {
1079 if (set == NULL)
1080 return -1;
1081
1082 if (data_len != 32)
1083 return -2;
1084
1085 Sha256Type lookup = { .rep.value = 0 };
1086 memcpy(lookup.sha256, data, 32);
1087 return THashRemoveFromHash(set->hash, &lookup);
1088 }
1089
1090 /** \brief remove serialized data from set
1091 * \retval int 1 removed
1092 * \retval int 0 found but busy (not removed)
1093 * \retval int -1 API error (not removed)
1094 * \retval int -2 DATA error */
1095 int DatasetRemoveSerialized(Dataset *set, const char *string)
1096 {
1097 if (set == NULL)
1098 return -1;
1099
1100 switch (set->type) {
1101 case DATASET_TYPE_STRING: {
1102 uint8_t decoded[strlen(string)];
1103 uint32_t len = DecodeBase64(decoded, (const uint8_t *)string, strlen(string), 1);
1104 if (len == 0) {
1105 return -2;
1106 }
1107
1108 return DatasetRemoveString(set, decoded, len);
1109 }
1110 case DATASET_TYPE_MD5: {
1111 if (strlen(string) != 32)
1112 return -2;
1113 uint8_t hash[16];
1114 if (HexToRaw((const uint8_t *)string, 32, hash, sizeof(hash)) < 0)
1115 return -2;
1116 return DatasetRemoveMd5(set, hash, 16);
1117 }
1118 case DATASET_TYPE_SHA256: {
1119 if (strlen(string) != 64)
1120 return -2;
1121 uint8_t hash[32];
1122 if (HexToRaw((const uint8_t *)string, 64, hash, sizeof(hash)) < 0)
1123 return -2;
1124 return DatasetRemoveSha256(set, hash, 32);
1125 }
1126 }
1127 return -1;
1128 }
5353 int DatasetLookup(Dataset *set, const uint8_t *data, const uint32_t data_len);
5454 DataRepResultType DatasetLookupwRep(Dataset *set, const uint8_t *data, const uint32_t data_len,
5555 const DataRepType *rep);
56
5657 int DatasetAddSerialized(Dataset *set, const char *string);
58 int DatasetRemoveSerialized(Dataset *set, const char *string);
5759
5860 #endif /* __DATASETS_H__ */
0 /* Copyright (C) 2015 Open Information Security Foundation
0 /* Copyright (C) 2020 Open Information Security Foundation
11 *
22 * You can copy, redistribute or modify this Program under the terms of
33 * the GNU General Public License version 2 as published by the Free
2626 *
2727 * \author Victor Julien <victor@inliniac.net>
2828 *
29 * Decodes ERSPAN
29 * Decodes ERSPAN Types I and II
3030 */
3131
3232 #include "suricata-common.h"
3939 #include "util-debug.h"
4040
4141 /**
42 * \brief Function to decode ERSPAN packets
42 * \brief Functions to decode ERSPAN Type I and II packets
4343 */
4444
45 int DecodeERSPAN(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, const uint8_t *pkt, uint32_t len, PacketQueue *pq)
45 bool g_erspan_typeI_enabled = false;
46
47 void DecodeERSPANConfig(void)
48 {
49 int enabled = 0;
50 if (ConfGetBool("decoder.erspan.typeI.enabled", &enabled) == 1) {
51 g_erspan_typeI_enabled = (enabled == 1);
52 }
53 SCLogDebug("ERSPAN Type I decode support %s", g_erspan_typeI_enabled ? "enabled" : "disabled");
54 }
55
56 /**
57 * \brief ERSPAN Type I
58 */
59 int DecodeERSPANTypeI(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p,
60 const uint8_t *pkt, uint32_t len, PacketQueue *pq)
61 {
62 if (unlikely(!g_erspan_typeI_enabled))
63 return TM_ECODE_FAILED;
64
65 StatsIncr(tv, dtv->counter_erspan);
66
67 return DecodeEthernet(tv, dtv, p, pkt, len, pq);
68 }
69
70 /**
71 * \brief ERSPAN Type II
72 */
73 int DecodeERSPANTypeII(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, const uint8_t *pkt, uint32_t len, PacketQueue *pq)
4674 {
4775 StatsIncr(tv, dtv->counter_erspan);
4876
3333 uint32_t padding;
3434 } __attribute__((__packed__)) ErspanHdr;
3535
36 void DecodeERSPANConfig(void);
3637 #endif /* __DECODE_ERSPAN_H__ */
0 /* Copyright (C) 2007-2013 Open Information Security Foundation
0 /* Copyright (C) 2007-2020 Open Information Security Foundation
11 *
22 * You can copy, redistribute or modify this Program under the terms of
33 * the GNU General Public License version 2 as published by the Free
6565 {
6666 case GRE_VERSION_0:
6767
68 /* GRE version 0 doenst support the fields below RFC 1701 */
68 /* GRE version 0 doesn't support the fields below RFC 1701 */
6969
7070 /**
7171 * \todo We need to make sure this does not allow bypassing
129129
130130 case GRE_VERSION_1:
131131
132 /* GRE version 1 doenst support the fields below RFC 1701 */
132 /* GRE version 1 doesn't support the fields below RFC 1701 */
133133
134134 /**
135135 * \todo We need to make sure this does not allow bypassing
251251 case ETHERNET_TYPE_ERSPAN:
252252 {
253253 if (pq != NULL) {
254 // Determine if it's Type I or Type II based on the flags in the GRE header.
255 // Type I: 0|0|0|0|0|00000|000000000|00000
256 // Type II: 0|0|0|1|0|00000|000000000|00000
257 // Seq
254258 Packet *tp = PacketTunnelPktSetup(tv, dtv, p, pkt + header_len,
255 len - header_len, DECODE_TUNNEL_ERSPAN, pq);
259 len - header_len,
260 GRE_FLAG_ISSET_SQ(p->greh) == 0 ?
261 DECODE_TUNNEL_ERSPANI :
262 DECODE_TUNNEL_ERSPANII,
263 pq);
256264 if (tp != NULL) {
257265 PKT_SET_SRC(tp, PKT_SRC_DECODER_GRE);
258266 PacketEnqueue(pq,tp);
523523 /* do the actual decoding */
524524 if (unlikely(DecodeIPV4Packet (p, pkt, len) < 0)) {
525525 SCLogDebug("decoding IPv4 packet failed");
526 p->ip4h = NULL;
526 CLEAR_IPV4_PACKET((p));
527527 return TM_ECODE_FAILED;
528528 }
529529 p->proto = IPV4_GET_IPPROTO(p);
588588 /* do the actual decoding */
589589 int ret = DecodeIPV6Packet (tv, dtv, p, pkt, len);
590590 if (unlikely(ret < 0)) {
591 p->ip6h = NULL;
591 CLEAR_IPV6_PACKET(p);
592592 return TM_ECODE_FAILED;
593593 }
594594
6464 StatsIncr(tv, dtv->counter_sctp);
6565
6666 if (unlikely(DecodeSCTPPacket(tv, p,pkt,len) < 0)) {
67 p->sctph = NULL;
67 CLEAR_SCTP_PACKET(p);
6868 return TM_ECODE_FAILED;
6969 }
7070
237237
238238 if (unlikely(DecodeTCPPacket(tv, p, pkt,len) < 0)) {
239239 SCLogDebug("invalid TCP packet");
240 p->tcph = NULL;
240 CLEAR_TCP_PACKET(p);
241241 return TM_ECODE_FAILED;
242242 }
243243
0 /* Copyright (C) 2012 Open Information Security Foundation
0 /* Copyright (C) 2012-2020 Open Information Security Foundation
11 *
22 * You can copy, redistribute or modify this Program under the terms of
33 * the GNU General Public License version 2 as published by the Free
3737 #include "decode-teredo.h"
3838 #include "util-debug.h"
3939 #include "conf.h"
40
41 #define TEREDO_ORIG_INDICATION_LENGTH 8
40 #include "detect-engine-port.h"
41
42 #define TEREDO_ORIG_INDICATION_LENGTH 8
4243
4344 static bool g_teredo_enabled = true;
45 static int g_teredo_ports[4] = { -1, -1, -1, -1 };
46 static int g_teredo_ports_cnt = 0;
47 static bool g_teredo_ports_any = true;
48
49 bool DecodeTeredoEnabledForPort(const uint16_t sp, const uint16_t dp)
50 {
51 SCLogDebug("ports %u->%u ports %d %d %d %d", sp, dp,
52 g_teredo_ports[0], g_teredo_ports[1],
53 g_teredo_ports[2], g_teredo_ports[3]);
54
55 if (g_teredo_enabled) {
56 /* no port config means we are enabled for all ports */
57 if (g_teredo_ports_any) {
58 return true;
59 }
60
61 for (int i = 0; i < g_teredo_ports_cnt; i++) {
62 if (g_teredo_ports[i] == -1)
63 return false;
64 const int port = g_teredo_ports[i];
65 if (port == (const int)sp ||
66 port == (const int)dp)
67 return true;
68 }
69 }
70 return false;
71 }
72
73 static void DecodeTeredoConfigPorts(const char *pstr)
74 {
75 SCLogDebug("parsing \'%s\'", pstr);
76
77 if (strcmp(pstr, "any") == 0) {
78 g_teredo_ports_any = true;
79 return;
80 }
81
82 DetectPort *head = NULL;
83 DetectPortParse(NULL, &head, pstr);
84
85 g_teredo_ports_any = false;
86 g_teredo_ports_cnt = 0;
87 for (DetectPort *p = head; p != NULL; p = p->next) {
88 if (g_teredo_ports_cnt >= 4) {
89 SCLogWarning(SC_ERR_INVALID_YAML_CONF_ENTRY,
90 "only 4 Teredo ports can be defined");
91 break;
92 }
93 g_teredo_ports[g_teredo_ports_cnt++] = (int)p->port;
94 }
95 DetectPortCleanupList(NULL, head);
96 }
4497
4598 void DecodeTeredoConfig(void)
4699 {
50103 g_teredo_enabled = true;
51104 } else {
52105 g_teredo_enabled = false;
106 }
107 }
108 if (g_teredo_enabled) {
109 ConfNode *node = ConfGetNode("decoder.teredo.ports");
110 if (node && node->val) {
111 DecodeTeredoConfigPorts(node->val);
53112 }
54113 }
55114 }
0 /* Copyright (C) 2012 Open Information Security Foundation
0 /* Copyright (C) 2012-2020 Open Information Security Foundation
11 *
22 * You can copy, redistribute or modify this Program under the terms of
33 * the GNU General Public License version 2 as published by the Free
2020 int DecodeTeredo(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p,
2121 const uint8_t *pkt, uint16_t len, PacketQueue *pq);
2222 void DecodeTeredoConfig(void);
23 bool DecodeTeredoEnabledForPort(const uint16_t sp, const uint16_t dp);
2324
2425 #endif
0 /* Copyright (C) 2007-2010 Open Information Security Foundation
0 /* Copyright (C) 2007-2020 Open Information Security Foundation
11 *
22 * You can copy, redistribute or modify this Program under the terms of
33 * the GNU General Public License version 2 as published by the Free
7676 StatsIncr(tv, dtv->counter_udp);
7777
7878 if (unlikely(DecodeUDPPacket(tv, p, pkt,len) < 0)) {
79 p->udph = NULL;
79 CLEAR_UDP_PACKET(p);
8080 return TM_ECODE_FAILED;
8181 }
8282
8383 SCLogDebug("UDP sp: %" PRIu32 " -> dp: %" PRIu32 " - HLEN: %" PRIu32 " LEN: %" PRIu32 "",
8484 UDP_GET_SRC_PORT(p), UDP_GET_DST_PORT(p), UDP_HEADER_LEN, p->payload_len);
8585
86 if (unlikely(DecodeTeredo(tv, dtv, p, p->payload, p->payload_len, pq) == TM_ECODE_OK)) {
86 if (DecodeTeredoEnabledForPort(p->sp, p->dp) &&
87 likely(DecodeTeredo(tv, dtv, p, p->payload, p->payload_len, pq) == TM_ECODE_OK)) {
8788 /* Here we have a Teredo packet and don't need to handle app
8889 * layer */
8990 FlowSetupPacket(p);
2727 * example we have DecodeIPV4() for IPv4 and DecodePPP() for
2828 * PPP.
2929 *
30 * These functions have all a pkt and and a len argument which
30 * These functions have all a pkt and a len argument which
3131 * are respectively a pointer to the protocol data and the length
3232 * of this protocol data.
3333 *
8787 return DecodeVLAN(tv, dtv, p, pkt, len, pq);
8888 case DECODE_TUNNEL_ETHERNET:
8989 return DecodeEthernet(tv, dtv, p, pkt, len, pq);
90 case DECODE_TUNNEL_ERSPAN:
91 return DecodeERSPAN(tv, dtv, p, pkt, len, pq);
90 case DECODE_TUNNEL_ERSPANII:
91 return DecodeERSPANTypeII(tv, dtv, p, pkt, len, pq);
92 case DECODE_TUNNEL_ERSPANI:
93 return DecodeERSPANTypeI(tv, dtv, p, pkt, len, pq);
9294 default:
9395 SCLogDebug("FIXME: DecodeTunnel: protocol %" PRIu32 " not supported.", proto);
9496 break;
109111 * \brief Finalize decoding of a packet
110112 *
111113 * This function needs to be call at the end of decode
112 * functions when decoding has been succesful.
114 * functions when decoding has been successful.
113115 *
114116 */
115117 void PacketDecodeFinalize(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p)
286288 SCReturnPtr(NULL, "Packet");
287289 }
288290
289 /* copy packet and set lenght, proto */
291 /* copy packet and set length, proto */
290292 PacketCopyData(p, pkt, len);
291293 p->recursion_level = parent->recursion_level + 1;
292294 p->ts.tv_sec = parent->ts.tv_sec;
383385
384386 /**
385387 * \brief inform defrag "parent" that a pseudo packet is
386 * now assosiated to it.
388 * now associated to it.
387389 */
388390 void PacketDefragPktSetupParent(Packet *parent)
389391 {
645647 }
646648
647649 /**
648 * \brief Set data for Packet and set length when zeo copy is used
650 * \brief Set data for Packet and set length when zero copy is used
649651 *
650652 * \param Pointer to the Packet to modify
651653 * \param Pointer to the data
729731 {
730732 DecodeTeredoConfig();
731733 DecodeVXLANConfig();
734 DecodeERSPANConfig();
732735 }
733736
734737 /**
0 /* Copyright (C) 2007-2013 Open Information Security Foundation
0 /* Copyright (C) 2007-2020 Open Information Security Foundation
11 *
22 * You can copy, redistribute or modify this Program under the terms of
33 * the GNU General Public License version 2 as published by the Free
160160 (a)->addr_data32[3] = 0; \
161161 } while (0)
162162
163 /* Set the IPv6 addressesinto the Addrs of the Packet.
163 /* Set the IPv6 addresses into the Addrs of the Packet.
164164 * Make sure p->ip6h is initialized and validated. */
165165 #define SET_IPV6_SRC_ADDR(p, a) do { \
166166 (a)->family = AF_INET6; \
385385
386386 #endif /* PROFILING */
387387
388 /* forward declartion since Packet struct definition requires this */
388 /* forward declaration since Packet struct definition requires this */
389389 struct PacketQueue_;
390390
391391 /* sizes of the members:
888888
889889 enum DecodeTunnelProto {
890890 DECODE_TUNNEL_ETHERNET,
891 DECODE_TUNNEL_ERSPAN,
891 DECODE_TUNNEL_ERSPANII,
892 DECODE_TUNNEL_ERSPANI,
892893 DECODE_TUNNEL_VLAN,
893894 DECODE_TUNNEL_IPV4,
894895 DECODE_TUNNEL_IPV6,
942943 int DecodeVXLAN(ThreadVars *, DecodeThreadVars *, Packet *, const uint8_t *, uint32_t, PacketQueue *);
943944 int DecodeMPLS(ThreadVars *, DecodeThreadVars *, Packet *, const uint8_t *, uint32_t, PacketQueue *);
944945 int DecodeERSPAN(ThreadVars *, DecodeThreadVars *, Packet *, const uint8_t *, uint32_t, PacketQueue *);
946 int DecodeERSPANTypeII(ThreadVars *, DecodeThreadVars *, Packet *, const uint8_t *, uint32_t, PacketQueue *);
947 int DecodeERSPANTypeI(ThreadVars *, DecodeThreadVars *, Packet *, const uint8_t *, uint32_t, PacketQueue *);
945948 int DecodeTEMPLATE(ThreadVars *, DecodeThreadVars *, Packet *, const uint8_t *, uint32_t, PacketQueue *);
946949
947950 #ifdef UNITTESTS
10881091 #define PKT_ALLOC (1<<3) /**< Packet was alloc'd this run, needs to be freed */
10891092 #define PKT_HAS_TAG (1<<4) /**< Packet has matched a tag */
10901093 #define PKT_STREAM_ADD (1<<5) /**< Packet payload was added to reassembled stream */
1091 #define PKT_STREAM_EST (1<<6) /**< Packet is part of establised stream */
1094 #define PKT_STREAM_EST (1<<6) /**< Packet is part of established stream */
10921095 #define PKT_STREAM_EOF (1<<7) /**< Stream is in eof state */
10931096 #define PKT_HAS_FLOW (1<<8)
10941097 #define PKT_PSEUDO_STREAM_END (1<<9) /**< Pseudo packet to end the stream */
6666 {
6767 sigmatch_table[DETECT_AL_APP_LAYER_EVENT].name = "app-layer-event";
6868 sigmatch_table[DETECT_AL_APP_LAYER_EVENT].desc = "match on events generated by the App Layer Parsers and the protocol detection engine";
69 sigmatch_table[DETECT_AL_APP_LAYER_EVENT].url = DOC_URL DOC_VERSION "/rules/app-layer.html#app-layer-event";
69 sigmatch_table[DETECT_AL_APP_LAYER_EVENT].url = "/rules/app-layer.html#app-layer-event";
7070 sigmatch_table[DETECT_AL_APP_LAYER_EVENT].Match =
7171 DetectAppLayerEventPktMatch;
7272 sigmatch_table[DETECT_AL_APP_LAYER_EVENT].Setup = DetectAppLayerEventSetupP1;
258258 {
259259 sigmatch_table[DETECT_AL_APP_LAYER_PROTOCOL].name = "app-layer-protocol";
260260 sigmatch_table[DETECT_AL_APP_LAYER_PROTOCOL].desc = "match on the detected app-layer protocol";
261 sigmatch_table[DETECT_AL_APP_LAYER_PROTOCOL].url = DOC_URL DOC_VERSION "/rules/app-layer.html#app-layer-protocol";
261 sigmatch_table[DETECT_AL_APP_LAYER_PROTOCOL].url = "/rules/app-layer.html#app-layer-protocol";
262262 sigmatch_table[DETECT_AL_APP_LAYER_PROTOCOL].Match =
263263 DetectAppLayerProtocolPacketMatch;
264264 sigmatch_table[DETECT_AL_APP_LAYER_PROTOCOL].Setup =
3232 sigmatch_table[DETECT_BASE64_DATA].desc =
3333 "Content match base64 decoded data.";
3434 sigmatch_table[DETECT_BASE64_DATA].url =
35 DOC_URL DOC_VERSION "/rules/base64-keywords.html#base64-data";
35 "/rules/base64-keywords.html#base64-data";
3636 sigmatch_table[DETECT_BASE64_DATA].Setup = DetectBase64DataSetup;
3737 sigmatch_table[DETECT_BASE64_DATA].RegisterTests =
3838 DetectBase64DataRegisterTests;
4141 sigmatch_table[DETECT_BASE64_DECODE].desc =
4242 "Decodes base64 encoded data.";
4343 sigmatch_table[DETECT_BASE64_DECODE].url =
44 DOC_URL DOC_VERSION "/rules/base64-keywords.html#base64-decode";
44 "/rules/base64-keywords.html#base64-decode";
4545 sigmatch_table[DETECT_BASE64_DECODE].Setup = DetectBase64DecodeSetup;
4646 sigmatch_table[DETECT_BASE64_DECODE].Free = DetectBase64DecodeFree;
4747 sigmatch_table[DETECT_BASE64_DECODE].RegisterTests =
0 /* Copyright (C) 2017 Open Information Security Foundation
0 /* Copyright (C) 2017-2020 Open Information Security Foundation
11 *
22 * You can copy, redistribute or modify this Program under the terms of
33 * the GNU General Public License version 2 as published by the Free
5050 {
5151 sigmatch_table[DETECT_BSIZE].name = "bsize";
5252 sigmatch_table[DETECT_BSIZE].desc = "match on the length of a buffer";
53 sigmatch_table[DETECT_BSIZE].url = DOC_URL DOC_VERSION "/rules/payload-keywords.html#bsize";
53 sigmatch_table[DETECT_BSIZE].url = "/rules/payload-keywords.html#bsize";
5454 sigmatch_table[DETECT_BSIZE].Match = NULL;
5555 sigmatch_table[DETECT_BSIZE].Setup = DetectBsizeSetup;
5656 sigmatch_table[DETECT_BSIZE].Free = DetectBsizeFree;
176176 char str1[11], *p = str1;
177177 memset(str1, 0, sizeof(str1));
178178 while (*str && isdigit(*str)) {
179 if (p - str1 >= (int)sizeof(str1))
179 if (p - str1 >= ((int)sizeof(str1) - 1))
180180 return NULL;
181181 *p++ = *str++;
182182 }
223223 p = str2;
224224 memset(str2, 0, sizeof(str2));
225225 while (*str && isdigit(*str)) {
226 if (p - str2 >= (int)sizeof(str2))
226 if (p - str2 >= ((int)sizeof(str2) - 1))
227227 return NULL;
228228 *p++ = *str++;
229229 }
6161 {
6262 sigmatch_table[DETECT_BYPASS].name = "bypass";
6363 sigmatch_table[DETECT_BYPASS].desc = "call the bypass callback when the match of a sig is complete";
64 sigmatch_table[DETECT_BYPASS].url = DOC_URL DOC_VERSION "/rules/bypass-keyword.html";
64 sigmatch_table[DETECT_BYPASS].url = "/rules/bypass-keyword.html";
6565 sigmatch_table[DETECT_BYPASS].Match = DetectBypassMatch;
6666 sigmatch_table[DETECT_BYPASS].Setup = DetectBypassSetup;
6767 sigmatch_table[DETECT_BYPASS].Free = NULL;
9999 {
100100 sigmatch_table[DETECT_BYTE_EXTRACT].name = "byte_extract";
101101 sigmatch_table[DETECT_BYTE_EXTRACT].desc = "extract <num of bytes> at a particular <offset> and store it in <var_name>";
102 sigmatch_table[DETECT_BYTE_EXTRACT].url = DOC_URL DOC_VERSION "/rules/payload-keywords.html#byte-extract";
102 sigmatch_table[DETECT_BYTE_EXTRACT].url = "/rules/payload-keywords.html#byte-extract";
103103 sigmatch_table[DETECT_BYTE_EXTRACT].Match = NULL;
104104 sigmatch_table[DETECT_BYTE_EXTRACT].Setup = DetectByteExtractSetup;
105105 sigmatch_table[DETECT_BYTE_EXTRACT].Free = DetectByteExtractFree;
7070 {
7171 sigmatch_table[DETECT_BYTEJUMP].name = "byte_jump";
7272 sigmatch_table[DETECT_BYTEJUMP].desc = "allow the ability to select a <num of bytes> from an <offset> and move the detection pointer to that position";
73 sigmatch_table[DETECT_BYTEJUMP].url = DOC_URL DOC_VERSION "/rules/payload-keywords.html#byte-jump";
73 sigmatch_table[DETECT_BYTEJUMP].url = "/rules/payload-keywords.html#byte-jump";
7474 sigmatch_table[DETECT_BYTEJUMP].Match = DetectBytejumpMatch;
7575 sigmatch_table[DETECT_BYTEJUMP].Setup = DetectBytejumpSetup;
7676 sigmatch_table[DETECT_BYTEJUMP].Free = DetectBytejumpFree;
7171 {
7272 sigmatch_table[DETECT_BYTETEST].name = "byte_test";
7373 sigmatch_table[DETECT_BYTETEST].desc = "extract <num of bytes> and perform an operation selected with <operator> against the value in <test value> at a particular <offset>";
74 sigmatch_table[DETECT_BYTETEST].url = DOC_URL DOC_VERSION "/rules/payload-keywords.html#byte-test";
74 sigmatch_table[DETECT_BYTETEST].url = "/rules/payload-keywords.html#byte-test";
7575 sigmatch_table[DETECT_BYTETEST].Match = DetectBytetestMatch;
7676 sigmatch_table[DETECT_BYTETEST].Setup = DetectBytetestSetup;
7777 sigmatch_table[DETECT_BYTETEST].Free = DetectBytetestFree;
5151 SCEnter();
5252 sigmatch_table[DETECT_CIPSERVICE].name = "cip_service"; //rule keyword
5353 sigmatch_table[DETECT_CIPSERVICE].desc = "match on CIP Service";
54 sigmatch_table[DETECT_CIPSERVICE].url = DOC_URL DOC_VERSION "/rules/enip-keyword.html#enip-cip-keywords";
54 sigmatch_table[DETECT_CIPSERVICE].url = "/rules/enip-keyword.html#enip-cip-keywords";
5555 sigmatch_table[DETECT_CIPSERVICE].Match = NULL;
5656 sigmatch_table[DETECT_CIPSERVICE].Setup = DetectCipServiceSetup;
5757 sigmatch_table[DETECT_CIPSERVICE].Free = DetectCipServiceFree;
306306 sigmatch_table[DETECT_ENIPCOMMAND].name = "enip_command"; //rule keyword
307307 sigmatch_table[DETECT_ENIPCOMMAND].desc
308308 = "rules for detecting EtherNet/IP command";
309 sigmatch_table[DETECT_ENIPCOMMAND].url = DOC_URL DOC_VERSION "/rules/enip-keyword.html#enip-cip-keywords";
309 sigmatch_table[DETECT_ENIPCOMMAND].url = "/rules/enip-keyword.html#enip-cip-keywords";
310310 sigmatch_table[DETECT_ENIPCOMMAND].Match = NULL;
311311 sigmatch_table[DETECT_ENIPCOMMAND].Setup = DetectEnipCommandSetup;
312312 sigmatch_table[DETECT_ENIPCOMMAND].Free = DetectEnipCommandFree;
5050 {
5151 sigmatch_table[DETECT_CLASSTYPE].name = "classtype";
5252 sigmatch_table[DETECT_CLASSTYPE].desc = "information about the classification of rules and alerts";
53 sigmatch_table[DETECT_CLASSTYPE].url = DOC_URL DOC_VERSION "/rules/meta.html#classtype";
53 sigmatch_table[DETECT_CLASSTYPE].url = "/rules/meta.html#classtype";
5454 sigmatch_table[DETECT_CLASSTYPE].Setup = DetectClasstypeSetup;
5555 sigmatch_table[DETECT_CLASSTYPE].RegisterTests = DetectClasstypeRegisterTests;
5656
5555 {
5656 sigmatch_table[DETECT_CONTENT].name = "content";
5757 sigmatch_table[DETECT_CONTENT].desc = "match on payload content";
58 sigmatch_table[DETECT_CONTENT].url = DOC_URL DOC_VERSION "/rules/payload-keywords.html#content";
58 sigmatch_table[DETECT_CONTENT].url = "/rules/payload-keywords.html#content";
5959 sigmatch_table[DETECT_CONTENT].Match = NULL;
6060 sigmatch_table[DETECT_CONTENT].Setup = DetectContentSetup;
6161 sigmatch_table[DETECT_CONTENT].Free = DetectContentFree;
5151 {
5252 sigmatch_table[DETECT_DATAREP].name = "datarep";
5353 sigmatch_table[DETECT_DATAREP].desc = "operate on datasets (experimental)";
54 sigmatch_table[DETECT_DATAREP].url = DOC_URL DOC_VERSION "/rules/dataset-keywords.html#datarep";
54 sigmatch_table[DETECT_DATAREP].url = "/rules/dataset-keywords.html#datarep";
5555 sigmatch_table[DETECT_DATAREP].Setup = DetectDatarepSetup;
5656 sigmatch_table[DETECT_DATAREP].Free = DetectDatarepFree;
5757
5050 {
5151 sigmatch_table[DETECT_DATASET].name = "dataset";
5252 sigmatch_table[DETECT_DATASET].desc = "match sticky buffer against datasets (experimental)";
53 sigmatch_table[DETECT_DATASET].url = DOC_URL DOC_VERSION "/rules/dataset-keywords.html#dataset";
53 sigmatch_table[DETECT_DATASET].url = "/rules/dataset-keywords.html#dataset";
5454 sigmatch_table[DETECT_DATASET].Setup = DetectDatasetSetup;
5555 sigmatch_table[DETECT_DATASET].Free = DetectDatasetFree;
5656
4747 {
4848 sigmatch_table[DETECT_DEPTH].name = "depth";
4949 sigmatch_table[DETECT_DEPTH].desc = "designate how many bytes from the beginning of the payload will be checked";
50 sigmatch_table[DETECT_DEPTH].url = DOC_URL DOC_VERSION "/rules/payload-keywords.html#depth";
50 sigmatch_table[DETECT_DEPTH].url = "/rules/payload-keywords.html#depth";
5151 sigmatch_table[DETECT_DEPTH].Match = NULL;
5252 sigmatch_table[DETECT_DEPTH].Setup = DetectDepthSetup;
5353 sigmatch_table[DETECT_DEPTH].Free = NULL;
5555
5656 sigmatch_table[DETECT_STARTS_WITH].name = "startswith";
5757 sigmatch_table[DETECT_STARTS_WITH].desc = "pattern must be at the start of a buffer (same as 'depth:<pattern len>')";
58 sigmatch_table[DETECT_STARTS_WITH].url = DOC_URL DOC_VERSION "/rules/payload-keywords.html#startswith";
58 sigmatch_table[DETECT_STARTS_WITH].url = "/rules/payload-keywords.html#startswith";
5959 sigmatch_table[DETECT_STARTS_WITH].Setup = DetectStartsWithSetup;
6060 sigmatch_table[DETECT_STARTS_WITH].flags |= SIGMATCH_NOOPT;
6161 }
6363 {
6464 sigmatch_table[DETECT_DETECTION_FILTER].name = "detection_filter";
6565 sigmatch_table[DETECT_DETECTION_FILTER].desc = "alert on every match after a threshold has been reached";
66 sigmatch_table[DETECT_DETECTION_FILTER].url = DOC_URL DOC_VERSION "/rules/thresholding.html#detection-filter";
66 sigmatch_table[DETECT_DETECTION_FILTER].url = "/rules/thresholding.html#detection-filter";
6767 sigmatch_table[DETECT_DETECTION_FILTER].Match = DetectDetectionFilterMatch;
6868 sigmatch_table[DETECT_DETECTION_FILTER].Setup = DetectDetectionFilterSetup;
6969 sigmatch_table[DETECT_DETECTION_FILTER].Free = DetectDetectionFilterFree;
5353 {
5454 sigmatch_table[DETECT_DISTANCE].name = "distance";
5555 sigmatch_table[DETECT_DISTANCE].desc = "indicates a relation between this content keyword and the content preceding it";
56 sigmatch_table[DETECT_DISTANCE].url = DOC_URL DOC_VERSION "/rules/payload-keywords.html#distance";
56 sigmatch_table[DETECT_DISTANCE].url = "/rules/payload-keywords.html#distance";
5757 sigmatch_table[DETECT_DISTANCE].Match = NULL;
5858 sigmatch_table[DETECT_DISTANCE].Setup = DetectDistanceSetup;
5959 sigmatch_table[DETECT_DISTANCE].Free = NULL;
492492 sigmatch_table[DETECT_AL_DNP3FUNC].name = "dnp3_func";
493493 sigmatch_table[DETECT_AL_DNP3FUNC].alias = "dnp3.func";
494494 sigmatch_table[DETECT_AL_DNP3FUNC].desc = "match on the application function code found in DNP3 request and responses";
495 sigmatch_table[DETECT_AL_DNP3FUNC].url = DOC_URL DOC_VERSION "/rules/dnp3-keywords.html#dnp3-func";
495 sigmatch_table[DETECT_AL_DNP3FUNC].url = "/rules/dnp3-keywords.html#dnp3-func";
496496 sigmatch_table[DETECT_AL_DNP3FUNC].Match = NULL;
497497 sigmatch_table[DETECT_AL_DNP3FUNC].AppLayerTxMatch = DetectDNP3FuncMatch;
498498 sigmatch_table[DETECT_AL_DNP3FUNC].Setup = DetectDNP3FuncSetup;
510510 sigmatch_table[DETECT_AL_DNP3IND].name = "dnp3_ind";
511511 sigmatch_table[DETECT_AL_DNP3IND].alias = "dnp3.ind";
512512 sigmatch_table[DETECT_AL_DNP3IND].desc = "match on the DNP3 internal indicator flags in the response application header";
513 sigmatch_table[DETECT_AL_DNP3IND].url = DOC_URL DOC_VERSION "/rules/dnp3-keywords.html#dnp3-ind";
513 sigmatch_table[DETECT_AL_DNP3IND].url = "/rules/dnp3-keywords.html#dnp3-ind";
514514 sigmatch_table[DETECT_AL_DNP3IND].Match = NULL;
515515 sigmatch_table[DETECT_AL_DNP3IND].AppLayerTxMatch = DetectDNP3IndMatch;
516516 sigmatch_table[DETECT_AL_DNP3IND].Setup = DetectDNP3IndSetup;
528528 sigmatch_table[DETECT_AL_DNP3OBJ].name = "dnp3_obj";
529529 sigmatch_table[DETECT_AL_DNP3OBJ].alias = "dnp3.obj";
530530 sigmatch_table[DETECT_AL_DNP3OBJ].desc = "match on the DNP3 application data objects";
531 sigmatch_table[DETECT_AL_DNP3OBJ].url = DOC_URL DOC_VERSION "/rules/dnp3-keywords.html#dnp3-obj";
531 sigmatch_table[DETECT_AL_DNP3OBJ].url = "/rules/dnp3-keywords.html#dnp3-obj";
532532 sigmatch_table[DETECT_AL_DNP3OBJ].Match = NULL;
533533 sigmatch_table[DETECT_AL_DNP3OBJ].AppLayerTxMatch = DetectDNP3ObjMatch;
534534 sigmatch_table[DETECT_AL_DNP3OBJ].Setup = DetectDNP3ObjSetup;
558558 sigmatch_table[DETECT_AL_DNP3DATA].name = "dnp3.data";
559559 sigmatch_table[DETECT_AL_DNP3DATA].alias = "dnp3_data";
560560 sigmatch_table[DETECT_AL_DNP3DATA].desc = "make the following content options to match on the re-assembled application buffer";
561 sigmatch_table[DETECT_AL_DNP3DATA].url = DOC_URL DOC_VERSION "/rules/dnp3-keywords.html#dnp3-data";
561 sigmatch_table[DETECT_AL_DNP3DATA].url = "/rules/dnp3-keywords.html#dnp3-data";
562562 sigmatch_table[DETECT_AL_DNP3DATA].Setup = DetectDNP3DataSetup;
563563 sigmatch_table[DETECT_AL_DNP3DATA].RegisterTests =
564564 DetectDNP3DataRegisterTests;
208208 sigmatch_table[DETECT_AL_DNS_QUERY].name = "dns.query";
209209 sigmatch_table[DETECT_AL_DNS_QUERY].alias = "dns_query";
210210 sigmatch_table[DETECT_AL_DNS_QUERY].desc = "sticky buffer to match DNS query-buffer";
211 sigmatch_table[DETECT_AL_DNS_QUERY].url = DOC_URL DOC_VERSION "/rules/dns-keywords.html#dns-query";
211 sigmatch_table[DETECT_AL_DNS_QUERY].url = "/rules/dns-keywords.html#dns-query";
212212 sigmatch_table[DETECT_AL_DNS_QUERY].Setup = DetectDnsQuerySetup;
213213 sigmatch_table[DETECT_AL_DNS_QUERY].RegisterTests = DetectDnsQueryRegisterTests;
214214 sigmatch_table[DETECT_AL_DNS_QUERY].flags |= SIGMATCH_NOOPT;
6565 {
6666 sigmatch_table[DETECT_DSIZE].name = "dsize";
6767 sigmatch_table[DETECT_DSIZE].desc = "match on the size of the packet payload";
68 sigmatch_table[DETECT_DSIZE].url = DOC_URL DOC_VERSION "/rules/payload-keywords.html#dsize";
68 sigmatch_table[DETECT_DSIZE].url = "/rules/payload-keywords.html#dsize";
6969 sigmatch_table[DETECT_DSIZE].Match = DetectDsizeMatch;
7070 sigmatch_table[DETECT_DSIZE].Setup = DetectDsizeSetup;
7171 sigmatch_table[DETECT_DSIZE].Free = DetectDsizeFree;
401401 return -1;
402402 }
403403
404 /**
405 * \brief Extends a target address range if the the source address range is
406 * wider than the target address range on either sides.
407 *
408 * Every address is a range, i.e. address->ip1....address->ip2. For
409 * example 1.2.3.4 to 192.168.1.1.
410 * if source->ip1 is smaller than target->ip1, it indicates that the
411 * source's left address limit is greater(range wise) than the target's
412 * left address limit, and hence we reassign the target's left address
413 * limit to source's left address limit.
414 * Similary if source->ip2 is greater than target->ip2, it indicates that
415 * the source's right address limit is greater(range wise) than the
416 * target's right address limit, and hence we reassign the target's right
417 * address limit to source's right address limit.
418 *
419 * \param de_ctx Pointer to the detection engine context.
420 * \param target Pointer to the target DetectAddress instance that has to be
421 * updated.
422 * \param source Pointer to the source DetectAddress instance that is used
423 * to decided whether we extend the target's address range.
424 *
425 * \retval 0 On success.
426 * \retval -1 On failure.
427 */
428 int DetectAddressJoinIPv4(DetectEngineCtx *de_ctx, DetectAddress *target,
429 DetectAddress *source)
430 {
431 if (source == NULL || target == NULL)
432 return -1;
433
434 if (SCNtohl(source->ip.addr_data32[0]) < SCNtohl(target->ip.addr_data32[0]))
435 target->ip.addr_data32[0] = source->ip.addr_data32[0];
436
437 if (SCNtohl(source->ip2.addr_data32[0]) > SCNtohl(target->ip2.addr_data32[0]))
438 target->ip2.addr_data32[0] = source->ip2.addr_data32[0];
439
440 return 0;
441 }
442
443404 /********************************Unittests*************************************/
444405
445406 #ifdef UNITTESTS
12941255 DetectAddressFree(a);
12951256 if (b != NULL)
12961257 DetectAddressFree(b);
1297 return 0;
1298 }
1299
1300 static int DetectAddressIPv4Join10(void)
1301 {
1302 struct in_addr in;
1303 int result = 1;
1304
1305 DetectAddress *source = DetectAddressInit();
1306 if (source == NULL)
1307 return 0;
1308
1309 DetectAddress *target = DetectAddressInit();
1310 if (target == NULL) {
1311 DetectAddressFree(source);
1312 return 0;
1313 }
1314
1315 if (inet_pton(AF_INET, "128.51.61.124", &in) < 0)
1316 goto error;
1317 target->ip.addr_data32[0] = in.s_addr;
1318 if (inet_pton(AF_INET, "192.168.1.2", &in) < 0)
1319 goto error;
1320 target->ip2.addr_data32[0] = in.s_addr;
1321
1322 if (inet_pton(AF_INET, "1.2.3.4", &in) < 0)
1323 goto error;
1324 source->ip.addr_data32[0] = in.s_addr;
1325 if (inet_pton(AF_INET, "192.168.1.2", &in) < 0)
1326 goto error;
1327 source->ip2.addr_data32[0] = in.s_addr;
1328
1329 result &= (DetectAddressJoinIPv4(NULL, target, source) == 0);
1330 if (inet_pton(AF_INET, "1.2.3.4", &in) < 0)
1331 goto error;
1332 result &= (target->ip.addr_data32[0] == in.s_addr);
1333 if (inet_pton(AF_INET, "192.168.1.2", &in) < 0)
1334 goto error;
1335 result &= (target->ip2.addr_data32[0] == in.s_addr);
1336
1337 if (inet_pton(AF_INET, "1.2.3.4", &in) < 0)
1338 goto error;
1339 target->ip.addr_data32[0] = in.s_addr;
1340 if (inet_pton(AF_INET, "192.168.1.2", &in) < 0)
1341 goto error;
1342 target->ip2.addr_data32[0] = in.s_addr;
1343
1344 if (inet_pton(AF_INET, "1.2.3.5", &in) < 0)
1345 goto error;
1346 source->ip.addr_data32[0] = in.s_addr;
1347 if (inet_pton(AF_INET, "192.168.1.1", &in) < 0)
1348 goto error;
1349 source->ip2.addr_data32[0] = in.s_addr;
1350
1351 result &= (DetectAddressJoinIPv4(NULL, target, source) == 0);
1352 if (inet_pton(AF_INET, "1.2.3.4", &in) < 0)
1353 goto error;
1354 result &= (target->ip.addr_data32[0] == in.s_addr);
1355 if (inet_pton(AF_INET, "192.168.1.2", &in) < 0)
1356 goto error;
1357 result &= (target->ip2.addr_data32[0] == in.s_addr);
1358
1359 if (inet_pton(AF_INET, "1.2.3.4", &in) < 0)
1360 goto error;
1361 target->ip.addr_data32[0] = in.s_addr;
1362 if (inet_pton(AF_INET, "192.168.1.2", &in) < 0)
1363 goto error;
1364 target->ip2.addr_data32[0] = in.s_addr;
1365
1366 if (inet_pton(AF_INET, "128.1.5.15", &in) < 0)
1367 goto error;
1368 source->ip.addr_data32[0] = in.s_addr;
1369 if (inet_pton(AF_INET, "200.202.200.200", &in) < 0)
1370 goto error;
1371 source->ip2.addr_data32[0] = in.s_addr;
1372
1373 result &= (DetectAddressJoinIPv4(NULL, target, source) == 0);
1374 if (inet_pton(AF_INET, "1.2.3.4", &in) < 0)
1375 goto error;
1376 result &= (target->ip.addr_data32[0] == in.s_addr);
1377 if (inet_pton(AF_INET, "200.202.200.200", &in) < 0)
1378 goto error;
1379 result &= (target->ip2.addr_data32[0] == in.s_addr);
1380
1381 if (inet_pton(AF_INET, "128.51.61.124", &in) < 0)
1382 goto error;
1383 target->ip.addr_data32[0] = in.s_addr;
1384 if (inet_pton(AF_INET, "192.168.1.2", &in) < 0)
1385 goto error;
1386 target->ip2.addr_data32[0] = in.s_addr;
1387
1388 if (inet_pton(AF_INET, "1.2.3.4", &in) < 0)
1389 goto error;
1390 source->ip.addr_data32[0] = in.s_addr;
1391 if (inet_pton(AF_INET, "192.168.1.2", &in) < 0)
1392 goto error;
1393 source->ip2.addr_data32[0] = in.s_addr;
1394
1395 result &= (DetectAddressJoinIPv4(NULL, target, source) == 0);
1396 if (inet_pton(AF_INET, "1.2.3.4", &in) < 0)
1397 goto error;
1398 result &= (target->ip.addr_data32[0] == in.s_addr);
1399 if (inet_pton(AF_INET, "192.168.1.2", &in) < 0)
1400 goto error;
1401 result &= (target->ip2.addr_data32[0] == in.s_addr);
1402
1403 if (inet_pton(AF_INET, "1.2.3.4", &in) < 0)
1404 goto error;
1405 target->ip.addr_data32[0] = in.s_addr;
1406 if (inet_pton(AF_INET, "192.168.1.2", &in) < 0)
1407 goto error;
1408 target->ip2.addr_data32[0] = in.s_addr;
1409
1410 if (inet_pton(AF_INET, "1.2.3.4", &in) < 0)
1411 goto error;
1412 source->ip.addr_data32[0] = in.s_addr;
1413 if (inet_pton(AF_INET, "192.168.1.2", &in) < 0)
1414 goto error;
1415 source->ip2.addr_data32[0] = in.s_addr;
1416
1417 result &= (DetectAddressJoinIPv4(NULL, target, source) == 0);
1418 if (inet_pton(AF_INET, "1.2.3.4", &in) < 0)
1419 goto error;
1420 result &= (target->ip.addr_data32[0] == in.s_addr);
1421 if (inet_pton(AF_INET, "192.168.1.2", &in) < 0)
1422 goto error;
1423 result &= (target->ip2.addr_data32[0] == in.s_addr);
1424
1425 DetectAddressFree(source);
1426 DetectAddressFree(target);
1427 return result;
1428
1429 error:
1430 DetectAddressFree(source);
1431 DetectAddressFree(target);
14321258 return 0;
14331259 }
14341260
14501276 UtRegisterTest("DetectAddressIPv4CutNot07", DetectAddressIPv4CutNot07);
14511277 UtRegisterTest("DetectAddressIPv4CutNot08", DetectAddressIPv4CutNot08);
14521278 UtRegisterTest("DetectAddressIPv4CutNot09", DetectAddressIPv4CutNot09);
1453 UtRegisterTest("DetectAddressIPv4Join10", DetectAddressIPv4Join10);
14541279 #endif
14551280 }
2828
2929 int DetectAddressCutIPv4(DetectEngineCtx *, DetectAddress *,
3030 DetectAddress *, DetectAddress **);
31 int DetectAddressJoinIPv4(DetectEngineCtx *, DetectAddress *target,
32 DetectAddress *source);
3331 int DetectAddressIsCompleteIPSpaceIPv4(DetectAddress *);
3432
3533 void DetectAddressIPv4Tests(void);
768768 return -1;
769769 }
770770
771 /**
772 * \brief Extends a target address range if the the source address range is
773 * wider than the target address range on either sides.
774 *
775 * Every address is a range, i.e. address->ip1....address->ip2. For
776 * example 2000::-2010::
777 * if source->ip1 is smaller than target->ip1, it indicates that the
778 * source's left address limit is greater(range wise) than the target's
779 * left address limit, and hence we reassign the target's left address
780 * limit to source's left address limit.
781 * Similary if source->ip2 is greater than target->ip2, it indicates that
782 * the source's right address limit is greater(range wise) than the
783 * target's right address limit, and hence we reassign the target's right
784 * address limit to source's right address limit.
785 *
786 * \param de_ctx Pointer to the detection engine context.
787 * \param target Pointer to the target DetectAddress instance that has to be
788 * updated.
789 * \param source Pointer to the source DetectAddress instance that is used
790 * to decided whether we extend the target's address range.
791 *
792 * \retval 0 On success.
793 * \retval -1 On failure.
794 */
795 int DetectAddressJoinIPv6(DetectEngineCtx *de_ctx, DetectAddress *target,
796 DetectAddress *source)
797 {
798 if (AddressIPv6Lt(&source->ip, &target->ip)) {
799 COPY_ADDRESS(&source->ip, &target->ip);
800 }
801
802 if (AddressIPv6Gt(&source->ip, &target->ip)) {
803 COPY_ADDRESS(&source->ip2, &target->ip2);
804 }
805
806 return 0;
807 }
808
809771
810772 /***************************************Unittests******************************/
811773
19251887 return 0;
19261888 }
19271889
1928 static int AddressTestIPv6Join01(void)
1929 {
1930 DetectAddress *source = DetectAddressInit();
1931 DetectAddress *target = DetectAddressInit();
1932 DetectAddress *temp = DetectAddressInit();
1933 struct in6_addr in6;
1934 int result = 1;
1935
1936 if (source == NULL || target == NULL || temp == NULL)
1937 goto error;
1938
1939 /* case 1 */
1940 if (inet_pton(AF_INET6, "2000::10", &in6) != 1)
1941 goto error;
1942 memcpy(&target->ip.address, in6.s6_addr, sizeof(in6.s6_addr));
1943 if (inet_pton(AF_INET6, "2000::20", &in6) != 1)
1944 goto error;
1945 memcpy(&target->ip2.address, in6.s6_addr, sizeof(in6.s6_addr));
1946
1947 if (inet_pton(AF_INET6, "2000::1", &in6) != 1)
1948 goto error;
1949 memcpy(&source->ip.address, in6.s6_addr, sizeof(in6.s6_addr));
1950 if (inet_pton(AF_INET6, "2000::20", &in6) != 1)
1951 goto error;
1952 memcpy(&source->ip2.address, in6.s6_addr, sizeof(in6.s6_addr));
1953
1954 result &= (DetectAddressJoinIPv6(NULL, target, source) == 0);
1955 if (inet_pton(AF_INET6, "2000::1", &in6) != 1)
1956 goto error;
1957 memcpy(&temp->ip.address, in6.s6_addr, sizeof(in6.s6_addr));
1958 if (inet_pton(AF_INET6, "2000::20", &in6) != 1)
1959 goto error;
1960 memcpy(&temp->ip2.address, in6.s6_addr, sizeof(in6.s6_addr));
1961 result = (DetectAddressCmpIPv6(target, temp) == ADDRESS_EQ);
1962
1963 /* case 2 */
1964 if (inet_pton(AF_INET6, "2000::1", &in6) != 1)
1965 goto error;
1966 memcpy(&target->ip.address, in6.s6_addr, sizeof(in6.s6_addr));
1967 if (inet_pton(AF_INET6, "2000::20", &in6) != 1)
1968 goto error;
1969 memcpy(&target->ip2.address, in6.s6_addr, sizeof(in6.s6_addr));
1970
1971 if (inet_pton(AF_INET6, "2000::2", &in6) != 1)
1972 goto error;
1973 memcpy(&source->ip.address, in6.s6_addr, sizeof(in6.s6_addr));
1974 if (inet_pton(AF_INET6, "2000::19", &in6) != 1)
1975 goto error;
1976 memcpy(&source->ip2.address, in6.s6_addr, sizeof(in6.s6_addr));
1977
1978 result &= (DetectAddressJoinIPv6(NULL, target, source) == 0);
1979 if (inet_pton(AF_INET6, "2000::1", &in6) != 1)
1980 goto error;
1981 memcpy(&temp->ip2.address, in6.s6_addr, sizeof(in6.s6_addr));
1982 if (inet_pton(AF_INET6, "2000::20", &in6) != 1)
1983 goto error;
1984 memcpy(&temp->ip2.address, in6.s6_addr, sizeof(in6.s6_addr));
1985 result = (DetectAddressCmpIPv6(target, temp) == ADDRESS_EQ);
1986
1987 /* case 3 */
1988 if (inet_pton(AF_INET6, "2000::1", &in6) != 1)
1989 goto error;
1990 memcpy(&target->ip.address, in6.s6_addr, sizeof(in6.s6_addr));
1991 if (inet_pton(AF_INET6, "2000::15", &in6) != 1)
1992 goto error;
1993 memcpy(&target->ip2.address, in6.s6_addr, sizeof(in6.s6_addr));
1994
1995 if (inet_pton(AF_INET6, "2000::10", &in6) != 1)
1996 goto error;
1997 memcpy(&source->ip.address, in6.s6_addr, sizeof(in6.s6_addr));
1998 if (inet_pton(AF_INET6, "2000::20", &in6) != 1)
1999 goto error;
2000 memcpy(&source->ip2.address, in6.s6_addr, sizeof(in6.s6_addr));
2001
2002 result &= (DetectAddressJoinIPv6(NULL, target, source) == 0);
2003 if (inet_pton(AF_INET6, "2000::1", &in6) != 1)
2004 goto error;
2005 memcpy(&temp->ip.address, in6.s6_addr, sizeof(in6.s6_addr));
2006 if (inet_pton(AF_INET6, "2000::20", &in6) != 1)
2007 goto error;
2008 memcpy(&temp->ip2.address, in6.s6_addr, sizeof(in6.s6_addr));
2009 result = (DetectAddressCmpIPv6(target, temp) == ADDRESS_EQ);
2010
2011 /* case 4 */
2012 if (inet_pton(AF_INET6, "2000::10", &in6) != 1)
2013 goto error;
2014 memcpy(&target->ip.address, in6.s6_addr, sizeof(in6.s6_addr));
2015 if (inet_pton(AF_INET6, "2000::20", &in6) != 1)
2016 goto error;
2017 memcpy(&target->ip2.address, in6.s6_addr, sizeof(in6.s6_addr));
2018
2019 if (inet_pton(AF_INET6, "2000::1", &in6) != 1)
2020 goto error;
2021 memcpy(&source->ip.address, in6.s6_addr, sizeof(in6.s6_addr));
2022 if (inet_pton(AF_INET6, "2000::20", &in6) != 1)
2023 goto error;
2024 memcpy(&source->ip2.address, in6.s6_addr, sizeof(in6.s6_addr));
2025
2026 result &= (DetectAddressJoinIPv6(NULL, target, source) == 0);
2027 if (inet_pton(AF_INET6, "2000::1", &in6) != 1)
2028 goto error;
2029 memcpy(&temp->ip.address, in6.s6_addr, sizeof(in6.s6_addr));
2030 if (inet_pton(AF_INET6, "2000::20", &in6) != 1)
2031 goto error;
2032 memcpy(&temp->ip2.address, in6.s6_addr, sizeof(in6.s6_addr));
2033 result = (DetectAddressCmpIPv6(target, temp) == ADDRESS_EQ);
2034
2035 /* case 5 */
2036 if (inet_pton(AF_INET6, "2000::1", &in6) != 1)
2037 goto error;
2038 memcpy(&target->ip.address, in6.s6_addr, sizeof(in6.s6_addr));
2039 if (inet_pton(AF_INET6, "2000::20", &in6) != 1)
2040 goto error;
2041 memcpy(&target->ip2.address, in6.s6_addr, sizeof(in6.s6_addr));
2042
2043 if (inet_pton(AF_INET6, "2000::1", &in6) != 1)
2044 goto error;
2045 memcpy(&source->ip.address, in6.s6_addr, sizeof(in6.s6_addr));
2046 if (inet_pton(AF_INET6, "2000::20", &in6) != 1)
2047 goto error;
2048 memcpy(&source->ip2.address, in6.s6_addr, sizeof(in6.s6_addr));
2049
2050 result &= (DetectAddressJoinIPv6(NULL, target, source) == 0);
2051 if (inet_pton(AF_INET6, "2000::1", &in6) != 1)
2052 goto error;
2053 memcpy(&temp->ip.address, in6.s6_addr, sizeof(in6.s6_addr));
2054 if (inet_pton(AF_INET6, "2000::20", &in6) != 1)
2055 goto error;
2056 memcpy(&temp->ip2.address, in6.s6_addr, sizeof(in6.s6_addr));
2057 result = (DetectAddressCmpIPv6(target, temp) == ADDRESS_EQ);
2058
2059 if (source != NULL)
2060 DetectAddressFree(source);
2061 if (target != NULL)
2062 DetectAddressFree(target);
2063 if (temp != NULL)
2064 DetectAddressFree(temp);
2065 return result;
2066
2067 error:
2068 if (source != NULL)
2069 DetectAddressFree(source);
2070 if (target != NULL)
2071 DetectAddressFree(target);
2072 if (temp != NULL)
2073 DetectAddressFree(temp);
2074
2075 return 0;
2076 }
2077
20781890 #endif /* UNITTESTS */
20791891
20801892 void DetectAddressIPv6Tests(void)
21211933 UtRegisterTest("AddressTestIPv6CutNot03", AddressTestIPv6CutNot03);
21221934 UtRegisterTest("AddressTestIPv6CutNot04", AddressTestIPv6CutNot04);
21231935 UtRegisterTest("AddressTestIPv6CutNot05", AddressTestIPv6CutNot05);
2124
2125 UtRegisterTest("AddressTestIPv6Join01", AddressTestIPv6Join01);
21261936 #endif /* UNITTESTS */
21271937
21281938 return;
4040
4141 int DetectAddressCutIPv6(DetectEngineCtx *, DetectAddress *, DetectAddress *,
4242 DetectAddress **);
43 int DetectAddressJoinIPv6(DetectEngineCtx *, DetectAddress *, DetectAddress *);
4443
4544 void DetectAddressIPv6Tests(void);
4645
0 /* Copyright (C) 2007-2010 Open Information Security Foundation
0 /* Copyright (C) 2007-2020 Open Information Security Foundation
11 *
22 * You can copy, redistribute or modify this Program under the terms of
33 * the GNU General Public License version 2 as published by the Free
2020 * \author Victor Julien <victor@inliniac.net>
2121 *
2222 * Address part of the detection engine.
23 *
24 * \todo Move this out of the detection plugin structure
25 * rename to detect-engine-address.c
2623 */
2724
2825 #include "suricata-common.h"
4744 #include "util-var.h"
4845
4946 /* prototypes */
50 void DetectAddressPrint(DetectAddress *);
47 #ifdef DEBUG
48 static void DetectAddressPrint(DetectAddress *);
49 #else
50 #define DetectAddressPrint(...)
51 #endif
5152 static int DetectAddressCutNot(DetectAddress *, DetectAddress **);
5253 static int DetectAddressCut(DetectEngineCtx *, DetectAddress *, DetectAddress *,
5354 DetectAddress **);
6162 */
6263 DetectAddress *DetectAddressInit(void)
6364 {
64 DetectAddress *ag = SCMalloc(sizeof(DetectAddress));
65 DetectAddress *ag = SCCalloc(1, sizeof(DetectAddress));
6566 if (unlikely(ag == NULL))
6667 return NULL;
67 memset(ag, 0, sizeof(DetectAddress));
68
6968 return ag;
7069 }
7170
8079 return;
8180
8281 SCFree(ag);
83
8482 return;
8583 }
8684
8785 /**
88 * \brief Copies the contents of one Address group in DetectAddress and returns
89 * a new instance of the DetectAddress that contains the copied address.
86 * \internal
87 * \brief Returns a new instance of DetectAddressHead.
88 *
89 * \retval gh Pointer to the new instance of DetectAddressHead.
90 */
91 static DetectAddressHead *DetectAddressHeadInit(void)
92 {
93 DetectAddressHead *gh = SCCalloc(1, sizeof(DetectAddressHead));
94 if (unlikely(gh == NULL))
95 return NULL;
96 return gh;
97 }
98
99 /**
100 * \internal
101 * \brief Frees a DetectAddressHead instance.
102 *
103 * \param gh Pointer to the DetectAddressHead instance to be freed.
104 */
105 static void DetectAddressHeadFree(DetectAddressHead *gh)
106 {
107 if (gh != NULL) {
108 DetectAddressHeadCleanup(gh);
109 SCFree(gh);
110 }
111 }
112
113 /**
114 * \brief copy a DetectAddress
90115 *
91116 * \param orig Pointer to the instance of DetectAddress that contains the
92117 * address data to be copied to the new instance.
94119 * \retval ag Pointer to the new instance of DetectAddress that contains the
95120 * copied address.
96121 */
97 DetectAddress *DetectAddressCopy(DetectAddress *orig)
122 static DetectAddress *DetectAddressCopy(DetectAddress *orig)
98123 {
99124 DetectAddress *ag = DetectAddressInit();
100125 if (ag == NULL)
101126 return NULL;
102127
103128 ag->flags = orig->flags;
104
105129 COPY_ADDRESS(&orig->ip, &ag->ip);
106130 COPY_ADDRESS(&orig->ip2, &ag->ip2);
107
108131 return ag;
109132 }
110133
111 /**
112 * \brief Used to check if a DetectAddress list contains an instance with
113 * a similar DetectAddress. The comparison done is not the one that
114 * checks the memory for the same instance, but one that checks that the
115 * two instances hold the same content.
116 *
117 * \param head Pointer to the DetectAddress list.
118 * \param ad Pointer to the DetectAddress that has to be checked for in
119 * the DetectAddress list.
120 *
121 * \retval cur Returns a pointer to the DetectAddress on a match; NULL if
122 * no match.
123 */
124 DetectAddress *DetectAddressLookupInList(DetectAddress *head, DetectAddress *gr)
125 {
126 DetectAddress *cur;
127
128 if (head != NULL) {
129 for (cur = head; cur != NULL; cur = cur->next) {
130 if (DetectAddressCmp(cur, gr) == ADDRESS_EQ)
131 return cur;
132 }
133 }
134
135 return NULL;
136 }
137
134 #ifdef DEBUG
138135 /**
139136 * \brief Prints the address data information for all the DetectAddress
140137 * instances in the DetectAddress list sent as the argument.
143140 */
144141 void DetectAddressPrintList(DetectAddress *head)
145142 {
146 DetectAddress *cur;
147
148143 SCLogInfo("list:");
149 if (head != NULL) {
150 for (cur = head; cur != NULL; cur = cur->next) {
151 DetectAddressPrint(cur);
152 }
144 for (DetectAddress *cur = head; cur != NULL; cur = cur->next) {
145 DetectAddressPrint(cur);
153146 }
154147 SCLogInfo("endlist");
155
156 return;
157 }
148 }
149 #endif
158150
159151 /**
152 * \internal
160153 * \brief Frees a list of DetectAddress instances.
161154 *
162155 * \param head Pointer to a list of DetectAddress instances to be freed.
163156 */
164 void DetectAddressCleanupList(DetectAddress *head)
165 {
166 DetectAddress *cur, *next;
167
168 if (head == NULL)
169 return;
170
171 for (cur = head; cur != NULL; ) {
172 next = cur->next;
157 static void DetectAddressCleanupList(DetectAddress *head)
158 {
159 for (DetectAddress *cur = head; cur != NULL; ) {
160 DetectAddress *next = cur->next;
173161 cur->next = NULL;
174162 DetectAddressFree(cur);
175163 cur = next;
176164 }
177
178 return;
179 }
180
181 /**
182 * \brief Do a sorted insert, where the top of the list should be the biggest
183 * network/range.
184 *
185 * XXX current sorting only works for overlapping nets
186 *
187 * \param head Pointer to the list of DetectAddress.
188 * \param ag Pointer to the DetectAddress that has to be added to the
189 * above list.
190 *
191 * \retval 0 On successfully inserting the DetectAddress.
192 * \retval -1 On failure.
193 */
194
195 int DetectAddressAdd(DetectAddress **head, DetectAddress *ag)
196 {
197 DetectAddress *cur, *prev_cur = NULL;
198 int r = 0;
199
200 if (*head != NULL) {
201 for (cur = *head; cur != NULL; cur = cur->next) {
202 prev_cur = cur;
203 r = DetectAddressCmp(ag, cur);
204 if (r == ADDRESS_EB) {
205 /* insert here */
206 ag->prev = cur->prev;
207 ag->next = cur;
208
209 cur->prev = ag;
210 if (*head == cur)
211 *head = ag;
212 else
213 ag->prev->next = ag;
214
215 return 0;
216 }
217 }
218 ag->prev = prev_cur;
219 if (prev_cur != NULL)
220 prev_cur->next = ag;
221 } else {
222 *head = ag;
223 }
224
225 return 0;
226165 }
227166
228167 /**
275214 }
276215
277216 /**
278 * \brief Same as DetectAddressInsert, but then for inserting a address group
279 * object. This also makes sure SigGroupContainer lists are handled
280 * correctly.
217 * \internal
218 * \brief insert DetectAddress into a DetectAddressHead
281219 *
282220 * \param de_ctx Pointer to the detection engine context.
283221 * \param gh Pointer to the DetectAddressHead list to which it has to
288226 * \retval -1 On error.
289227 * \retval 0 Not inserted, memory of new is freed.
290228 */
291 int DetectAddressInsert(DetectEngineCtx *de_ctx, DetectAddressHead *gh,
229 static int DetectAddressInsert(DetectEngineCtx *de_ctx, DetectAddressHead *gh,
292230 DetectAddress *new)
293231 {
294232 DetectAddress *head = NULL;
412350 }
413351
414352 /**
415 * \brief Join two addresses groups together.
416 *
417 * \param de_ctx Pointer to the detection engine context.
418 * \param target Pointer to the target address group.
419 * \param source Pointer to the source address group.
420 *
421 * \retval 0 On success.
422 * \retval -1 On failure.
423 */
424 int DetectAddressJoin(DetectEngineCtx *de_ctx, DetectAddress *target,
425 DetectAddress *source)
426 {
427 if (target == NULL || source == NULL)
428 return -1;
429
430 if (target->ip.family != source->ip.family)
431 return -1;
432
433 if (target->ip.family == AF_INET)
434 return DetectAddressJoinIPv4(de_ctx, target, source);
435 else if (target->ip.family == AF_INET6)
436 return DetectAddressJoinIPv6(de_ctx, target, source);
437
438 return -1;
439 }
440
441 /**
442353 * \brief Checks if two address group lists are equal.
443354 *
444355 * \param list1 Pointer to the first address group list.
520431 * \retval 0 On successfully parsing the address string.
521432 * \retval -1 On failure.
522433 */
523 int DetectAddressParseString(DetectAddress *dd, const char *str)
434 static int DetectAddressParseString(DetectAddress *dd, const char *str)
524435 {
525436 char *ip = NULL;
526437 char *ip2 = NULL;
527438 char *mask = NULL;
528439 int r = 0;
529440 char ipstr[256];
530
531 while (*str != '\0' && *str == ' ')
532 str++;
533441
534442 /* shouldn't see 'any' here */
535443 BUG_ON(strcasecmp(str, "any") == 0);
560468 mask++;
561469 uint32_t ip4addr = 0;
562470 uint32_t netmask = 0;
563 size_t u = 0;
564471
565472 if ((strchr (mask, '.')) == NULL) {
566473 /* 1.2.3.4/24 format */
567474
568 for (u = 0; u < strlen(mask); u++) {
475 for (size_t u = 0; u < strlen(mask); u++) {
569476 if(!isdigit((unsigned char)mask[u]))
570477 goto error;
571478 }
632539
633540 int cidr = atoi(mask);
634541 if (cidr < 0 || cidr > 128)
635 goto error;
542 goto error;
636543
637544 r = inet_pton(AF_INET6, ip, &in6);
638545 if (r <= 0)
700607 */
701608 static DetectAddress *DetectAddressParseSingle(const char *str)
702609 {
703 DetectAddress *dd;
704
705610 SCLogDebug("str %s", str);
706611
707 dd = DetectAddressInit();
612 DetectAddress *dd = DetectAddressInit();
708613 if (dd == NULL)
709 goto error;
614 return NULL;
710615
711616 if (DetectAddressParseString(dd, str) < 0) {
712617 SCLogDebug("AddressParse failed");
713 goto error;
618 DetectAddressFree(dd);
619 return NULL;
714620 }
715621
716622 return dd;
717
718 error:
719 if (dd != NULL)
720 DetectAddressFree(dd);
721 return NULL;
722623 }
723624
724625 /**
736637 static int DetectAddressSetup(DetectAddressHead *gh, const char *s)
737638 {
738639 SCLogDebug("gh %p, s %s", gh, s);
640
641 while (*s != '\0' && isspace(*s))
642 s++;
739643
740644 if (strcasecmp(s, "any") == 0) {
741645 SCLogDebug("adding 0.0.0.0/0 and ::/0 as we\'re handling \'any\'");
830734 */
831735 static int DetectAddressParse2(const DetectEngineCtx *de_ctx,
832736 DetectAddressHead *gh, DetectAddressHead *ghn,
833 const char *s, int negate, ResolvedVariablesList *var_list)
737 const char *s, int negate, ResolvedVariablesList *var_list,
738 int recur)
834739 {
835740 size_t x = 0;
836741 size_t u = 0;
840745 char address[8196] = "";
841746 const char *rule_var_address = NULL;
842747 char *temp_rule_var_address = NULL;
748
749 if (++recur > 64) {
750 SCLogError(SC_ERR_ADDRESS_ENGINE_GENERIC, "address block recursion "
751 "limit reached (max 64)");
752 goto error;
753 }
843754
844755 SCLogDebug("s %s negate %s", s, negate ? "true" : "false");
845756
871782 /* normal block */
872783 SCLogDebug("normal block");
873784
874 if (DetectAddressParse2(de_ctx, gh, ghn, address, (negate + n_set) % 2, var_list) < 0)
785 if (DetectAddressParse2(de_ctx, gh, ghn, address, (negate + n_set) % 2, var_list, recur) < 0)
875786 goto error;
876787 } else {
877788 /* negated block
884795 DetectAddressHead tmp_gh = { NULL, NULL };
885796 DetectAddressHead tmp_ghn = { NULL, NULL };
886797
887 if (DetectAddressParse2(de_ctx, &tmp_gh, &tmp_ghn, address, 0, var_list) < 0) {
798 if (DetectAddressParse2(de_ctx, &tmp_gh, &tmp_ghn, address, 0, var_list, recur) < 0) {
888799 DetectAddressHeadCleanup(&tmp_gh);
889800 DetectAddressHeadCleanup(&tmp_ghn);
890801 goto error;
984895
985896
986897 if (DetectAddressParse2(de_ctx, gh, ghn, temp_rule_var_address,
987 (negate + n_set) % 2, var_list) < 0)
898 (negate + n_set) % 2, var_list, recur) < 0)
988899 {
989900 if (temp_rule_var_address != rule_var_address)
990901 SCFree(temp_rule_var_address);
1052963 }
1053964
1054965 if (DetectAddressParse2(de_ctx, gh, ghn, temp_rule_var_address,
1055 (negate + n_set) % 2, var_list) < 0) {
966 (negate + n_set) % 2, var_list, recur) < 0) {
1056967 SCLogDebug("DetectAddressParse2 hates us");
1057968 if (temp_rule_var_address != rule_var_address)
1058969 SCFree(temp_rule_var_address);
13461257 goto error;
13471258 }
13481259
1349 int r = DetectAddressParse2(NULL, gh, ghn, seq_node->val, /* start with negate no */0, &var_list);
1260 int r = DetectAddressParse2(NULL, gh, ghn, seq_node->val, /* start with negate no */0, &var_list, 0);
13501261
13511262 CleanVariableResolveList(&var_list);
13521263
14911402 int DetectAddressParse(const DetectEngineCtx *de_ctx,
14921403 DetectAddressHead *gh, const char *str)
14931404 {
1494 int r;
1495 DetectAddressHead *ghn = NULL;
1496
14971405 SCLogDebug("gh %p, str %s", gh, str);
14981406
14991407 if (str == NULL) {
15001408 SCLogDebug("DetectAddressParse can not be run with NULL address");
1501 goto error;
1502 }
1503
1504 ghn = DetectAddressHeadInit();
1409 return -1;
1410 }
1411
1412 DetectAddressHead *ghn = DetectAddressHeadInit();
15051413 if (ghn == NULL) {
15061414 SCLogDebug("DetectAddressHeadInit for ghn failed");
1507 goto error;
1508 }
1509
1510 r = DetectAddressParse2(de_ctx, gh, ghn, str, /* start with negate no */0, NULL);
1415 return -1;
1416 }
1417
1418 int r = DetectAddressParse2(de_ctx, gh, ghn, str, /* start with negate no */0, NULL, 0);
15111419 if (r < 0) {
15121420 SCLogDebug("DetectAddressParse2 returned %d", r);
1513 goto error;
1421 DetectAddressHeadFree(ghn);
1422 return -1;
15141423 }
15151424
15161425 SCLogDebug("gh->ipv4_head %p, ghn->ipv4_head %p", gh->ipv4_head,
15211430 /* merge the 'not' address groups */
15221431 if (DetectAddressMergeNot(gh, ghn) < 0) {
15231432 SCLogDebug("DetectAddressMergeNot failed");
1524 goto error;
1433 DetectAddressHeadFree(ghn);
1434 return -1;
15251435 }
15261436
15271437 /* free the temp negate head */
15281438 DetectAddressHeadFree(ghn);
15291439 return contains_negation ? 1 : 0;
1530
1531 error:
1532 if (ghn != NULL)
1533 DetectAddressHeadFree(ghn);
1534 return -1;
15351440 }
15361441
15371442 const DetectAddressHead *DetectParseAddress(DetectEngineCtx *de_ctx,
15661471 }
15671472
15681473 /**
1569 * \brief Returns a new instance of DetectAddressHead.
1570 *
1571 * \retval gh Pointer to the new instance of DetectAddressHead.
1572 */
1573 DetectAddressHead *DetectAddressHeadInit(void)
1574 {
1575 DetectAddressHead *gh = SCMalloc(sizeof(DetectAddressHead));
1576 if (unlikely(gh == NULL))
1577 return NULL;
1578 memset(gh, 0, sizeof(DetectAddressHead));
1579
1580 return gh;
1581 }
1582
1583 /**
15841474 * \brief Cleans a DetectAddressHead. The functions frees the address
15851475 * group heads(ipv4 and ipv6) inside the DetectAddressHead
15861476 * instance.
15991489 DetectAddressCleanupList(gh->ipv6_head);
16001490 gh->ipv6_head = NULL;
16011491 }
1602 }
1603
1604 return;
1605 }
1606
1607 /**
1608 * \brief Frees a DetectAddressHead instance.
1609 *
1610 * \param gh Pointer to the DetectAddressHead instance to be freed.
1611 */
1612 void DetectAddressHeadFree(DetectAddressHead *gh)
1613 {
1614 if (gh != NULL) {
1615 DetectAddressHeadCleanup(gh);
1616 SCFree(gh);
16171492 }
16181493
16191494 return;
17271602 SCReturnInt(0);
17281603 }
17291604
1730 uint16_t idx;
1731 for (idx = 0; idx < addrs_cnt; idx++) {
1605 for (uint16_t idx = 0; idx < addrs_cnt; idx++) {
17321606 if (SCNtohl(a->addr_data32[0]) >= addrs[idx].ip &&
17331607 SCNtohl(a->addr_data32[0]) <= addrs[idx].ip2)
17341608 {
17621636 SCReturnInt(0);
17631637 }
17641638
1765 uint16_t idx;
1766 int i = 0;
1767 uint16_t result1, result2;
1768
17691639 /* See if the packet address is within the range of any entry in the
17701640 * signature's address match array.
17711641 */
1772 for (idx = 0; idx < addrs_cnt; idx++) {
1773 result1 = result2 = 0;
1642 for (uint16_t idx = 0; idx < addrs_cnt; idx++) {
1643 uint16_t result1 = 0, result2 = 0;
17741644
17751645 /* See if packet address equals either limit. Return 1 if true. */
17761646 if (SCNtohl(a->addr_data32[0]) == addrs[idx].ip[0] &&
17911661 /* See if packet address is greater than lower limit
17921662 * of the current signature address match pair.
17931663 */
1794 for (i = 0; i < 4; i++) {
1664 for (int i = 0; i < 4; i++) {
17951665 if (SCNtohl(a->addr_data32[i]) > addrs[idx].ip[i]) {
17961666 result1 = 1;
17971667 break;
18091679 /* See if packet address is less than upper limit
18101680 * of the current signature address match pair.
18111681 */
1812 for (i = 0; i < 4; i++) {
1682 for (int i = 0; i < 4; i++) {
18131683 if (SCNtohl(a->addr_data32[i]) < addrs[idx].ip2[i]) {
18141684 result2 = 1;
18151685 break;
18431713 * \param 1 On a match.
18441714 * \param 0 On no match.
18451715 */
1846 int DetectAddressMatch(DetectAddress *dd, Address *a)
1716 static int DetectAddressMatch(DetectAddress *dd, Address *a)
18471717 {
18481718 SCEnter();
18491719
18861756 SCReturnInt(0);
18871757 }
18881758
1759 #ifdef DEBUG
18891760 /**
18901761 * \brief Prints the address data held by the DetectAddress. If the address
18911762 * data family is IPv4, we print the the ipv4 address and mask, and
18941765 *
18951766 * \param ad Pointer to the DetectAddress instance to be printed.
18961767 */
1897 void DetectAddressPrint(DetectAddress *gr)
1768 static void DetectAddressPrint(DetectAddress *gr)
18981769 {
18991770 if (gr == NULL)
19001771 return;
19251796
19261797 return;
19271798 }
1799 #endif
19281800
19291801 /**
19301802 * \brief Find the group matching address in a group head.
24212293 FAIL_IF_NULL(gh);
24222294 int r = DetectAddressParse(NULL, gh, "ANY");
24232295 FAIL_IF_NOT(r == 0);
2296 DetectAddressHeadFree(gh);
2297 PASS;
2298 }
2299
2300 /** \test recursion limit */
2301 static int AddressTestParse26(void)
2302 {
2303 DetectAddressHead *gh = DetectAddressHeadInit();
2304 FAIL_IF_NULL(gh);
2305 /* exactly 64: should pass */
2306 int r = DetectAddressParse(NULL, gh,
2307 "[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[["
2308 "1.2.3.4"
2309 "]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]"
2310 );
2311 FAIL_IF_NOT(r == 0);
2312 DetectAddressHeadFree(gh);
2313 gh = DetectAddressHeadInit();
2314 FAIL_IF_NULL(gh);
2315 /* exactly 65: should fail */
2316 r = DetectAddressParse(NULL, gh,
2317 "[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[["
2318 "1.2.3.4"
2319 "]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]"
2320 );
2321 FAIL_IF(r == 0);
24242322 DetectAddressHeadFree(gh);
24252323 PASS;
24262324 }
49614859 UtRegisterTest("AddressTestParse23", AddressTestParse23);
49624860 UtRegisterTest("AddressTestParse24", AddressTestParse24);
49634861 UtRegisterTest("AddressTestParse25", AddressTestParse25);
4862 UtRegisterTest("AddressTestParse26", AddressTestParse26);
49644863 UtRegisterTest("AddressTestParse27", AddressTestParse27);
49654864 UtRegisterTest("AddressTestParse28", AddressTestParse28);
49664865 UtRegisterTest("AddressTestParse29", AddressTestParse29);
2323 #ifndef __DETECT_ADDRESS_H__
2424 #define __DETECT_ADDRESS_H__
2525
26 /* prototypes */
27 void DetectAddressRegister (void);
2826
29 DetectAddressHead *DetectAddressHeadInit(void);
30 void DetectAddressHeadFree(DetectAddressHead *);
31 void DetectAddressHeadCleanup(DetectAddressHead *);
32
33 int DetectAddressParseString(DetectAddress *, const char *);
34 int DetectAddressParse(const DetectEngineCtx *, DetectAddressHead *, const char *);
3527
3628 DetectAddress *DetectAddressInit(void);
3729 void DetectAddressFree(DetectAddress *);
38
39 void DetectAddressCleanupList (DetectAddress *);
40 int DetectAddressAdd(DetectAddress **, DetectAddress *);
41 void DetectAddressPrintList(DetectAddress *);
42
43 int DetectAddressInsert(DetectEngineCtx *, DetectAddressHead *, DetectAddress *);
44 int DetectAddressJoin(DetectEngineCtx *, DetectAddress *, DetectAddress *);
30 int DetectAddressParse(const DetectEngineCtx *, DetectAddressHead *, const char *);
31 void DetectAddressHeadCleanup(DetectAddressHead *);
4532
4633 bool DetectAddressListsAreEqual(DetectAddress *list1, DetectAddress *list2);
4734
4835 DetectAddress *DetectAddressLookupInHead(const DetectAddressHead *, Address *);
49 DetectAddress *DetectAddressLookupInList(DetectAddress *, DetectAddress *);
50 int DetectAddressMatch(DetectAddress *, Address *);
5136
52 DetectAddress *DetectAddressCopy(DetectAddress *);
53 void DetectAddressPrint(DetectAddress *);
5437 int DetectAddressCmp(DetectAddress *, DetectAddress *);
5538
5639 int DetectAddressMatchIPv4(const DetectMatchAddressIPv4 *, uint16_t, const Address *);
6548 const DetectAddressHead *DetectParseAddress(DetectEngineCtx *de_ctx,
6649 const char *string, bool *contains_negation);
6750
51 #ifdef DEBUG
52 void DetectAddressPrintList(DetectAddress *);
53 #endif
54
6855 #endif /* __DETECT_ADDRESS_H__ */
0 /* Copyright (C) 2007-2010 Open Information Security Foundation
0 /* Copyright (C) 2007-2020 Open Information Security Foundation
11 *
22 * You can copy, redistribute or modify this Program under the terms of
33 * the GNU General Public License version 2 as published by the Free
2121 * \author Pablo Rincon Crespo <pablo.rincon.crespo@gmail.com>
2222 *
2323 * Signatures that only inspect IP addresses are processed here
24 * We use radix trees for src dst ipv4 and ipv6 adresses
24 * We use radix trees for src dst ipv4 and ipv6 addresses
2525 * This radix trees hold information for subnets and hosts in a
2626 * hierarchical distribution
2727 */
9191 return 0;
9292 }
9393
94 //declaration for using it already
95 static IPOnlyCIDRItem *IPOnlyCIDRItemInsert(IPOnlyCIDRItem *head,
96 IPOnlyCIDRItem *item);
97
9498 /**
9599 * \internal
96100 * \brief Parses an ipv4/ipv6 address string and updates the result into the
97101 * IPOnlyCIDRItem instance sent as the argument.
98102 *
99 * \param dd Pointer to the IPOnlyCIDRItem instance which should be updated with
100 * the address (in cidr) details from the parsed ip string.
103 * \param pdd Double pointer to the IPOnlyCIDRItem instance which should be updated
104 * with the address (in cidr) details from the parsed ip string.
101105 * \param str Pointer to address string that has to be parsed.
102106 *
103107 * \retval 0 On successfully parsing the address string.
104108 * \retval -1 On failure.
105109 */
106 static int IPOnlyCIDRItemParseSingle(IPOnlyCIDRItem *dd, const char *str)
110 static int IPOnlyCIDRItemParseSingle(IPOnlyCIDRItem **pdd, const char *str)
107111 {
108112 char buf[256] = "";
109113 char *ip = NULL, *ip2 = NULL;
110114 char *mask = NULL;
111115 int r = 0;
116 IPOnlyCIDRItem *dd = *pdd;
112117
113118 while (*str != '\0' && *str == ' ')
114119 str++;
122127 /* if any, insert 0.0.0.0/0 and ::/0 as well */
123128 SCLogDebug("adding 0.0.0.0/0 and ::/0 as we\'re handling \'any\'");
124129
125 IPOnlyCIDRItemParseSingle(dd, "0.0.0.0/0");
130 IPOnlyCIDRItemParseSingle(&dd, "0.0.0.0/0");
126131 BUG_ON(dd->family == 0);
127132
128133 dd->next = IPOnlyCIDRItemNew();
129134 if (dd->next == NULL)
130135 goto error;
131136
132 IPOnlyCIDRItemParseSingle(dd->next, "::/0");
137 IPOnlyCIDRItemParseSingle(&dd->next, "::/0");
133138 BUG_ON(dd->family == 0);
134139
135140 SCLogDebug("address is \'any\'");
177182
178183 netmask = in.s_addr;
179184
180 /* Extract cidr netmask */
181 while ((0x01 & netmask) == 0) {
182 dd->netmask++;
183 netmask = netmask >> 1;
185 if (netmask != 0) {
186 /* Extract cidr netmask */
187 while ((0x01 & netmask) == 0) {
188 dd->netmask++;
189 netmask = netmask >> 1;
190 }
191 dd->netmask = 32 - dd->netmask;
184192 }
185 dd->netmask = 32 - dd->netmask;
186193 }
187194
188195 r = inet_pton(AF_INET, ip, &in);
196203 ip[ip2 - ip] = '\0';
197204 ip2++;
198205
199 uint32_t tmp_ip[4];
200 uint32_t tmp_ip2[4];
201206 uint32_t first, last;
202207
203208 r = inet_pton(AF_INET, ip, &in);
204209 if (r <= 0)
205210 goto error;
206 tmp_ip[0] = in.s_addr;
211 first = SCNtohl(in.s_addr);
207212
208213 r = inet_pton(AF_INET, ip2, &in);
209214 if (r <= 0)
210215 goto error;
211 tmp_ip2[0] = in.s_addr;
216 last = SCNtohl(in.s_addr);
212217
213218 /* a > b is illegal, a = b is ok */
214 if (SCNtohl(tmp_ip[0]) > SCNtohl(tmp_ip2[0]))
219 if (first > last)
215220 goto error;
216221
217 first = SCNtohl(tmp_ip[0]);
218 last = SCNtohl(tmp_ip2[0]);
219
222 SCLogDebug("Creating CIDR range for [%s - %s]", ip, ip2);
220223 dd->netmask = 32;
221 dd->ip[0] =htonl(first);
222
223 if (first < last) {
224 for (first++; first <= last; first++) {
225 IPOnlyCIDRItem *new = IPOnlyCIDRItemNew();
226 if (new == NULL)
227 goto error;
228 dd->next = new;
229 new->negated = dd->negated;
230 new->family= dd->family;
231 new->netmask = dd->netmask;
232 new->ip[0] = htonl(first);
233 dd = dd->next;
224 /* Find the maximum netmask starting from current address first
225 * and not crossing last.
226 * To extend the mask, we need to start from a power of 2.
227 * And we need to pay attention to unsigned overflow back to 0.0.0.0
228 */
229 while (dd->netmask > 0 &&
230 (first & (1UL << (32-dd->netmask))) == 0 &&
231 first + (1UL << (32-(dd->netmask-1))) - 1 <= last) {
232 dd->netmask--;
233 }
234 dd->ip[0] = htonl(first);
235 first += 1UL << (32-dd->netmask);
236 //case whatever-255.255.255.255 looping to 0.0.0.0/0
237 while ( first <= last && first != 0 ) {
238 IPOnlyCIDRItem *new = IPOnlyCIDRItemNew();
239 if (new == NULL)
240 goto error;
241 new->negated = dd->negated;
242 new->family= dd->family;
243 new->netmask = 32;
244 while (new->netmask > 0 &&
245 (first & (1UL << (32-new->netmask))) == 0 &&
246 first + (1UL << (32-(new->netmask-1))) - 1 <= last) {
247 new->netmask--;
234248 }
249 new->ip[0] = htonl(first);
250 first += 1UL << (32-new->netmask);
251 dd = IPOnlyCIDRItemInsert(dd, new);
235252 }
253 //update head of list
254 *pdd = dd;
236255
237256 } else {
238257 /* 1.2.3.4 format */
293312 * \retval 0 On success.
294313 * \retval -1 On failure.
295314 */
296 static int IPOnlyCIDRItemSetup(IPOnlyCIDRItem *gh, char *s)
297 {
298 SCLogDebug("gh %p, s %s", gh, s);
315 static int IPOnlyCIDRItemSetup(IPOnlyCIDRItem **gh, char *s)
316 {
317 SCLogDebug("gh %p, s %s", *gh, s);
299318
300319 /* parse the address */
301320 if (IPOnlyCIDRItemParseSingle(gh, s) == -1) {
671690 else
672691 subhead->negated = 1;
673692
674 if (IPOnlyCIDRItemSetup(subhead, address) < 0) {
693 if (IPOnlyCIDRItemSetup(&subhead, address) < 0) {
675694 IPOnlyCIDRListFree(subhead);
676695 subhead = NULL;
677696 goto error;
727746 else
728747 subhead->negated = 1;
729748
730 if (IPOnlyCIDRItemSetup(subhead, address) < 0) {
749 if (IPOnlyCIDRItemSetup(&subhead, address) < 0) {
731750 IPOnlyCIDRListFree(subhead);
732751 subhead = NULL;
733752 goto error;
15111530 SCFree(tmpaux);
15121531 }
15131532
1514 /* print all the trees: for debuggin it might print too much info
1533 /* print all the trees: for debugging it might print too much info
15151534 SCLogDebug("Radix tree src ipv4:");
15161535 SCRadixPrintTree((de_ctx->io_ctx).tree_ipv4src);
15171536 SCLogDebug("Radix tree src ipv6:");
15271546 }
15281547
15291548 /**
1530 * \brief Add a signature to the lists of Adrresses in CIDR format (sorted)
1549 * \brief Add a signature to the lists of Addresses in CIDR format (sorted)
15311550 * this step is necesary to build the radix tree with a hierarchical
15321551 * relation between nodes
15331552 * \param de_ctx Pointer to the current detection engine context
22552274 return result;
22562275 }
22572276
2277 /**
2278 * \brief Unittest to show #3568 -- IP address range handling
2279 */
2280 static int IPOnlyTestSig18(void)
2281 {
2282 int result = 0;
2283 uint8_t *buf = (uint8_t *)"Hi all!";
2284 uint16_t buflen = strlen((char *)buf);
2285
2286 uint8_t numpkts = 4;
2287 uint8_t numsigs = 4;
2288
2289 Packet *p[4];
2290
2291 p[0] = UTHBuildPacketSrcDst((uint8_t *)buf, buflen, IPPROTO_TCP, "10.10.10.1", "50.0.0.1");
2292 p[1] = UTHBuildPacketSrcDst((uint8_t *)buf, buflen, IPPROTO_TCP, "220.10.10.1", "5.0.0.1");
2293 p[2] = UTHBuildPacketSrcDst((uint8_t *)buf, buflen, IPPROTO_TCP, "0.0.0.1", "50.0.0.1");
2294 p[3] = UTHBuildPacketSrcDst((uint8_t *)buf, buflen, IPPROTO_TCP, "255.255.255.254", "5.0.0.1");
2295
2296 const char *sigs[numsigs];
2297 // really many IP addresses
2298 sigs[0]= "alert ip 1.2.3.4-219.6.7.8 any -> any any (sid:1;)";
2299 sigs[1]= "alert ip 51.2.3.4-253.1.2.3 any -> any any (sid:2;)";
2300 sigs[2]= "alert ip 0.0.0.0-50.0.0.2 any -> any any (sid:3;)";
2301 sigs[3]= "alert ip 50.0.0.0-255.255.255.255 any -> any any (sid:4;)";
2302
2303 uint32_t sid[4] = { 1, 2, 3, 4, };
2304 uint32_t results[4][4] = {
2305 { 1, 0, 1, 0, }, { 0, 1, 0, 1}, { 0, 0, 1, 0 }, { 0, 0, 0, 1}};
2306
2307 result = UTHGenericTest(p, numpkts, sigs, sid, (uint32_t *) results, numsigs);
2308
2309 UTHFreePackets(p, numpkts);
2310
2311 FAIL_IF(result != 1);
2312
2313 PASS;
2314 }
2315
22582316 #endif /* UNITTESTS */
22592317
22602318 void IPOnlyRegisterTests(void)
22902348 UtRegisterTest("IPOnlyTestSig16", IPOnlyTestSig16);
22912349
22922350 UtRegisterTest("IPOnlyTestSig17", IPOnlyTestSig17);
2351 UtRegisterTest("IPOnlyTestSig18", IPOnlyTestSig18);
22932352 #endif
22942353
22952354 return;
830830 static int DetectPortParseDo(const DetectEngineCtx *de_ctx,
831831 DetectPort **head, DetectPort **nhead,
832832 const char *s, int negate,
833 ResolvedVariablesList *var_list)
833 ResolvedVariablesList *var_list, int recur)
834834 {
835835 size_t u = 0;
836836 size_t x = 0;
841841 char address[1024] = "";
842842 const char *rule_var_port = NULL;
843843 int r = 0;
844
845 if (recur++ > 64) {
846 SCLogError(SC_ERR_PORT_ENGINE_GENERIC, "port block recursion "
847 "limit reached (max 64)");
848 goto error;
849 }
844850
845851 SCLogDebug("head %p, *head %p, negate %d", head, *head, negate);
846852
870876 SCLogDebug("Parsed port from DetectPortParseDo - %s", address);
871877 x = 0;
872878
873 r = DetectPortParseDo(de_ctx, head, nhead, address, negate? negate: n_set, var_list);
879 r = DetectPortParseDo(de_ctx, head, nhead, address,
880 negate? negate: n_set, var_list, recur);
874881 if (r == -1)
875882 goto error;
876883
911918 }
912919 temp_rule_var_port = alloc_rule_var_port;
913920 r = DetectPortParseDo(de_ctx, head, nhead, temp_rule_var_port,
914 (negate + n_set) % 2, var_list);//negate? negate: n_set);
921 (negate + n_set) % 2, var_list, recur);
915922 if (r == -1) {
916923 SCFree(alloc_rule_var_port);
917924 goto error;
981988 }
982989 temp_rule_var_port = alloc_rule_var_port;
983990 r = DetectPortParseDo(de_ctx, head, nhead, temp_rule_var_port,
984 (negate + n_set) % 2, var_list);
991 (negate + n_set) % 2, var_list, recur);
985992 SCFree(alloc_rule_var_port);
986993 if (r == -1)
987994 goto error;
11831190 goto error;
11841191 }
11851192
1186 int r = DetectPortParseDo(NULL, &gh, &ghn, seq_node->val, /* start with negate no */0, &var_list);
1193 int r = DetectPortParseDo(NULL, &gh, &ghn, seq_node->val,
1194 /* start with negate no */0, &var_list, 0);
11871195
11881196 CleanVariableResolveList(&var_list);
11891197
12361244 DetectPort *nhead = NULL;
12371245
12381246 int r = DetectPortParseDo(de_ctx, head, &nhead, str,
1239 /* start with negate no */ 0, NULL);
1247 /* start with negate no */ 0, NULL, 0);
12401248 if (r < 0)
12411249 goto error;
12421250
17321740 FAIL_IF_NOT(dd->next->port2 == 65535);
17331741
17341742 DetectPortCleanupList(NULL, dd);
1743 PASS;
1744 }
1745
1746 static int PortTestParse16 (void)
1747 {
1748 DetectPort *dd = NULL;
1749 int r = DetectPortParse(NULL,&dd,"\
1750 [[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[\
1751 1:65535\
1752 ]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]\
1753 ");
1754 FAIL_IF_NOT(r == 0);
1755 DetectPortFree(NULL, dd);
1756 dd = NULL;
1757 r = DetectPortParse(NULL,&dd,"\
1758 [[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[\
1759 1:65535\
1760 ]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]\
1761 ");
1762 FAIL_IF(r == 0);
17351763 PASS;
17361764 }
17371765
24222450 int result = 0;
24232451 DetectPort *head = NULL, *nhead = NULL;
24242452
2425 if (DetectPortParseDo(NULL, &head, &nhead, "![!80]", 0, NULL) == -1)
2453 if (DetectPortParseDo(NULL, &head, &nhead, "![!80]", 0, NULL, 0) == -1)
24262454 return result;
24272455
24282456 result = (head != NULL);
24472475 UtRegisterTest("PortTestParse13", PortTestParse13);
24482476 UtRegisterTest("PortTestParse14", PortTestParse14);
24492477 UtRegisterTest("PortTestParse15", PortTestParse15);
2478 UtRegisterTest("PortTestParse16", PortTestParse16);
24502479 UtRegisterTest("PortTestFunctions01", PortTestFunctions01);
24512480 UtRegisterTest("PortTestFunctions02", PortTestFunctions02);
24522481 UtRegisterTest("PortTestFunctions03", PortTestFunctions03);
309309 printf("%sFeatures: ", prefix);
310310 PrintFeatureList(&sigmatch_table[i], ',');
311311 if (sigmatch_table[i].url) {
312 printf("\n%sDocumentation: %s", prefix, sigmatch_table[i].url);
312 printf("\n%sDocumentation: %s%s", prefix, GetDocURL(), sigmatch_table[i].url);
313313 }
314314 if (sigmatch_table[i].alternative) {
315315 printf("\n%sReplaced by: %s", prefix, sigmatch_table[sigmatch_table[i].alternative].name);
357357 PrintFeatureList(&sigmatch_table[i], ':');
358358 printf(";");
359359 if (sigmatch_table[i].url) {
360 printf("%s", sigmatch_table[i].url);
360 printf("%s%s", GetDocURL(), sigmatch_table[i].url);
361361 }
362362 printf(";");
363363 printf("\n");
0 /* Copyright (C) 2007-2010 Open Information Security Foundation
0 /* Copyright (C) 2007-2020 Open Information Security Foundation
11 *
22 * You can copy, redistribute or modify this Program under the terms of
33 * the GNU General Public License version 2 as published by the Free
985985 {
986986 BUG_ON(s->init_data == NULL);
987987
988 if (s->init_data->list && s->init_data->transform_cnt) {
988 if (s->init_data->transform_cnt) {
989 if (s->init_data->list == DETECT_SM_LIST_NOTSET ||
990 s->init_data->list < DETECT_SM_LIST_DYNAMIC_START) {
991 SCLogError(SC_ERR_INVALID_SIGNATURE, "previous transforms not consumed "
992 "(list: %u, transform_cnt %u)", s->init_data->list,
993 s->init_data->transform_cnt);
994 SCReturnInt(-1);
995 }
996
989997 SCLogDebug("buffer %d has transform(s) registered: %d",
990998 s->init_data->list, s->init_data->transforms[0]);
991999 int new_list = DetectBufferTypeGetByIdTransforms(de_ctx, s->init_data->list,
9921000 s->init_data->transforms, s->init_data->transform_cnt);
9931001 if (new_list == -1) {
994 return -1;
1002 SCReturnInt(-1);
9951003 }
9961004 SCLogDebug("new_list %d", new_list);
9971005 s->init_data->list = new_list;
10001008 s->init_data->transform_cnt = 0;
10011009 }
10021010
1003 return 0;
1011 SCReturnInt(0);
10041012 }
10051013
10061014 void InspectionBufferClean(DetectEngineThreadCtx *det_ctx)
30473055 return item->id;
30483056 }
30493057
3058 /** \brief Remove Thread keyword context registration
3059 *
3060 * \param de_ctx detection engine to deregister from
3061 * \param det_ctx detection engine thread context to deregister from
3062 * \param data keyword init data to pass to Func. Can be NULL.
3063 * \param name keyword name for error printing
3064 *
3065 * \retval 1 Item unregistered
3066 * \retval 0 otherwise
3067 *
3068 * \note make sure "data" remains valid and it free'd elsewhere. It's
3069 * recommended to store it in the keywords global ctx so that
3070 * it's freed when the de_ctx is freed.
3071 */
3072 int DetectUnregisterThreadCtxFuncs(DetectEngineCtx *de_ctx,
3073 DetectEngineThreadCtx *det_ctx, void *data, const char *name)
3074 {
3075 BUG_ON(de_ctx == NULL);
3076
3077 DetectEngineThreadKeywordCtxItem *item = de_ctx->keyword_list;
3078 DetectEngineThreadKeywordCtxItem *prev_item = NULL;
3079 while (item != NULL) {
3080 if (strcmp(name, item->name) == 0 && (data == item->data)) {
3081 if (prev_item == NULL)
3082 de_ctx->keyword_list = item->next;
3083 else
3084 prev_item->next = item->next;
3085 if (det_ctx)
3086 item->FreeFunc(det_ctx->keyword_ctxs_array[item->id]);
3087 SCFree(item);
3088 return 1;
3089 }
3090 prev_item = item;
3091 item = item->next;
3092 }
3093 return 0;
3094 }
30503095 /** \brief Retrieve thread local keyword ctx by id
30513096 *
30523097 * \param det_ctx detection engine thread ctx to retrieve the ctx from
9797 return;
9898 }
9999
100 if (priority <= tmp->priority)
100 /* We need a strict check to be sure that the current list
101 * was not already registered
102 * and other lists with the same priority hide it.
103 */
104 if (priority < tmp->priority)
101105 break;
102106
103107 ip = tmp;
161165 {
162166 sigmatch_table[DETECT_FAST_PATTERN].name = "fast_pattern";
163167 sigmatch_table[DETECT_FAST_PATTERN].desc = "force using preceding content in the multi pattern matcher";
164 sigmatch_table[DETECT_FAST_PATTERN].url = DOC_URL DOC_VERSION "/rules/prefilter-keywords.html#fast-pattern";
168 sigmatch_table[DETECT_FAST_PATTERN].url = "/rules/prefilter-keywords.html#fast-pattern";
165169 sigmatch_table[DETECT_FAST_PATTERN].Match = NULL;
166170 sigmatch_table[DETECT_FAST_PATTERN].Setup = DetectFastPatternSetup;
167171 sigmatch_table[DETECT_FAST_PATTERN].Free = NULL;
8282 sigmatch_table[DETECT_FILE_DATA].name = "file.data";
8383 sigmatch_table[DETECT_FILE_DATA].alias = "file_data";
8484 sigmatch_table[DETECT_FILE_DATA].desc = "make content keywords match on file data";
85 sigmatch_table[DETECT_FILE_DATA].url = DOC_URL DOC_VERSION "/rules/http-keywords.html#file-data";
85 sigmatch_table[DETECT_FILE_DATA].url = "/rules/http-keywords.html#file-data";
8686 sigmatch_table[DETECT_FILE_DATA].Setup = DetectFiledataSetup;
8787 #ifdef UNITTESTS
8888 sigmatch_table[DETECT_FILE_DATA].RegisterTests = DetectFiledataRegisterTests;
6464 {
6565 sigmatch_table[DETECT_FILEEXT].name = "fileext";
6666 sigmatch_table[DETECT_FILEEXT].desc = "match on the extension of a file name";
67 sigmatch_table[DETECT_FILEEXT].url = DOC_URL DOC_VERSION "/rules/file-keywords.html#fileext";
67 sigmatch_table[DETECT_FILEEXT].url = "/rules/file-keywords.html#fileext";
6868 sigmatch_table[DETECT_FILEEXT].FileMatch = DetectFileextMatch;
6969 sigmatch_table[DETECT_FILEEXT].Setup = DetectFileextSetup;
7070 sigmatch_table[DETECT_FILEEXT].Free = DetectFileextFree;
7070 {
7171 sigmatch_table[DETECT_FILEMAGIC].name = "filemagic";
7272 sigmatch_table[DETECT_FILEMAGIC].desc = "match on the information libmagic returns about a file";
73 sigmatch_table[DETECT_FILEMAGIC].url = DOC_URL DOC_VERSION "/rules/file-keywords.html#filemagic";
73 sigmatch_table[DETECT_FILEMAGIC].url = "/rules/file-keywords.html#filemagic";
7474 sigmatch_table[DETECT_FILEMAGIC].Setup = DetectFilemagicSetupNoSupport;
7575 sigmatch_table[DETECT_FILEMAGIC].flags = SIGMATCH_QUOTES_MANDATORY|SIGMATCH_HANDLE_NEGATION;
7676 }
105105 {
106106 sigmatch_table[DETECT_FILEMAGIC].name = "filemagic";
107107 sigmatch_table[DETECT_FILEMAGIC].desc = "match on the information libmagic returns about a file";
108 sigmatch_table[DETECT_FILEMAGIC].url = DOC_URL DOC_VERSION "/rules/file-keywords.html#filemagic";
108 sigmatch_table[DETECT_FILEMAGIC].url = "/rules/file-keywords.html#filemagic";
109109 sigmatch_table[DETECT_FILEMAGIC].FileMatch = DetectFilemagicMatch;
110110 sigmatch_table[DETECT_FILEMAGIC].Setup = DetectFilemagicSetup;
111111 sigmatch_table[DETECT_FILEMAGIC].Free = DetectFilemagicFree;
115115
116116 sigmatch_table[DETECT_FILE_MAGIC].name = "file.magic";
117117 sigmatch_table[DETECT_FILE_MAGIC].desc = "sticky buffer to match on the file magic";
118 sigmatch_table[DETECT_FILE_MAGIC].url = DOC_URL DOC_VERSION "/rules/file-keywords.html#filemagic";
118 sigmatch_table[DETECT_FILE_MAGIC].url = "/rules/file-keywords.html#filemagic";
119119 sigmatch_table[DETECT_FILE_MAGIC].Setup = DetectFilemagicSetupSticky;
120120 sigmatch_table[DETECT_FILE_MAGIC].flags = SIGMATCH_NOOPT|SIGMATCH_INFO_STICKY_BUFFER;
121121
6868 {
6969 sigmatch_table[DETECT_FILEMD5].name = "filemd5";
7070 sigmatch_table[DETECT_FILEMD5].desc = "match file MD5 against list of MD5 checksums";
71 sigmatch_table[DETECT_FILEMD5].url = DOC_URL DOC_VERSION "/rules/file-keywords.html#filemd5";
71 sigmatch_table[DETECT_FILEMD5].url = "/rules/file-keywords.html#filemd5";
7272 sigmatch_table[DETECT_FILEMD5].FileMatch = DetectFileHashMatch;
7373 sigmatch_table[DETECT_FILEMD5].Setup = DetectFileMd5Setup;
7474 sigmatch_table[DETECT_FILEMD5].Free = DetectFileHashFree;
7878 {
7979 sigmatch_table[DETECT_FILENAME].name = "filename";
8080 sigmatch_table[DETECT_FILENAME].desc = "match on the file name";
81 sigmatch_table[DETECT_FILENAME].url = DOC_URL DOC_VERSION "/rules/file-keywords.html#filename";
81 sigmatch_table[DETECT_FILENAME].url = "/rules/file-keywords.html#filename";
8282 sigmatch_table[DETECT_FILENAME].FileMatch = DetectFilenameMatch;
8383 sigmatch_table[DETECT_FILENAME].Setup = DetectFilenameSetup;
8484 sigmatch_table[DETECT_FILENAME].Free = DetectFilenameFree;
8888
8989 sigmatch_table[DETECT_FILE_NAME].name = "file.name";
9090 sigmatch_table[DETECT_FILE_NAME].desc = "sticky buffer to match on the file name";
91 sigmatch_table[DETECT_FILE_NAME].url = DOC_URL DOC_VERSION "/rules/file-keywords.html#filename";
91 sigmatch_table[DETECT_FILE_NAME].url = "/rules/file-keywords.html#filename";
9292 sigmatch_table[DETECT_FILE_NAME].Setup = DetectFilenameSetupSticky;
9393 sigmatch_table[DETECT_FILE_NAME].flags = SIGMATCH_NOOPT|SIGMATCH_INFO_STICKY_BUFFER;
9494
6868 {
6969 sigmatch_table[DETECT_FILESHA1].name = "filesha1";
7070 sigmatch_table[DETECT_FILESHA1].desc = "match file SHA-1 against list of SHA-1 checksums";
71 sigmatch_table[DETECT_FILESHA1].url = DOC_URL DOC_VERSION "/rules/file-keywords.html#filesha1";
71 sigmatch_table[DETECT_FILESHA1].url = "/rules/file-keywords.html#filesha1";
7272 sigmatch_table[DETECT_FILESHA1].FileMatch = DetectFileHashMatch;
7373 sigmatch_table[DETECT_FILESHA1].Setup = DetectFileSha1Setup;
7474 sigmatch_table[DETECT_FILESHA1].Free = DetectFileHashFree;
6868 {
6969 sigmatch_table[DETECT_FILESHA256].name = "filesha256";
7070 sigmatch_table[DETECT_FILESHA256].desc = "match file SHA-256 against list of SHA-256 checksums";
71 sigmatch_table[DETECT_FILESHA256].url = DOC_URL DOC_VERSION "/rules/file-keywords.html#filesha256";
71 sigmatch_table[DETECT_FILESHA256].url = "/rules/file-keywords.html#filesha256";
7272 sigmatch_table[DETECT_FILESHA256].FileMatch = DetectFileHashMatch;
7373 sigmatch_table[DETECT_FILESHA256].Setup = DetectFileSha256Setup;
7474 sigmatch_table[DETECT_FILESHA256].Free = DetectFileHashFree;
6464 {
6565 sigmatch_table[DETECT_FILESIZE].name = "filesize";
6666 sigmatch_table[DETECT_FILESIZE].desc = "match on the size of the file as it is being transferred";
67 sigmatch_table[DETECT_FILESIZE].url = DOC_URL DOC_VERSION "/rules/file-keywords.html#filesize";
67 sigmatch_table[DETECT_FILESIZE].url = "/rules/file-keywords.html#filesize";
6868 sigmatch_table[DETECT_FILESIZE].FileMatch = DetectFilesizeMatch;
6969 sigmatch_table[DETECT_FILESIZE].Setup = DetectFilesizeSetup;
7070 sigmatch_table[DETECT_FILESIZE].Free = DetectFilesizeFree;
0 /* Copyright (C) 2007-2012 Open Information Security Foundation
0 /* Copyright (C) 2007-2020 Open Information Security Foundation
11 *
22 * You can copy, redistribute or modify this Program under the terms of
33 * the GNU General Public License version 2 as published by the Free
7575 {
7676 sigmatch_table[DETECT_FILESTORE].name = "filestore";
7777 sigmatch_table[DETECT_FILESTORE].desc = "stores files to disk if the rule matched";
78 sigmatch_table[DETECT_FILESTORE].url = DOC_URL DOC_VERSION "/rules/file-keywords.html#filestore";
78 sigmatch_table[DETECT_FILESTORE].url = "/rules/file-keywords.html#filestore";
7979 sigmatch_table[DETECT_FILESTORE].FileMatch = DetectFilestoreMatch;
8080 sigmatch_table[DETECT_FILESTORE].Setup = DetectFilestoreSetup;
8181 sigmatch_table[DETECT_FILESTORE].Free = DetectFilestoreFree;
343343 sm->type = DETECT_FILESTORE;
344344
345345 if (str != NULL && strlen(str) > 0) {
346 char str_0[32];
347 char str_1[32];
348 char str_2[32];
346349 SCLogDebug("str %s", str);
347350
348351 ret = pcre_exec(parse_regex, parse_regex_study, str, strlen(str), 0, 0, ov, MAX_SUBSTRINGS);
352355 }
353356
354357 if (ret > 1) {
355 const char *str_ptr;
356 res = pcre_get_substring((char *)str, ov, MAX_SUBSTRINGS, 1, &str_ptr);
358 res = pcre_copy_substring((char *)str, ov, MAX_SUBSTRINGS, 1, str_0, sizeof(str_0));
357359 if (res < 0) {
358 SCLogError(SC_ERR_PCRE_GET_SUBSTRING, "pcre_get_substring failed");
360 SCLogError(SC_ERR_PCRE_COPY_SUBSTRING, "pcre_copy_substring failed");
359361 goto error;
360362 }
361 args[0] = (char *)str_ptr;
363 args[0] = (char *)str_0;
362364
363365 if (ret > 2) {
364 res = pcre_get_substring((char *)str, ov, MAX_SUBSTRINGS, 2, &str_ptr);
366 res = pcre_copy_substring((char *)str, ov, MAX_SUBSTRINGS, 2, str_1, sizeof(str_1));
365367 if (res < 0) {
366 SCLogError(SC_ERR_PCRE_GET_SUBSTRING, "pcre_get_substring failed");
368 SCLogError(SC_ERR_PCRE_COPY_SUBSTRING, "pcre_copy_substring failed");
367369 goto error;
368370 }
369 args[1] = (char *)str_ptr;
371 args[1] = (char *)str_1;
370372 }
371373 if (ret > 3) {
372 res = pcre_get_substring((char *)str, ov, MAX_SUBSTRINGS, 3, &str_ptr);
374 res = pcre_copy_substring((char *)str, ov, MAX_SUBSTRINGS, 3, str_2, sizeof(str_2));
373375 if (res < 0) {
374 SCLogError(SC_ERR_PCRE_GET_SUBSTRING, "pcre_get_substring failed");
376 SCLogError(SC_ERR_PCRE_COPY_SUBSTRING, "pcre_copy_substring failed");
375377 goto error;
376378 }
377 args[2] = (char *)str_ptr;
379 args[2] = (char *)str_2;
378380 }
379381 }
380382
6464 {
6565 sigmatch_table[DETECT_FLOW].name = "flow";
6666 sigmatch_table[DETECT_FLOW].desc = "match on direction and state of the flow";
67 sigmatch_table[DETECT_FLOW].url = DOC_URL DOC_VERSION "/rules/flow-keywords.html#flow";
67 sigmatch_table[DETECT_FLOW].url = "/rules/flow-keywords.html#flow";
6868 sigmatch_table[DETECT_FLOW].Match = DetectFlowMatch;
6969 sigmatch_table[DETECT_FLOW].Setup = DetectFlowSetup;
7070 sigmatch_table[DETECT_FLOW].Free = DetectFlowFree;
5858 {
5959 sigmatch_table[DETECT_FLOWBITS].name = "flowbits";
6060 sigmatch_table[DETECT_FLOWBITS].desc = "operate on flow flag";
61 sigmatch_table[DETECT_FLOWBITS].url = DOC_URL DOC_VERSION "/rules/flow-keywords.html#flowbits";
61 sigmatch_table[DETECT_FLOWBITS].url = "/rules/flow-keywords.html#flowbits";
6262 sigmatch_table[DETECT_FLOWBITS].Match = DetectFlowbitMatch;
6363 sigmatch_table[DETECT_FLOWBITS].Setup = DetectFlowbitSetup;
6464 sigmatch_table[DETECT_FLOWBITS].Free = DetectFlowbitFree;
6262 {
6363 sigmatch_table[DETECT_FLOWINT].name = "flowint";
6464 sigmatch_table[DETECT_FLOWINT].desc = "operate on a per-flow integer";
65 sigmatch_table[DETECT_FLOWINT].url = DOC_URL DOC_VERSION "/rules/flow-keywords.html#flowint";
65 sigmatch_table[DETECT_FLOWINT].url = "/rules/flow-keywords.html#flowint";
6666 sigmatch_table[DETECT_FLOWINT].Match = DetectFlowintMatch;
6767 sigmatch_table[DETECT_FLOWINT].Setup = DetectFlowintSetup;
6868 sigmatch_table[DETECT_FLOWINT].Free = DetectFlowintFree;
0 /* Copyright (C) 2007-2014 Open Information Security Foundation
0 /* Copyright (C) 2007-2020 Open Information Security Foundation
11 *
22 * You can copy, redistribute or modify this Program under the terms of
33 * the GNU General Public License version 2 as published by the Free
117117 {
118118 DetectFlowvarData *fd = NULL;
119119 SigMatch *sm = NULL;
120 char *varname = NULL, *varcontent = NULL;
120 char varname[64], varcontent[64];
121121 #define MAX_SUBSTRINGS 30
122122 int ret = 0, res = 0;
123123 int ov[MAX_SUBSTRINGS];
124 const char *str_ptr;
125124 uint8_t *content = NULL;
126125 uint16_t contentlen = 0;
127126 uint32_t contentflags = s->init_data->negated ? DETECT_CONTENT_NEGATED : 0;
132131 return -1;
133132 }
134133
135 res = pcre_get_substring((char *)rawstr, ov, MAX_SUBSTRINGS, 1, &str_ptr);
134 res = pcre_copy_substring((char *)rawstr, ov, MAX_SUBSTRINGS, 1, varname, sizeof(varname));
136135 if (res < 0) {
137 SCLogError(SC_ERR_PCRE_GET_SUBSTRING, "pcre_get_substring failed");
136 SCLogError(SC_ERR_PCRE_COPY_SUBSTRING, "pcre_copy_substring failed");
138137 return -1;
139138 }
140 varname = (char *)str_ptr;
141
142 res = pcre_get_substring((char *)rawstr, ov, MAX_SUBSTRINGS, 2, &str_ptr);
139
140 res = pcre_copy_substring((char *)rawstr, ov, MAX_SUBSTRINGS, 2, varcontent, sizeof(varcontent));
143141 if (res < 0) {
144 SCLogError(SC_ERR_PCRE_GET_SUBSTRING, "pcre_get_substring failed");
142 SCLogError(SC_ERR_PCRE_COPY_SUBSTRING, "pcre_copy_substring failed");
145143 return -1;
146144 }
147 varcontent = (char *)str_ptr;
148
145
146 int varcontent_index = 0;
149147 if (strlen(varcontent) >= 2) {
150148 if (varcontent[0] == '"')
151 varcontent++;
149 varcontent_index++;
152150 if (varcontent[strlen(varcontent)-1] == '"')
153151 varcontent[strlen(varcontent)-1] = '\0';
154152 }
155 SCLogDebug("varcontent %s", varcontent);
156
157 res = DetectContentDataParse("flowvar", varcontent, &content, &contentlen);
153 SCLogDebug("varcontent %s", &varcontent[varcontent_index]);
154
155 res = DetectContentDataParse("flowvar", &varcontent[varcontent_index], &content, &contentlen);
158156 if (res == -1)
159157 goto error;
160158
8383 {
8484 sigmatch_table[DETECT_FRAGBITS].name = "fragbits";
8585 sigmatch_table[DETECT_FRAGBITS].desc = "check if the fragmentation and reserved bits are set in the IP header";
86 sigmatch_table[DETECT_FRAGBITS].url = DOC_URL DOC_VERSION "/rules/header-keywords.html#fragbits-ip-fragmentation";
86 sigmatch_table[DETECT_FRAGBITS].url = "/rules/header-keywords.html#fragbits-ip-fragmentation";
8787 sigmatch_table[DETECT_FRAGBITS].Match = DetectFragBitsMatch;
8888 sigmatch_table[DETECT_FRAGBITS].Setup = DetectFragBitsSetup;
8989 sigmatch_table[DETECT_FRAGBITS].Free = DetectFragBitsFree;
5959 {
6060 sigmatch_table[DETECT_FRAGOFFSET].name = "fragoffset";
6161 sigmatch_table[DETECT_FRAGOFFSET].desc = "match on specific decimal values of the IP fragment offset field";
62 sigmatch_table[DETECT_FRAGOFFSET].url = DOC_URL DOC_VERSION "/rules/header-keywords.html#fragoffset";
62 sigmatch_table[DETECT_FRAGOFFSET].url = "/rules/header-keywords.html#fragoffset";
6363 sigmatch_table[DETECT_FRAGOFFSET].Match = DetectFragOffsetMatch;
6464 sigmatch_table[DETECT_FRAGOFFSET].Setup = DetectFragOffsetSetup;
6565 sigmatch_table[DETECT_FRAGOFFSET].Free = DetectFragOffsetFree;
7171 sigmatch_table[DETECT_FTPBOUNCE].Setup = DetectFtpbounceSetup;
7272 sigmatch_table[DETECT_FTPBOUNCE].AppLayerTxMatch = DetectFtpbounceALMatch;
7373 sigmatch_table[DETECT_FTPBOUNCE].RegisterTests = DetectFtpbounceRegisterTests;
74 sigmatch_table[DETECT_FTPBOUNCE].url = DOC_URL DOC_VERSION "/rules/ftp-keywords.html#ftpbounce";
74 sigmatch_table[DETECT_FTPBOUNCE].url = "/rules/ftp-keywords.html#ftpbounce";
7575 sigmatch_table[DETECT_FTPBOUNCE].flags = SIGMATCH_NOOPT;
7676
7777 g_ftp_request_list_id = DetectBufferTypeRegister("ftp_request");
6464 sigmatch_table[DETECT_FTPDATA].name = "ftpdata_command";
6565 /* description: listed in "suricata --list-keywords=all" */
6666 sigmatch_table[DETECT_FTPDATA].desc = "match FTP command triggering a FTP data channel";
67 sigmatch_table[DETECT_FTPDATA].url = DOC_URL DOC_VERSION "/rules/ftp-keywords.html#ftpdata-command";
67 sigmatch_table[DETECT_FTPDATA].url = "/rules/ftp-keywords.html#ftpdata-command";
6868 sigmatch_table[DETECT_FTPDATA].AppLayerTxMatch = DetectFtpdataMatch;
6969 /* setup function is called during signature parsing, when the ftpcommand
7070 * keyword is encountered in the rule */
5555 {
5656 sigmatch_table[DETECT_GEOIP].name = "geoip";
5757 sigmatch_table[DETECT_GEOIP].desc = "match on the source, destination or source and destination IP addresses of network traffic, and to see to which country it belongs";
58 sigmatch_table[DETECT_GEOIP].url = DOC_URL DOC_VERSION "/rules/header-keywords.html#geoip";
58 sigmatch_table[DETECT_GEOIP].url = "/rules/header-keywords.html#geoip";
5959 sigmatch_table[DETECT_GEOIP].Setup = DetectGeoipSetupNoSupport;
6060 sigmatch_table[DETECT_GEOIP].Free = NULL;
6161 sigmatch_table[DETECT_GEOIP].RegisterTests = NULL;
7878 void DetectGeoipRegister(void)
7979 {
8080 sigmatch_table[DETECT_GEOIP].name = "geoip";
81 sigmatch_table[DETECT_GEOIP].url = DOC_URL DOC_VERSION "/rules/header-keywords.html#geoip";
81 sigmatch_table[DETECT_GEOIP].url = "/rules/header-keywords.html#geoip";
8282 sigmatch_table[DETECT_GEOIP].desc = "keyword to match on country of src and or dst IP";
8383 sigmatch_table[DETECT_GEOIP].Match = DetectGeoipMatch;
8484 sigmatch_table[DETECT_GEOIP].Setup = DetectGeoipSetup;
4545 {
4646 sigmatch_table[DETECT_GID].name = "gid";
4747 sigmatch_table[DETECT_GID].desc = "give different groups of signatures another id value";
48 sigmatch_table[DETECT_GID].url = DOC_URL DOC_VERSION "/rules/meta.html#gid-group-id";
48 sigmatch_table[DETECT_GID].url = "/rules/meta.html#gid-group-id";
4949 sigmatch_table[DETECT_GID].Match = NULL;
5050 sigmatch_table[DETECT_GID].Setup = DetectGidSetup;
5151 sigmatch_table[DETECT_GID].Free = NULL;
7777 {
7878 sigmatch_table[DETECT_HOSTBITS].name = "hostbits";
7979 sigmatch_table[DETECT_HOSTBITS].desc = "operate on host flag";
80 // sigmatch_table[DETECT_HOSTBITS].url = DOC_URL DOC_VERSION "/rules/flow-keywords.html#flowbits";
80 // sigmatch_table[DETECT_HOSTBITS].url = "/rules/flow-keywords.html#flowbits";
8181 sigmatch_table[DETECT_HOSTBITS].Match = DetectHostbitMatch;
8282 sigmatch_table[DETECT_HOSTBITS].Setup = DetectHostbitSetup;
8383 sigmatch_table[DETECT_HOSTBITS].Free = DetectHostbitFree;
8080 /* http_client_body content modifier */
8181 sigmatch_table[DETECT_AL_HTTP_CLIENT_BODY].name = "http_client_body";
8282 sigmatch_table[DETECT_AL_HTTP_CLIENT_BODY].desc = "content modifier to match only on HTTP request-body";
83 sigmatch_table[DETECT_AL_HTTP_CLIENT_BODY].url = DOC_URL DOC_VERSION "/rules/http-keywords.html#http-client-body";
83 sigmatch_table[DETECT_AL_HTTP_CLIENT_BODY].url = "/rules/http-keywords.html#http-client-body";
8484 sigmatch_table[DETECT_AL_HTTP_CLIENT_BODY].Setup = DetectHttpClientBodySetup;
8585 #ifdef UNITTESTS
8686 sigmatch_table[DETECT_AL_HTTP_CLIENT_BODY].RegisterTests = DetectHttpClientBodyRegisterTests;
9292 /* http.request_body sticky buffer */
9393 sigmatch_table[DETECT_HTTP_REQUEST_BODY].name = "http.request_body";
9494 sigmatch_table[DETECT_HTTP_REQUEST_BODY].desc = "sticky buffer to match the HTTP request body buffer";
95 sigmatch_table[DETECT_HTTP_REQUEST_BODY].url = DOC_URL DOC_VERSION "/rules/http-keywords.html#http-client-body";
95 sigmatch_table[DETECT_HTTP_REQUEST_BODY].url = "/rules/http-keywords.html#http-client-body";
9696 sigmatch_table[DETECT_HTTP_REQUEST_BODY].Setup = DetectHttpClientBodySetupSticky;
9797 sigmatch_table[DETECT_HTTP_REQUEST_BODY].flags |= SIGMATCH_NOOPT;
9898 sigmatch_table[DETECT_HTTP_REQUEST_BODY].flags |= SIGMATCH_INFO_STICKY_BUFFER;
8484 /* http_cookie content modifier */
8585 sigmatch_table[DETECT_AL_HTTP_COOKIE].name = "http_cookie";
8686 sigmatch_table[DETECT_AL_HTTP_COOKIE].desc = "content modifier to match only on the HTTP cookie-buffer";
87 sigmatch_table[DETECT_AL_HTTP_COOKIE].url = DOC_URL DOC_VERSION "/rules/http-keywords.html#http-cookie";
87 sigmatch_table[DETECT_AL_HTTP_COOKIE].url = "/rules/http-keywords.html#http-cookie";
8888 sigmatch_table[DETECT_AL_HTTP_COOKIE].Setup = DetectHttpCookieSetup;
8989 #ifdef UNITTESTS
9090 sigmatch_table[DETECT_AL_HTTP_COOKIE].RegisterTests = DetectHttpCookieRegisterTests;
9696 /* http.cookie sticky buffer */
9797 sigmatch_table[DETECT_HTTP_COOKIE].name = "http.cookie";
9898 sigmatch_table[DETECT_HTTP_COOKIE].desc = "sticky buffer to match on the HTTP Cookie/Set-Cookie buffers";
99 sigmatch_table[DETECT_HTTP_COOKIE].url = DOC_URL DOC_VERSION "/rules/http-keywords.html#http-cookie";
99 sigmatch_table[DETECT_HTTP_COOKIE].url = "/rules/http-keywords.html#http-cookie";
100100 sigmatch_table[DETECT_HTTP_COOKIE].Setup = DetectHttpCookieSetupSticky;
101101 sigmatch_table[DETECT_HTTP_COOKIE].flags |= SIGMATCH_NOOPT;
102102 sigmatch_table[DETECT_HTTP_COOKIE].flags |= SIGMATCH_INFO_STICKY_BUFFER;
392392 sigmatch_table[DETECT_AL_HTTP_HEADER_NAMES].name = KEYWORD_NAME;
393393 sigmatch_table[DETECT_AL_HTTP_HEADER_NAMES].alias = KEYWORD_NAME_LEGACY;
394394 sigmatch_table[DETECT_AL_HTTP_HEADER_NAMES].desc = BUFFER_NAME " sticky buffer";
395 sigmatch_table[DETECT_AL_HTTP_HEADER_NAMES].url = DOC_URL DOC_VERSION "/rules/" KEYWORD_DOC;
395 sigmatch_table[DETECT_AL_HTTP_HEADER_NAMES].url = "/rules/" KEYWORD_DOC;
396396 sigmatch_table[DETECT_AL_HTTP_HEADER_NAMES].Setup = DetectHttpHeaderNamesSetup;
397397
398398 sigmatch_table[DETECT_AL_HTTP_HEADER_NAMES].flags |= SIGMATCH_NOOPT | SIGMATCH_INFO_STICKY_BUFFER;
407407 /* http_header content modifier */
408408 sigmatch_table[DETECT_AL_HTTP_HEADER].name = "http_header";
409409 sigmatch_table[DETECT_AL_HTTP_HEADER].desc = "content modifier to match only on the HTTP header-buffer";
410 sigmatch_table[DETECT_AL_HTTP_HEADER].url = DOC_URL DOC_VERSION "/rules/http-keywords.html#http-header-and-http-raw-header";
410 sigmatch_table[DETECT_AL_HTTP_HEADER].url = "/rules/http-keywords.html#http-header-and-http-raw-header";
411411 sigmatch_table[DETECT_AL_HTTP_HEADER].Setup = DetectHttpHeaderSetup;
412412 #ifdef UNITTESTS
413413 sigmatch_table[DETECT_AL_HTTP_HEADER].RegisterTests = DetectHttpHeaderRegisterTests;
419419 /* http.header sticky buffer */
420420 sigmatch_table[DETECT_HTTP_HEADER].name = "http.header";
421421 sigmatch_table[DETECT_HTTP_HEADER].desc = "sticky buffer to match on the normalized HTTP header-buffer";
422 sigmatch_table[DETECT_HTTP_HEADER].url = DOC_URL DOC_VERSION "/rules/http-keywords.html#http-header-and-http-raw-header";
422 sigmatch_table[DETECT_HTTP_HEADER].url = "/rules/http-keywords.html#http-header-and-http-raw-header";
423423 sigmatch_table[DETECT_HTTP_HEADER].Setup = DetectHttpHeaderSetupSticky;
424424 sigmatch_table[DETECT_HTTP_HEADER].flags |= SIGMATCH_NOOPT;
425425 sigmatch_table[DETECT_HTTP_HEADER].flags |= SIGMATCH_INFO_STICKY_BUFFER;
141141 sigmatch_table[KEYWORD_ID].alias = KEYWORD_NAME_LEGACY;
142142 #endif
143143 sigmatch_table[KEYWORD_ID].desc = KEYWORD_NAME " sticky buffer for the " BUFFER_DESC;
144 sigmatch_table[KEYWORD_ID].url = DOC_URL DOC_VERSION "/rules/" KEYWORD_DOC;
144 sigmatch_table[KEYWORD_ID].url = "/rules/" KEYWORD_DOC;
145145 sigmatch_table[KEYWORD_ID].Setup = DetectHttpHeadersSetupSticky;
146146 sigmatch_table[KEYWORD_ID].flags |= SIGMATCH_NOOPT | SIGMATCH_INFO_STICKY_BUFFER;
147147
8383 /* http_host content modifier */
8484 sigmatch_table[DETECT_AL_HTTP_HOST].name = "http_host";
8585 sigmatch_table[DETECT_AL_HTTP_HOST].desc = "content modifier to match on the HTTP hostname";
86 sigmatch_table[DETECT_AL_HTTP_HOST].url = DOC_URL DOC_VERSION "/rules/http-keywords.html#http-host-and-http-raw-host";
86 sigmatch_table[DETECT_AL_HTTP_HOST].url = "/rules/http-keywords.html#http-host-and-http-raw-host";
8787 sigmatch_table[DETECT_AL_HTTP_HOST].Setup = DetectHttpHHSetup;
8888 #ifdef UNITTESTS
8989 sigmatch_table[DETECT_AL_HTTP_HOST].RegisterTests = DetectHttpHHRegisterTests;
9494 /* http.host sticky buffer */
9595 sigmatch_table[DETECT_HTTP_HOST].name = "http.host";
9696 sigmatch_table[DETECT_HTTP_HOST].desc = "sticky buffer to match on the HTTP Host buffer";
97 sigmatch_table[DETECT_HTTP_HOST].url = DOC_URL DOC_VERSION "/rules/http-keywords.html#http-host-and-http-raw-host";
97 sigmatch_table[DETECT_HTTP_HOST].url = "/rules/http-keywords.html#http-host-and-http-raw-host";
9898 sigmatch_table[DETECT_HTTP_HOST].Setup = DetectHttpHostSetup;
9999 sigmatch_table[DETECT_HTTP_HOST].flags |= SIGMATCH_NOOPT|SIGMATCH_INFO_STICKY_BUFFER;
100100
117117 /* http_raw_host content modifier */
118118 sigmatch_table[DETECT_AL_HTTP_RAW_HOST].name = "http_raw_host";
119119 sigmatch_table[DETECT_AL_HTTP_RAW_HOST].desc = "content modifier to match on the HTTP host header or the raw hostname from the HTTP uri";
120 sigmatch_table[DETECT_AL_HTTP_RAW_HOST].url = DOC_URL DOC_VERSION "/rules/http-keywords.html#http-host-and-http-raw-host";
120 sigmatch_table[DETECT_AL_HTTP_RAW_HOST].url = "/rules/http-keywords.html#http-host-and-http-raw-host";
121121 sigmatch_table[DETECT_AL_HTTP_RAW_HOST].Setup = DetectHttpHRHSetup;
122122 sigmatch_table[DETECT_AL_HTTP_RAW_HOST].flags |= SIGMATCH_NOOPT|SIGMATCH_INFO_CONTENT_MODIFIER;
123123 sigmatch_table[DETECT_AL_HTTP_RAW_HOST].alternative = DETECT_HTTP_HOST_RAW;
125125 /* http.host sticky buffer */
126126 sigmatch_table[DETECT_HTTP_HOST_RAW].name = "http.host.raw";
127127 sigmatch_table[DETECT_HTTP_HOST_RAW].desc = "sticky buffer to match on the HTTP host header or the raw hostname from the HTTP uri";
128 sigmatch_table[DETECT_HTTP_HOST_RAW].url = DOC_URL DOC_VERSION "/rules/http-keywords.html#http-host-and-http-raw-host";
128 sigmatch_table[DETECT_HTTP_HOST_RAW].url = "/rules/http-keywords.html#http-host-and-http-raw-host";
129129 sigmatch_table[DETECT_HTTP_HOST_RAW].Setup = DetectHttpHostRawSetupSticky;
130130 sigmatch_table[DETECT_HTTP_HOST_RAW].flags |= SIGMATCH_NOOPT|SIGMATCH_INFO_STICKY_BUFFER;
131131
7878 /* http_method content modifier */
7979 sigmatch_table[DETECT_AL_HTTP_METHOD].name = "http_method";
8080 sigmatch_table[DETECT_AL_HTTP_METHOD].desc = "content modifier to match only on the HTTP method-buffer";
81 sigmatch_table[DETECT_AL_HTTP_METHOD].url = DOC_URL DOC_VERSION "/rules/http-keywords.html#http-method";
81 sigmatch_table[DETECT_AL_HTTP_METHOD].url = "/rules/http-keywords.html#http-method";
8282 sigmatch_table[DETECT_AL_HTTP_METHOD].Match = NULL;
8383 sigmatch_table[DETECT_AL_HTTP_METHOD].Setup = DetectHttpMethodSetup;
8484 #ifdef UNITTESTS
9090 /* http.method sticky buffer */
9191 sigmatch_table[DETECT_HTTP_METHOD].name = "http.method";
9292 sigmatch_table[DETECT_HTTP_METHOD].desc = "sticky buffer to match specifically and only on the HTTP method buffer";
93 sigmatch_table[DETECT_HTTP_METHOD].url = DOC_URL DOC_VERSION "/rules/http-keywords.html#http-method";
93 sigmatch_table[DETECT_HTTP_METHOD].url = "/rules/http-keywords.html#http-method";
9494 sigmatch_table[DETECT_HTTP_METHOD].Setup = DetectHttpMethodSetupSticky;
9595 sigmatch_table[DETECT_HTTP_METHOD].flags |= SIGMATCH_NOOPT|SIGMATCH_INFO_STICKY_BUFFER;
9696
123123 sigmatch_table[DETECT_AL_HTTP_PROTOCOL].name = KEYWORD_NAME;
124124 sigmatch_table[DETECT_AL_HTTP_PROTOCOL].alias = KEYWORD_NAME_LEGACY;
125125 sigmatch_table[DETECT_AL_HTTP_PROTOCOL].desc = BUFFER_NAME " sticky buffer";
126 sigmatch_table[DETECT_AL_HTTP_PROTOCOL].url = DOC_URL DOC_VERSION "/rules/" KEYWORD_DOC;
126 sigmatch_table[DETECT_AL_HTTP_PROTOCOL].url = "/rules/" KEYWORD_DOC;
127127 sigmatch_table[DETECT_AL_HTTP_PROTOCOL].Setup = DetectHttpProtocolSetup;
128128 sigmatch_table[DETECT_AL_HTTP_PROTOCOL].flags |= SIGMATCH_INFO_STICKY_BUFFER | SIGMATCH_NOOPT;
129129
7777 /* http_raw_header content modifier */
7878 sigmatch_table[DETECT_AL_HTTP_RAW_HEADER].name = "http_raw_header";
7979 sigmatch_table[DETECT_AL_HTTP_RAW_HEADER].desc = "content modifier to match the raw HTTP header buffer";
80 sigmatch_table[DETECT_AL_HTTP_RAW_HEADER].url = DOC_URL DOC_VERSION "/rules/http-keywords.html#http-header-and-http-raw-header";
80 sigmatch_table[DETECT_AL_HTTP_RAW_HEADER].url = "/rules/http-keywords.html#http-header-and-http-raw-header";
8181 sigmatch_table[DETECT_AL_HTTP_RAW_HEADER].Setup = DetectHttpRawHeaderSetup;
8282 #ifdef UNITTESTS
8383 sigmatch_table[DETECT_AL_HTTP_RAW_HEADER].RegisterTests = DetectHttpRawHeaderRegisterTests;
8888 /* http.header.raw sticky buffer */
8989 sigmatch_table[DETECT_HTTP_RAW_HEADER].name = "http.header.raw";
9090 sigmatch_table[DETECT_HTTP_RAW_HEADER].desc = "sticky buffer to match the raw HTTP header buffer";
91 sigmatch_table[DETECT_HTTP_RAW_HEADER].url = DOC_URL DOC_VERSION "/rules/http-keywords.html#http-header-and-http-raw-header";
91 sigmatch_table[DETECT_HTTP_RAW_HEADER].url = "/rules/http-keywords.html#http-header-and-http-raw-header";
9292 sigmatch_table[DETECT_HTTP_RAW_HEADER].Setup = DetectHttpRawHeaderSetupSticky;
9393 sigmatch_table[DETECT_HTTP_RAW_HEADER].flags |= SIGMATCH_NOOPT|SIGMATCH_INFO_STICKY_BUFFER;
9494
7575 sigmatch_table[DETECT_AL_HTTP_REQUEST_LINE].name = "http.request_line";
7676 sigmatch_table[DETECT_AL_HTTP_REQUEST_LINE].alias = "http_request_line";
7777 sigmatch_table[DETECT_AL_HTTP_REQUEST_LINE].desc = "sticky buffer to match on the HTTP request line";
78 sigmatch_table[DETECT_AL_HTTP_REQUEST_LINE].url = DOC_URL DOC_VERSION "/rules/http-keywords.html#http-request-line";
78 sigmatch_table[DETECT_AL_HTTP_REQUEST_LINE].url = "/rules/http-keywords.html#http-request-line";
7979 sigmatch_table[DETECT_AL_HTTP_REQUEST_LINE].Match = NULL;
8080 sigmatch_table[DETECT_AL_HTTP_REQUEST_LINE].Setup = DetectHttpRequestLineSetup;
8181 sigmatch_table[DETECT_AL_HTTP_REQUEST_LINE].RegisterTests = DetectHttpRequestLineRegisterTests;
7575 sigmatch_table[DETECT_AL_HTTP_RESPONSE_LINE].name = "http.response_line";
7676 sigmatch_table[DETECT_AL_HTTP_RESPONSE_LINE].alias = "http_response_line";
7777 sigmatch_table[DETECT_AL_HTTP_RESPONSE_LINE].desc = "content modifier to match only on the HTTP response line";
78 sigmatch_table[DETECT_AL_HTTP_RESPONSE_LINE].url = DOC_URL DOC_VERSION "/rules/http-keywords.html#http-response-line";
78 sigmatch_table[DETECT_AL_HTTP_RESPONSE_LINE].url = "/rules/http-keywords.html#http-response-line";
7979 sigmatch_table[DETECT_AL_HTTP_RESPONSE_LINE].Setup = DetectHttpResponseLineSetup;
8080 sigmatch_table[DETECT_AL_HTTP_RESPONSE_LINE].RegisterTests = DetectHttpResponseLineRegisterTests;
8181
7373 /* http_server_body content modifier */
7474 sigmatch_table[DETECT_AL_HTTP_SERVER_BODY].name = "http_server_body";
7575 sigmatch_table[DETECT_AL_HTTP_SERVER_BODY].desc = "content modifier to match on the HTTP response-body";
76 sigmatch_table[DETECT_AL_HTTP_SERVER_BODY].url = DOC_URL DOC_VERSION "/rules/http-keywords.html#http-server-body";
76 sigmatch_table[DETECT_AL_HTTP_SERVER_BODY].url = "/rules/http-keywords.html#http-server-body";
7777 sigmatch_table[DETECT_AL_HTTP_SERVER_BODY].Setup = DetectHttpServerBodySetup;
7878 #ifdef UNITTESTS
7979 sigmatch_table[DETECT_AL_HTTP_SERVER_BODY].RegisterTests = DetectHttpServerBodyRegisterTests;
8585 /* http.request_body sticky buffer */
8686 sigmatch_table[DETECT_HTTP_RESPONSE_BODY].name = "http.response_body";
8787 sigmatch_table[DETECT_HTTP_RESPONSE_BODY].desc = "sticky buffer to match the HTTP response body buffer";
88 sigmatch_table[DETECT_HTTP_RESPONSE_BODY].url = DOC_URL DOC_VERSION "/rules/http-keywords.html#http-server-body";
88 sigmatch_table[DETECT_HTTP_RESPONSE_BODY].url = "/rules/http-keywords.html#http-server-body";
8989 sigmatch_table[DETECT_HTTP_RESPONSE_BODY].Setup = DetectHttpServerBodySetupSticky;
9090 sigmatch_table[DETECT_HTTP_RESPONSE_BODY].flags |= SIGMATCH_NOOPT;
9191 sigmatch_table[DETECT_HTTP_RESPONSE_BODY].flags |= SIGMATCH_INFO_STICKY_BUFFER;
376376 sigmatch_table[DETECT_AL_HTTP_START].name = KEYWORD_NAME;
377377 sigmatch_table[DETECT_AL_HTTP_START].alias = KEYWORD_NAME_LEGACY;
378378 sigmatch_table[DETECT_AL_HTTP_START].desc = BUFFER_NAME " sticky buffer";
379 sigmatch_table[DETECT_AL_HTTP_START].url = DOC_URL DOC_VERSION "/rules/" KEYWORD_DOC;
379 sigmatch_table[DETECT_AL_HTTP_START].url = "/rules/" KEYWORD_DOC;
380380 sigmatch_table[DETECT_AL_HTTP_START].Setup = DetectHttpStartSetup;
381381 sigmatch_table[DETECT_AL_HTTP_START].flags |= SIGMATCH_NOOPT|SIGMATCH_INFO_STICKY_BUFFER;
382382
8080 /* http_stat_code content modifier */
8181 sigmatch_table[DETECT_AL_HTTP_STAT_CODE].name = "http_stat_code";
8282 sigmatch_table[DETECT_AL_HTTP_STAT_CODE].desc = "content modifier to match only on HTTP stat-code-buffer";
83 sigmatch_table[DETECT_AL_HTTP_STAT_CODE].url = DOC_URL DOC_VERSION "/rules/http-keywords.html#http-stat-code";
83 sigmatch_table[DETECT_AL_HTTP_STAT_CODE].url = "/rules/http-keywords.html#http-stat-code";
8484 sigmatch_table[DETECT_AL_HTTP_STAT_CODE].Setup = DetectHttpStatCodeSetup;
8585 #ifdef UNITTESTS
8686 sigmatch_table[DETECT_AL_HTTP_STAT_CODE].RegisterTests = DetectHttpStatCodeRegisterTests;
9191 /* http.stat_code content modifier */
9292 sigmatch_table[DETECT_HTTP_STAT_CODE].name = "http.stat_code";
9393 sigmatch_table[DETECT_HTTP_STAT_CODE].desc = "sticky buffer to match only on HTTP stat-code-buffer";
94 sigmatch_table[DETECT_HTTP_STAT_CODE].url = DOC_URL DOC_VERSION "/rules/http-keywords.html#http-stat-code";
94 sigmatch_table[DETECT_HTTP_STAT_CODE].url = "/rules/http-keywords.html#http-stat-code";
9595 sigmatch_table[DETECT_HTTP_STAT_CODE].Setup = DetectHttpStatCodeSetupSticky;
9696 sigmatch_table[DETECT_HTTP_STAT_CODE].flags |= SIGMATCH_NOOPT|SIGMATCH_INFO_STICKY_BUFFER;
9797
8080 /* http_stat_msg content modifier */
8181 sigmatch_table[DETECT_AL_HTTP_STAT_MSG].name = "http_stat_msg";
8282 sigmatch_table[DETECT_AL_HTTP_STAT_MSG].desc = "content modifier to match on HTTP stat-msg-buffer";
83 sigmatch_table[DETECT_AL_HTTP_STAT_MSG].url = DOC_URL DOC_VERSION "/rules/http-keywords.html#http-stat-msg";
83 sigmatch_table[DETECT_AL_HTTP_STAT_MSG].url = "/rules/http-keywords.html#http-stat-msg";
8484 sigmatch_table[DETECT_AL_HTTP_STAT_MSG].Setup = DetectHttpStatMsgSetup;
8585 #ifdef UNITTESTS
8686 sigmatch_table[DETECT_AL_HTTP_STAT_MSG].RegisterTests = DetectHttpStatMsgRegisterTests;
9191 /* http.stat_msg sticky buffer */
9292 sigmatch_table[DETECT_HTTP_STAT_MSG].name = "http.stat_msg";
9393 sigmatch_table[DETECT_HTTP_STAT_MSG].desc = "sticky buffer to match on the HTTP response status message";
94 sigmatch_table[DETECT_HTTP_STAT_MSG].url = DOC_URL DOC_VERSION "/rules/http-keywords.html#http-stat-msg";
94 sigmatch_table[DETECT_HTTP_STAT_MSG].url = "/rules/http-keywords.html#http-stat-msg";
9595 sigmatch_table[DETECT_HTTP_STAT_MSG].Setup = DetectHttpStatMsgSetupSticky;
9696 sigmatch_table[DETECT_HTTP_STAT_MSG].flags |= SIGMATCH_NOOPT|SIGMATCH_INFO_STICKY_BUFFER;
9797
7777 /* http_user_agent content modifier */
7878 sigmatch_table[DETECT_AL_HTTP_USER_AGENT].name = "http_user_agent";
7979 sigmatch_table[DETECT_AL_HTTP_USER_AGENT].desc = "content modifier to match only on the HTTP User-Agent header";
80 sigmatch_table[DETECT_AL_HTTP_USER_AGENT].url = DOC_URL DOC_VERSION "/rules/http-keywords.html#http-user-agent";
80 sigmatch_table[DETECT_AL_HTTP_USER_AGENT].url = "/rules/http-keywords.html#http-user-agent";
8181 sigmatch_table[DETECT_AL_HTTP_USER_AGENT].Setup = DetectHttpUASetup;
8282 #ifdef UNITTESTS
8383 sigmatch_table[DETECT_AL_HTTP_USER_AGENT].RegisterTests = DetectHttpUARegisterTests;
8989 /* http.user_agent sticky buffer */
9090 sigmatch_table[DETECT_HTTP_UA].name = "http.user_agent";
9191 sigmatch_table[DETECT_HTTP_UA].desc = "sticky buffer to match specifically and only on the HTTP User Agent buffer";
92 sigmatch_table[DETECT_HTTP_UA].url = DOC_URL DOC_VERSION "/rules/http-keywords.html#http-user-agent";
92 sigmatch_table[DETECT_HTTP_UA].url = "/rules/http-keywords.html#http-user-agent";
9393 sigmatch_table[DETECT_HTTP_UA].Setup = DetectHttpUserAgentSetup;
9494 sigmatch_table[DETECT_HTTP_UA].flags |= SIGMATCH_NOOPT;
9595 sigmatch_table[DETECT_HTTP_UA].flags |= SIGMATCH_INFO_STICKY_BUFFER;
8989 /* http_uri content modifier */
9090 sigmatch_table[DETECT_AL_HTTP_URI].name = "http_uri";
9191 sigmatch_table[DETECT_AL_HTTP_URI].desc = "content modifier to match specifically and only on the HTTP uri-buffer";
92 sigmatch_table[DETECT_AL_HTTP_URI].url = DOC_URL DOC_VERSION "/rules/http-keywords.html#http-uri-and-http-raw-uri";
92 sigmatch_table[DETECT_AL_HTTP_URI].url = "/rules/http-keywords.html#http-uri-and-http-raw-uri";
9393 sigmatch_table[DETECT_AL_HTTP_URI].Setup = DetectHttpUriSetup;
9494 #ifdef UNITTESTS
9595 sigmatch_table[DETECT_AL_HTTP_URI].RegisterTests = DetectHttpUriRegisterTests;
101101 sigmatch_table[DETECT_HTTP_URI].name = "http.uri";
102102 sigmatch_table[DETECT_HTTP_URI].alias = "http.uri.normalized";
103103 sigmatch_table[DETECT_HTTP_URI].desc = "sticky buffer to match specifically and only on the normalized HTTP URI buffer";
104 sigmatch_table[DETECT_HTTP_URI].url = DOC_URL DOC_VERSION "/rules/http-keywords.html#http-uri-and-http-raw-uri";
104 sigmatch_table[DETECT_HTTP_URI].url = "/rules/http-keywords.html#http-uri-and-http-raw-uri";
105105 sigmatch_table[DETECT_HTTP_URI].Setup = DetectHttpUriSetupSticky;
106106 sigmatch_table[DETECT_HTTP_URI].flags |= SIGMATCH_NOOPT|SIGMATCH_INFO_STICKY_BUFFER;
107107
127127 /* http_raw_uri content modifier */
128128 sigmatch_table[DETECT_AL_HTTP_RAW_URI].name = "http_raw_uri";
129129 sigmatch_table[DETECT_AL_HTTP_RAW_URI].desc = "content modifier to match on the raw HTTP uri";
130 sigmatch_table[DETECT_AL_HTTP_RAW_URI].url = DOC_URL DOC_VERSION "/rules/http-keywords.html#http_uri-and-http_raw-uri";
130 sigmatch_table[DETECT_AL_HTTP_RAW_URI].url = "/rules/http-keywords.html#http_uri-and-http_raw-uri";
131131 sigmatch_table[DETECT_AL_HTTP_RAW_URI].Setup = DetectHttpRawUriSetup;
132132 sigmatch_table[DETECT_AL_HTTP_RAW_URI].flags |= SIGMATCH_NOOPT|SIGMATCH_INFO_CONTENT_MODIFIER;
133133 sigmatch_table[DETECT_AL_HTTP_RAW_URI].alternative = DETECT_HTTP_URI_RAW;
135135 /* http.uri.raw sticky buffer */
136136 sigmatch_table[DETECT_HTTP_URI_RAW].name = "http.uri.raw";
137137 sigmatch_table[DETECT_HTTP_URI_RAW].desc = "sticky buffer to match specifically and only on the raw HTTP URI buffer";
138 sigmatch_table[DETECT_HTTP_URI_RAW].url = DOC_URL DOC_VERSION "/rules/http-keywords.html#http-uri-and-http-raw-uri";
138 sigmatch_table[DETECT_HTTP_URI_RAW].url = "/rules/http-keywords.html#http-uri-and-http-raw-uri";
139139 sigmatch_table[DETECT_HTTP_URI_RAW].Setup = DetectHttpRawUriSetupSticky;
140140 sigmatch_table[DETECT_HTTP_URI_RAW].flags |= SIGMATCH_NOOPT|SIGMATCH_INFO_STICKY_BUFFER;
141141
5757 {
5858 sigmatch_table[DETECT_ICMP_ID].name = "icmp_id";
5959 sigmatch_table[DETECT_ICMP_ID].desc = "check for a ICMP ID";
60 sigmatch_table[DETECT_ICMP_ID].url = DOC_URL DOC_VERSION "/rules/header-keywords.html#icmp-id";
60 sigmatch_table[DETECT_ICMP_ID].url = "/rules/header-keywords.html#icmp-id";
6161 sigmatch_table[DETECT_ICMP_ID].Match = DetectIcmpIdMatch;
6262 sigmatch_table[DETECT_ICMP_ID].Setup = DetectIcmpIdSetup;
6363 sigmatch_table[DETECT_ICMP_ID].Free = DetectIcmpIdFree;
5757 {
5858 sigmatch_table[DETECT_ICMP_SEQ].name = "icmp_seq";
5959 sigmatch_table[DETECT_ICMP_SEQ].desc = "check for a ICMP sequence number";
60 sigmatch_table[DETECT_ICMP_SEQ].url = DOC_URL DOC_VERSION "/rules/header-keywords.html#icmp-seq";
60 sigmatch_table[DETECT_ICMP_SEQ].url = "/rules/header-keywords.html#icmp-seq";
6161 sigmatch_table[DETECT_ICMP_SEQ].Match = DetectIcmpSeqMatch;
6262 sigmatch_table[DETECT_ICMP_SEQ].Setup = DetectIcmpSeqSetup;
6363 sigmatch_table[DETECT_ICMP_SEQ].Free = DetectIcmpSeqFree;
6161 {
6262 sigmatch_table[DETECT_ICODE].name = "icode";
6363 sigmatch_table[DETECT_ICODE].desc = "match on specific ICMP id-value";
64 sigmatch_table[DETECT_ICODE].url = DOC_URL DOC_VERSION "/rules/header-keywords.html#icode";
64 sigmatch_table[DETECT_ICODE].url = "/rules/header-keywords.html#icode";
6565 sigmatch_table[DETECT_ICODE].Match = DetectICodeMatch;
6666 sigmatch_table[DETECT_ICODE].Setup = DetectICodeSetup;
6767 sigmatch_table[DETECT_ICODE].Free = DetectICodeFree;
6464 {
6565 sigmatch_table[DETECT_ID].name = "id";
6666 sigmatch_table[DETECT_ID].desc = "match on a specific IP ID value";
67 sigmatch_table[DETECT_ID].url = DOC_URL DOC_VERSION "/rules/header-keywords.html#id";
67 sigmatch_table[DETECT_ID].url = "/rules/header-keywords.html#id";
6868 sigmatch_table[DETECT_ID].Match = DetectIdMatch;
6969 sigmatch_table[DETECT_ID].Setup = DetectIdSetup;
7070 sigmatch_table[DETECT_ID].Free = DetectIdFree;
5555 {
5656 sigmatch_table[DETECT_IPOPTS].name = "ipopts";
5757 sigmatch_table[DETECT_IPOPTS].desc = "check if a specific IP option is set";
58 sigmatch_table[DETECT_IPOPTS].url = DOC_URL DOC_VERSION "/rules/header-keywords.html#ipopts";
58 sigmatch_table[DETECT_IPOPTS].url = "/rules/header-keywords.html#ipopts";
5959 sigmatch_table[DETECT_IPOPTS].Match = DetectIpOptsMatch;
6060 sigmatch_table[DETECT_IPOPTS].Setup = DetectIpOptsSetup;
6161 sigmatch_table[DETECT_IPOPTS].Free = DetectIpOptsFree;
5858 {
5959 sigmatch_table[DETECT_IPPROTO].name = "ip_proto";
6060 sigmatch_table[DETECT_IPPROTO].desc = "match on the IP protocol in the packet-header";
61 sigmatch_table[DETECT_IPPROTO].url = DOC_URL DOC_VERSION "/rules/header-keywords.html#ip-proto";
61 sigmatch_table[DETECT_IPPROTO].url = "/rules/header-keywords.html#ip-proto";
6262 sigmatch_table[DETECT_IPPROTO].Match = NULL;
6363 sigmatch_table[DETECT_IPPROTO].Setup = DetectIPProtoSetup;
6464 sigmatch_table[DETECT_IPPROTO].Free = DetectIPProtoFree;
6161 {
6262 sigmatch_table[DETECT_IPREP].name = "iprep";
6363 sigmatch_table[DETECT_IPREP].desc = "match on the IP reputation information for a host";
64 sigmatch_table[DETECT_IPREP].url = DOC_URL DOC_VERSION "/rules/ip-reputation-rules.html#iprep";
64 sigmatch_table[DETECT_IPREP].url = "/rules/ip-reputation-rules.html#iprep";
6565 sigmatch_table[DETECT_IPREP].Match = DetectIPRepMatch;
6666 sigmatch_table[DETECT_IPREP].Setup = DetectIPRepSetup;
6767 sigmatch_table[DETECT_IPREP].Free = DetectIPRepFree;
5050 {
5151 sigmatch_table[DETECT_IPV4HDR].name = "ipv4.hdr";
5252 sigmatch_table[DETECT_IPV4HDR].desc = "sticky buffer to match on the IPV4 header";
53 sigmatch_table[DETECT_IPV4HDR].url = DOC_URL DOC_VERSION "/rules/header-keywords.html#ipv4hdr";
53 sigmatch_table[DETECT_IPV4HDR].url = "/rules/header-keywords.html#ipv4hdr";
5454 sigmatch_table[DETECT_IPV4HDR].Setup = DetectIpv4hdrSetup;
5555 sigmatch_table[DETECT_IPV4HDR].flags |= SIGMATCH_NOOPT | SIGMATCH_INFO_STICKY_BUFFER;
5656 #ifdef UNITTESTS
4949 void DetectIpv6hdrRegister(void)
5050 {
5151 sigmatch_table[DETECT_IPV6HDR].name = "ipv6.hdr";
52 sigmatch_table[DETECT_IPV6HDR].desc = "sticky buffer to match on the IPV4 header";
53 sigmatch_table[DETECT_IPV6HDR].url = DOC_URL DOC_VERSION "/rules/header-keywords.html#ipv6hdr";
52 sigmatch_table[DETECT_IPV6HDR].desc = "sticky buffer to match on the IPV6 header";
53 sigmatch_table[DETECT_IPV6HDR].url = "/rules/header-keywords.html#ipv6hdr";
5454 sigmatch_table[DETECT_IPV6HDR].Setup = DetectIpv6hdrSetup;
5555 sigmatch_table[DETECT_IPV6HDR].flags |= SIGMATCH_NOOPT | SIGMATCH_INFO_STICKY_BUFFER;
5656 #ifdef UNITTESTS
6767 {
6868 sigmatch_table[DETECT_ISDATAAT].name = "isdataat";
6969 sigmatch_table[DETECT_ISDATAAT].desc = "check if there is still data at a specific part of the payload";
70 sigmatch_table[DETECT_ISDATAAT].url = DOC_URL DOC_VERSION "/rules/payload-keywords.html#isdataat";
70 sigmatch_table[DETECT_ISDATAAT].url = "/rules/payload-keywords.html#isdataat";
7171 /* match is handled in DetectEngineContentInspection() */
7272 sigmatch_table[DETECT_ISDATAAT].Match = NULL;
7373 sigmatch_table[DETECT_ISDATAAT].Setup = DetectIsdataatSetup;
7676
7777 sigmatch_table[DETECT_ENDS_WITH].name = "endswith";
7878 sigmatch_table[DETECT_ENDS_WITH].desc = "make sure the previous content matches exactly at the end of the buffer";
79 sigmatch_table[DETECT_ENDS_WITH].url = DOC_URL DOC_VERSION "/rules/payload-keywords.html#endswith";
79 sigmatch_table[DETECT_ENDS_WITH].url = "/rules/payload-keywords.html#endswith";
8080 sigmatch_table[DETECT_ENDS_WITH].Setup = DetectEndsWithSetup;
8181 sigmatch_table[DETECT_ENDS_WITH].flags = SIGMATCH_NOOPT;
8282
6161 {
6262 sigmatch_table[DETECT_ITYPE].name = "itype";
6363 sigmatch_table[DETECT_ITYPE].desc = "match on a specific ICMP type";
64 sigmatch_table[DETECT_ITYPE].url = DOC_URL DOC_VERSION "/rules/header-keywords.html#itype";
64 sigmatch_table[DETECT_ITYPE].url = "/rules/header-keywords.html#itype";
6565 sigmatch_table[DETECT_ITYPE].Match = DetectITypeMatch;
6666 sigmatch_table[DETECT_ITYPE].Setup = DetectITypeSetup;
6767 sigmatch_table[DETECT_ITYPE].Free = DetectITypeFree;
193193 {
194194 sigmatch_table[DETECT_AL_KRB5_CNAME].name = "krb5.cname";
195195 sigmatch_table[DETECT_AL_KRB5_CNAME].alias = "krb5_cname";
196 sigmatch_table[DETECT_AL_KRB5_CNAME].url = DOC_URL DOC_VERSION "/rules/kerberos-keywords.html#krb5-cname";
196 sigmatch_table[DETECT_AL_KRB5_CNAME].url = "/rules/kerberos-keywords.html#krb5-cname";
197197 sigmatch_table[DETECT_AL_KRB5_CNAME].Setup = DetectKrb5CNameSetup;
198198 sigmatch_table[DETECT_AL_KRB5_CNAME].flags |= SIGMATCH_NOOPT|SIGMATCH_INFO_STICKY_BUFFER;
199199 sigmatch_table[DETECT_AL_KRB5_CNAME].desc = "sticky buffer to match on Kerberos 5 client name";
6262 void DetectKrb5ErrCodeRegister(void) {
6363 sigmatch_table[DETECT_AL_KRB5_ERRCODE].name = "krb5_err_code";
6464 sigmatch_table[DETECT_AL_KRB5_ERRCODE].desc = "match Kerberos 5 error code";
65 sigmatch_table[DETECT_AL_KRB5_ERRCODE].url = DOC_URL DOC_VERSION "/rules/kerberos-keywords.html#krb5-err-code";
65 sigmatch_table[DETECT_AL_KRB5_ERRCODE].url = "/rules/kerberos-keywords.html#krb5-err-code";
6666 sigmatch_table[DETECT_AL_KRB5_ERRCODE].Match = NULL;
6767 sigmatch_table[DETECT_AL_KRB5_ERRCODE].AppLayerTxMatch = DetectKrb5ErrCodeMatch;
6868 sigmatch_table[DETECT_AL_KRB5_ERRCODE].Setup = DetectKrb5ErrCodeSetup;
6262 void DetectKrb5MsgTypeRegister(void) {
6363 sigmatch_table[DETECT_AL_KRB5_MSGTYPE].name = "krb5_msg_type";
6464 sigmatch_table[DETECT_AL_KRB5_MSGTYPE].desc = "match Kerberos 5 message type";
65 sigmatch_table[DETECT_AL_KRB5_MSGTYPE].url = DOC_URL DOC_VERSION "/rules/kerberos-keywords.html#krb5-msg-type";
65 sigmatch_table[DETECT_AL_KRB5_MSGTYPE].url = "/rules/kerberos-keywords.html#krb5-msg-type";
6666 sigmatch_table[DETECT_AL_KRB5_MSGTYPE].Match = NULL;
6767 sigmatch_table[DETECT_AL_KRB5_MSGTYPE].AppLayerTxMatch = DetectKrb5MsgTypeMatch;
6868 sigmatch_table[DETECT_AL_KRB5_MSGTYPE].Setup = DetectKrb5MsgTypeSetup;
193193 {
194194 sigmatch_table[DETECT_AL_KRB5_SNAME].name = "krb5.sname";
195195 sigmatch_table[DETECT_AL_KRB5_SNAME].alias = "krb5_sname";
196 sigmatch_table[DETECT_AL_KRB5_SNAME].url = DOC_URL DOC_VERSION "/rules/kerberos-keywords.html#krb5-sname";
196 sigmatch_table[DETECT_AL_KRB5_SNAME].url = "/rules/kerberos-keywords.html#krb5-sname";
197197 sigmatch_table[DETECT_AL_KRB5_SNAME].Setup = DetectKrb5SNameSetup;
198198 sigmatch_table[DETECT_AL_KRB5_SNAME].flags |= SIGMATCH_NOOPT|SIGMATCH_INFO_STICKY_BUFFER;
199199 sigmatch_table[DETECT_AL_KRB5_SNAME].desc = "sticky buffer to match on Kerberos 5 server name";
7575 sigmatch_table[DETECT_LUA].name = "lua";
7676 sigmatch_table[DETECT_LUA].alias = "luajit";
7777 sigmatch_table[DETECT_LUA].desc = "support for lua scripting";
78 sigmatch_table[DETECT_LUA].url = DOC_URL DOC_VERSION "/rules/rule-lua-scripting.html";
78 sigmatch_table[DETECT_LUA].url = "/rules/rule-lua-scripting.html";
7979 sigmatch_table[DETECT_LUA].Setup = DetectLuaSetupNoSupport;
8080 sigmatch_table[DETECT_LUA].Free = NULL;
8181 sigmatch_table[DETECT_LUA].RegisterTests = NULL;
114114 sigmatch_table[DETECT_LUA].name = "lua";
115115 sigmatch_table[DETECT_LUA].alias = "luajit";
116116 sigmatch_table[DETECT_LUA].desc = "match via a lua script";
117 sigmatch_table[DETECT_LUA].url = DOC_URL DOC_VERSION "/rules/rule-lua-scripting.html";
117 sigmatch_table[DETECT_LUA].url = "/rules/rule-lua-scripting.html";
118118 sigmatch_table[DETECT_LUA].Match = DetectLuaMatch;
119119 sigmatch_table[DETECT_LUA].AppLayerTxMatch = DetectLuaAppTxMatch;
120120 sigmatch_table[DETECT_LUA].Setup = DetectLuaSetup;
686686 goto error;
687687 }
688688
689 lua->de_ctx = de_ctx;
689690 return lua;
690691
691692 error:
11171118 SCFree(lua->buffername);
11181119 if (lua->filename)
11191120 SCFree(lua->filename);
1121
1122 if (lua->de_ctx) {
1123 DetectUnregisterThreadCtxFuncs((DetectEngineCtx *)lua->de_ctx, NULL, lua, "lua");
1124 }
11201125
11211126 SCFree(lua);
11221127 }
4848 uint32_t sid;
4949 uint32_t rev;
5050 uint32_t gid;
51
52 const DetectEngineCtx *de_ctx;
5153 } DetectLuaData;
5254
5355 #endif /* HAVE_LUA */
4040 {
4141 sigmatch_table[DETECT_METADATA].name = "metadata";
4242 sigmatch_table[DETECT_METADATA].desc = "used for logging";
43 sigmatch_table[DETECT_METADATA].url = DOC_URL DOC_VERSION "/rules/meta.html#metadata";
43 sigmatch_table[DETECT_METADATA].url = "/rules/meta.html#metadata";
4444 sigmatch_table[DETECT_METADATA].Match = NULL;
4545 sigmatch_table[DETECT_METADATA].Setup = DetectMetadataSetup;
4646 sigmatch_table[DETECT_METADATA].Free = NULL;
517517 SCEnter();
518518 sigmatch_table[DETECT_AL_MODBUS].name = "modbus";
519519 sigmatch_table[DETECT_AL_MODBUS].desc = "match on various properties of Modbus requests";
520 sigmatch_table[DETECT_AL_MODBUS].url = DOC_URL DOC_VERSION "/rules/modbus-keyword.html#modbus-keyword";
520 sigmatch_table[DETECT_AL_MODBUS].url = "/rules/modbus-keyword.html#modbus-keyword";
521521 sigmatch_table[DETECT_AL_MODBUS].Match = NULL;
522522 sigmatch_table[DETECT_AL_MODBUS].Setup = DetectModbusSetup;
523523 sigmatch_table[DETECT_AL_MODBUS].Free = DetectModbusFree;
4040 {
4141 sigmatch_table[DETECT_MSG].name = "msg";
4242 sigmatch_table[DETECT_MSG].desc = "information about the rule and the possible alert";
43 sigmatch_table[DETECT_MSG].url = DOC_URL DOC_VERSION "/rules/meta.html#msg-message";
43 sigmatch_table[DETECT_MSG].url = "/rules/meta.html#msg-message";
4444 sigmatch_table[DETECT_MSG].Match = NULL;
4545 sigmatch_table[DETECT_MSG].Setup = DetectMsgSetup;
4646 sigmatch_table[DETECT_MSG].Free = NULL;
9191 {
9292 sigmatch_table[DETECT_AL_NFS_PROCEDURE].name = "nfs_procedure";
9393 sigmatch_table[DETECT_AL_NFS_PROCEDURE].desc = "match NFS procedure";
94 sigmatch_table[DETECT_AL_NFS_PROCEDURE].url = DOC_URL DOC_VERSION "/rules/nfs-keywords.html#procedure";
94 sigmatch_table[DETECT_AL_NFS_PROCEDURE].url = "/rules/nfs-keywords.html#procedure";
9595 sigmatch_table[DETECT_AL_NFS_PROCEDURE].Match = NULL;
9696 sigmatch_table[DETECT_AL_NFS_PROCEDURE].AppLayerTxMatch = DetectNfsProcedureMatch;
9797 sigmatch_table[DETECT_AL_NFS_PROCEDURE].Setup = DetectNfsProcedureSetup;
9292 sigmatch_table[DETECT_AL_NFS_VERSION].name = "nfs.version";
9393 sigmatch_table[DETECT_AL_NFS_VERSION].alias = "nfs_version";
9494 sigmatch_table[DETECT_AL_NFS_VERSION].desc = "match NFS version";
95 sigmatch_table[DETECT_AL_NFS_VERSION].url = DOC_URL DOC_VERSION "/rules/nfs-keywords.html#version";
95 sigmatch_table[DETECT_AL_NFS_VERSION].url = "/rules/nfs-keywords.html#version";
9696 sigmatch_table[DETECT_AL_NFS_VERSION].AppLayerTxMatch = DetectNfsVersionMatch;
9797 sigmatch_table[DETECT_AL_NFS_VERSION].Setup = DetectNfsVersionSetup;
9898 sigmatch_table[DETECT_AL_NFS_VERSION].Free = DetectNfsVersionFree;
3333 {
3434 sigmatch_table[DETECT_NOALERT].name = "noalert";
3535 sigmatch_table[DETECT_NOALERT].desc = "no alert will be generated by the rule";
36 sigmatch_table[DETECT_NOALERT].url = DOC_URL DOC_VERSION "/rules/flow-keywords.html";
36 sigmatch_table[DETECT_NOALERT].url = "/rules/flow-keywords.html";
3737 sigmatch_table[DETECT_NOALERT].Match = NULL;
3838 sigmatch_table[DETECT_NOALERT].Setup = DetectNoalertSetup;
3939 sigmatch_table[DETECT_NOALERT].Free = NULL;
3838 {
3939 sigmatch_table[DETECT_NOCASE].name = "nocase";
4040 sigmatch_table[DETECT_NOCASE].desc = "modify content match to be case insensitive";
41 sigmatch_table[DETECT_NOCASE].url = DOC_URL DOC_VERSION "/rules/payload-keywords.html#nocase";
41 sigmatch_table[DETECT_NOCASE].url = "/rules/payload-keywords.html#nocase";
4242 sigmatch_table[DETECT_NOCASE].Match = NULL;
4343 sigmatch_table[DETECT_NOCASE].Setup = DetectNocaseSetup;
4444 sigmatch_table[DETECT_NOCASE].Free = NULL;
4545 {
4646 sigmatch_table[DETECT_OFFSET].name = "offset";
4747 sigmatch_table[DETECT_OFFSET].desc = "designate from which byte in the payload will be checked to find a match";
48 sigmatch_table[DETECT_OFFSET].url = DOC_URL DOC_VERSION "/rules/payload-keywords.html#offset";
48 sigmatch_table[DETECT_OFFSET].url = "/rules/payload-keywords.html#offset";
4949 sigmatch_table[DETECT_OFFSET].Match = NULL;
5050 sigmatch_table[DETECT_OFFSET].Setup = DetectOffsetSetup;
5151 sigmatch_table[DETECT_OFFSET].Free = NULL;
693693
694694 /* Call option parsing */
695695 st = SigTableGet(optname);
696 if (st == NULL) {
696 if (st == NULL || st->Setup == NULL) {
697697 SCLogError(SC_ERR_RULE_KEYWORD_UNKNOWN, "unknown rule keyword '%s'.", optname);
698698 goto error;
699699 }
12741274
12751275 sig->init_data->smlists_tail = SCCalloc(sig->init_data->smlists_array_size, sizeof(SigMatch *));
12761276 if (sig->init_data->smlists_tail == NULL) {
1277 SCFree(sig->init_data->smlists_tail);
1277 SCFree(sig->init_data->smlists);
12781278 SCFree(sig->init_data);
12791279 SCFree(sig);
12801280 return NULL;
23382338 return (dup_sig == 0 || dup_sig == 2) ? sig : NULL;
23392339
23402340 error:
2341 if (sig != NULL)
2341 /* free the 2nd sig bidir may have set up */
2342 if (sig != NULL && sig->next != NULL) {
2343 SigFree(sig->next);
2344 sig->next = NULL;
2345 }
2346 if (sig != NULL) {
23422347 SigFree(sig);
2348 }
23432349 return NULL;
23442350 }
23452351
8686 {
8787 sigmatch_table[DETECT_PCRE].name = "pcre";
8888 sigmatch_table[DETECT_PCRE].desc = "match on regular expression";
89 sigmatch_table[DETECT_PCRE].url = DOC_URL DOC_VERSION "/rules/payload-keywords.html#pcre-perl-compatible-regular-expressions";
89 sigmatch_table[DETECT_PCRE].url = "/rules/payload-keywords.html#pcre-perl-compatible-regular-expressions";
9090 sigmatch_table[DETECT_PCRE].Match = NULL;
9191 sigmatch_table[DETECT_PCRE].Setup = DetectPcreSetup;
9292 sigmatch_table[DETECT_PCRE].Free = DetectPcreFree;
0 /* Copyright (C) 2012 Open Information Security Foundation
0 /* Copyright (C) 2012-2020 Open Information Security Foundation
11 *
22 * You can copy, redistribute or modify this Program under the terms of
33 * the GNU General Public License version 2 as published by the Free
5151 void DetectPktDataRegister(void)
5252 {
5353 sigmatch_table[DETECT_PKT_DATA].name = "pkt_data";
54 sigmatch_table[DETECT_PKT_DATA].Match = NULL;
5554 sigmatch_table[DETECT_PKT_DATA].Setup = DetectPktDataSetup;
56 sigmatch_table[DETECT_PKT_DATA].Free = NULL;
5755 sigmatch_table[DETECT_PKT_DATA].RegisterTests = DetectPktDataTestRegister;
5856 sigmatch_table[DETECT_PKT_DATA].flags = SIGMATCH_NOOPT;
5957 }
6361 * \brief into the current signature
6462 *
6563 * \param de_ctx pointer to the Detection Engine Context
66 * \param s pointer to the Current Signature
67 * \param str pointer to the user provided "filestore" option
64 * \param s pointer to the current signature
65 * \param unused unused for keyword with SIGMATCH_NOOPT set
6866 *
6967 * \retval 0 on Success
7068 * \retval -1 on Failure
7169 */
72 static int DetectPktDataSetup (DetectEngineCtx *de_ctx, Signature *s, const char *str)
70 static int DetectPktDataSetup (DetectEngineCtx *de_ctx, Signature *s, const char *unused)
7371 {
7472 SCEnter();
73 if (s->init_data->transform_cnt) {
74 SCLogError(SC_ERR_INVALID_SIGNATURE,
75 "previous transforms not consumed before 'pkt_data'");
76 SCReturnInt(-1);
77 }
7578 s->init_data->list = DETECT_SM_LIST_NOTSET;
76
77 return 0;
79 SCReturnInt(0);
7880 }
7981
8082 #ifdef UNITTESTS
8486
8587 static int DetectPktDataTest01(void)
8688 {
87 DetectEngineCtx *de_ctx = NULL;
88 int result = 0;
89 SigMatch *sm = NULL;
90
91 de_ctx = DetectEngineCtxInit();
92 if (de_ctx == NULL)
93 goto end;
94
89 DetectEngineCtx *de_ctx = DetectEngineCtxInit();
90 FAIL_IF_NULL(de_ctx);
9591 de_ctx->flags |= DE_QUIET;
9692
97 Signature *sig = SigInit(de_ctx, "alert tcp any any -> any any "
93 Signature *sig = DetectEngineAppendSig(de_ctx, "alert tcp any any -> any any "
9894 "(file_data; content:\"in file data\";"
99 " pkt_data; content:\"in pkt data\";)");
100 de_ctx->sig_list = sig;
101 if (de_ctx->sig_list == NULL) {
102 SCLogError(SC_ERR_INVALID_SIGNATURE,"could not load test signature");
103 goto end;
104 }
95 " pkt_data; content:\"in pkt data\"; sid:1;)");
96 FAIL_IF_NULL(sig);
10597
106 /* sm should be in the MATCH list */
107 sm = de_ctx->sig_list->sm_lists[g_file_data_buffer_id];
108 if (sm == NULL) {
109 printf("sm not in g_file_data_buffer_id: ");
110 goto end;
111 }
98 SigMatch *sm = de_ctx->sig_list->sm_lists[g_file_data_buffer_id];
99 FAIL_IF_NULL(sm);
112100
113101 sm = de_ctx->sig_list->sm_lists[DETECT_SM_LIST_PMATCH];
114 if (sm == NULL) {
115 printf("sm not in DETECT_SM_LIST_PMATCH: ");
116 goto end;
117 }
102 FAIL_IF_NULL(sm);
118103
119 if (sm->type != DETECT_CONTENT) {
120 printf("sm type not DETECT_AL_HTTP_SERVER_BODY: ");
121 goto end;
122 }
104 FAIL_IF_NOT(sm->type == DETECT_CONTENT);
105 FAIL_IF_NOT_NULL(sm->next);
123106
124 if (sm->next != NULL) {
125 goto end;
126 }
107 FAIL_IF_NOT(sig->init_data->list == DETECT_SM_LIST_NOTSET);
108 DetectEngineCtxFree(de_ctx);
109 PASS;
110 }
127111
128
129 if (sig->init_data->list != DETECT_SM_LIST_NOTSET) {
130 printf("sticky buffer set: ");
131 goto end;
132 }
133
134 result = 1;
135 end:
136 SigGroupCleanup(de_ctx);
137 SigCleanSignatures(de_ctx);
138 DetectEngineCtxFree(de_ctx);
139
140 return result;
141 }
142112 #endif
143113
144114 static void DetectPktDataTestRegister(void)
4242 static int DetectPktvarMatch (DetectEngineThreadCtx *, Packet *,
4343 const Signature *, const SigMatchCtx *);
4444 static int DetectPktvarSetup (DetectEngineCtx *, Signature *, const char *);
45 static void DetectPktvarFree(void *data);
4546
4647 void DetectPktvarRegister (void)
4748 {
4849 sigmatch_table[DETECT_PKTVAR].name = "pktvar";
4950 sigmatch_table[DETECT_PKTVAR].Match = DetectPktvarMatch;
5051 sigmatch_table[DETECT_PKTVAR].Setup = DetectPktvarSetup;
51 sigmatch_table[DETECT_PKTVAR].Free = NULL;
52 sigmatch_table[DETECT_PKTVAR].Free = DetectPktvarFree;
5253 sigmatch_table[DETECT_PKTVAR].RegisterTests = NULL;
5354
5455 DetectSetupParseRegexes(PARSE_REGEX, &parse_regex, &parse_regex_study);
7677 return ret;
7778 }
7879
80 static void DetectPktvarFree(void *ptr)
81 {
82 DetectPktvarData *data = ptr;
83 if (data != NULL) {
84 SCFree(data->content);
85 SCFree(data);
86 }
87 }
88
7989 static int DetectPktvarSetup (DetectEngineCtx *de_ctx, Signature *s, const char *rawstr)
8090 {
8191 char *varname = NULL, *varcontent = NULL;
101111
102112 res = pcre_get_substring((char *)rawstr, ov, MAX_SUBSTRINGS, 2, &str_ptr);
103113 if (res < 0) {
114 pcre_free(varname);
104115 SCLogError(SC_ERR_PCRE_GET_SUBSTRING, "pcre_get_substring failed");
105116 return -1;
106117 }
124135 pcre_free(varcontent);
125136 return -1;
126137 }
138 pcre_free(varcontent);
127139
128140 DetectPktvarData *cd = SCCalloc(1, sizeof(DetectPktvarData));
129141 if (unlikely(cd == NULL)) {
130142 pcre_free(varname);
131 pcre_free(varcontent);
132143 SCFree(content);
133144 return -1;
134145 }
137148 cd->content_len = len;
138149 cd->id = VarNameStoreSetupAdd(varname, VAR_TYPE_PKT_VAR);
139150 pcre_free(varname);
140 pcre_free(varcontent);
141151
142152 /* Okay so far so good, lets get this into a SigMatch
143153 * and put it in the Signature. */
144154 SigMatch *sm = SigMatchAlloc();
145155 if (unlikely(sm == NULL)) {
146 SCFree(cd->content);
147 SCFree(cd);
156 DetectPktvarFree(cd);
148157 return -1;
149158 }
150159 sm->type = DETECT_PKTVAR;
153162 SigMatchAppendSMToList(s, sm, DETECT_SM_LIST_MATCH);
154163 return 0;
155164 }
156
157
3737 {
3838 sigmatch_table[DETECT_PREFILTER].name = "prefilter";
3939 sigmatch_table[DETECT_PREFILTER].desc = "force a condition to be used as prefilter";
40 sigmatch_table[DETECT_PREFILTER].url = DOC_URL DOC_VERSION "/rules/prefilter-keywords.html#prefilter";
40 sigmatch_table[DETECT_PREFILTER].url = "/rules/prefilter-keywords.html#prefilter";
4141 sigmatch_table[DETECT_PREFILTER].Match = NULL;
4242 sigmatch_table[DETECT_PREFILTER].Setup = DetectPrefilterSetup;
4343 sigmatch_table[DETECT_PREFILTER].Free = NULL;
4848 {
4949 sigmatch_table[DETECT_PRIORITY].name = "priority";
5050 sigmatch_table[DETECT_PRIORITY].desc = "rules with a higher priority will be examined first";
51 sigmatch_table[DETECT_PRIORITY].url = DOC_URL DOC_VERSION "/rules/meta.html#priority";
51 sigmatch_table[DETECT_PRIORITY].url = "/rules/meta.html#priority";
5252 sigmatch_table[DETECT_PRIORITY].Setup = DetectPrioritySetup;
5353 sigmatch_table[DETECT_PRIORITY].RegisterTests = SCPriorityRegisterTests;
5454
5959 {
6060 sigmatch_table[DETECT_REFERENCE].name = "reference";
6161 sigmatch_table[DETECT_REFERENCE].desc = "direct to places where information about the rule can be found";
62 sigmatch_table[DETECT_REFERENCE].url = DOC_URL DOC_VERSION "/rules/meta.html#reference";
62 sigmatch_table[DETECT_REFERENCE].url = "/rules/meta.html#reference";
6363 sigmatch_table[DETECT_REFERENCE].Setup = DetectReferenceSetup;
6464 #ifdef UNITTESTS
6565 sigmatch_table[DETECT_REFERENCE].RegisterTests = ReferenceRegisterTests;
6868 {
6969 sigmatch_table[DETECT_REPLACE].name = "replace";
7070 sigmatch_table[DETECT_REPLACE].desc = "only to be used in IPS-mode. Change the following content into another";
71 sigmatch_table[DETECT_REPLACE].url = DOC_URL DOC_VERSION "/rules/payload-keywords.html#replace";
71 sigmatch_table[DETECT_REPLACE].url = "/rules/payload-keywords.html#replace";
7272 sigmatch_table[DETECT_REPLACE].Match = DetectReplacePostMatch;
7373 sigmatch_table[DETECT_REPLACE].Setup = DetectReplaceSetup;
7474 sigmatch_table[DETECT_REPLACE].Free = NULL;
3434 {
3535 sigmatch_table[DETECT_REV].name = "rev";
3636 sigmatch_table[DETECT_REV].desc = "set version of the rule";
37 sigmatch_table[DETECT_REV].url = DOC_URL DOC_VERSION "/rules/meta.html#rev-revision";
37 sigmatch_table[DETECT_REV].url = "/rules/meta.html#rev-revision";
3838 sigmatch_table[DETECT_REV].Match = NULL;
3939 sigmatch_table[DETECT_REV].Setup = DetectRevSetup;
4040 sigmatch_table[DETECT_REV].Free = NULL;
6060 {
6161 sigmatch_table[DETECT_RPC].name = "rpc";
6262 sigmatch_table[DETECT_RPC].desc = "match RPC procedure numbers and RPC version";
63 sigmatch_table[DETECT_RPC].url = DOC_URL DOC_VERSION "/rules/payload-keywords.html#rpc";
63 sigmatch_table[DETECT_RPC].url = "/rules/payload-keywords.html#rpc";
6464 sigmatch_table[DETECT_RPC].Match = DetectRpcMatch;
6565 sigmatch_table[DETECT_RPC].Setup = DetectRpcSetup;
6666 sigmatch_table[DETECT_RPC].Free = DetectRpcFree;
4949 {
5050 sigmatch_table[DETECT_SAMEIP].name = "sameip";
5151 sigmatch_table[DETECT_SAMEIP].desc = "check if the IP address of the source is the same as the IP address of the destination";
52 sigmatch_table[DETECT_SAMEIP].url = DOC_URL DOC_VERSION "/rules/header-keywords.html#sameip";
52 sigmatch_table[DETECT_SAMEIP].url = "/rules/header-keywords.html#sameip";
5353 sigmatch_table[DETECT_SAMEIP].Match = DetectSameipMatch;
5454 sigmatch_table[DETECT_SAMEIP].Setup = DetectSameipSetup;
5555 sigmatch_table[DETECT_SAMEIP].Free = NULL;
3838 {
3939 sigmatch_table[DETECT_SID].name = "sid";
4040 sigmatch_table[DETECT_SID].desc = "set rule ID";
41 sigmatch_table[DETECT_SID].url = DOC_URL DOC_VERSION "/rules/meta.html#sid-signature-id";
41 sigmatch_table[DETECT_SID].url = "/rules/meta.html#sid-signature-id";
4242 sigmatch_table[DETECT_SID].Match = NULL;
4343 sigmatch_table[DETECT_SID].Setup = DetectSidSetup;
4444 sigmatch_table[DETECT_SID].Free = NULL;
127127 /* sip.method sticky buffer */
128128 sigmatch_table[DETECT_AL_SIP_METHOD].name = KEYWORD_NAME;
129129 sigmatch_table[DETECT_AL_SIP_METHOD].desc = "sticky buffer to match on the SIP method buffer";
130 sigmatch_table[DETECT_AL_SIP_METHOD].url = DOC_URL DOC_VERSION "/rules/" KEYWORD_DOC;
130 sigmatch_table[DETECT_AL_SIP_METHOD].url = "/rules/" KEYWORD_DOC;
131131 sigmatch_table[DETECT_AL_SIP_METHOD].Setup = DetectSipMethodSetup;
132132 sigmatch_table[DETECT_AL_SIP_METHOD].flags |= SIGMATCH_NOOPT;
133133
9797 /* sip.protocol sticky buffer */
9898 sigmatch_table[DETECT_AL_SIP_PROTOCOL].name = KEYWORD_NAME;
9999 sigmatch_table[DETECT_AL_SIP_PROTOCOL].desc = "sticky buffer to match on the SIP protocol";
100 sigmatch_table[DETECT_AL_SIP_PROTOCOL].url = DOC_URL DOC_VERSION "/rules/" KEYWORD_DOC;
100 sigmatch_table[DETECT_AL_SIP_PROTOCOL].url = "/rules/" KEYWORD_DOC;
101101 sigmatch_table[DETECT_AL_SIP_PROTOCOL].Setup = DetectSipProtocolSetup;
102102 sigmatch_table[DETECT_AL_SIP_PROTOCOL].flags |= SIGMATCH_NOOPT;
103103
9797 /* sip.request_line sticky buffer */
9898 sigmatch_table[DETECT_AL_SIP_REQUEST_LINE].name = KEYWORD_NAME;
9999 sigmatch_table[DETECT_AL_SIP_REQUEST_LINE].desc = "sticky buffer to match on the SIP request line";
100 sigmatch_table[DETECT_AL_SIP_REQUEST_LINE].url = DOC_URL DOC_VERSION "/rules/" KEYWORD_DOC;
100 sigmatch_table[DETECT_AL_SIP_REQUEST_LINE].url = "/rules/" KEYWORD_DOC;
101101 sigmatch_table[DETECT_AL_SIP_REQUEST_LINE].Setup = DetectSipRequestLineSetup;
102102 sigmatch_table[DETECT_AL_SIP_REQUEST_LINE].flags |= SIGMATCH_NOOPT;
103103
9797 /* sip.response_line sticky buffer */
9898 sigmatch_table[DETECT_AL_SIP_RESPONSE_LINE].name = KEYWORD_NAME;
9999 sigmatch_table[DETECT_AL_SIP_RESPONSE_LINE].desc = "sticky buffer to match on the SIP response line";
100 sigmatch_table[DETECT_AL_SIP_RESPONSE_LINE].url = DOC_URL DOC_VERSION "/rules/" KEYWORD_DOC;
100 sigmatch_table[DETECT_AL_SIP_RESPONSE_LINE].url = "/rules/" KEYWORD_DOC;
101101 sigmatch_table[DETECT_AL_SIP_RESPONSE_LINE].Setup = DetectSipResponseLineSetup;
102102 sigmatch_table[DETECT_AL_SIP_RESPONSE_LINE].flags |= SIGMATCH_NOOPT;
103103
100100 /* sip.stat_code sticky buffer */
101101 sigmatch_table[DETECT_AL_SIP_STAT_CODE].name = KEYWORD_NAME;
102102 sigmatch_table[DETECT_AL_SIP_STAT_CODE].desc = "sticky buffer to match on the SIP status code";
103 sigmatch_table[DETECT_AL_SIP_STAT_CODE].url = DOC_URL DOC_VERSION "/rules/" KEYWORD_DOC;
103 sigmatch_table[DETECT_AL_SIP_STAT_CODE].url = "/rules/" KEYWORD_DOC;
104104 sigmatch_table[DETECT_AL_SIP_STAT_CODE].Setup = DetectSipStatCodeSetup;
105105 sigmatch_table[DETECT_AL_SIP_STAT_CODE].flags |= SIGMATCH_NOOPT;
106106
100100 /* sip.stat_msg sticky buffer */
101101 sigmatch_table[DETECT_AL_SIP_STAT_MSG].name = KEYWORD_NAME;
102102 sigmatch_table[DETECT_AL_SIP_STAT_MSG].desc = "sticky buffer to match on the SIP status message";
103 sigmatch_table[DETECT_AL_SIP_STAT_MSG].url = DOC_URL DOC_VERSION "/rules/" KEYWORD_DOC;
103 sigmatch_table[DETECT_AL_SIP_STAT_MSG].url = "/rules/" KEYWORD_DOC;
104104 sigmatch_table[DETECT_AL_SIP_STAT_MSG].Setup = DetectSipStatMsgSetup;
105105 sigmatch_table[DETECT_AL_SIP_STAT_MSG].flags |= SIGMATCH_NOOPT;
106106
109109 {
110110 sigmatch_table[DETECT_AL_SIP_URI].name = KEYWORD_NAME;
111111 sigmatch_table[DETECT_AL_SIP_URI].desc = "sticky buffer to match on the SIP URI";
112 sigmatch_table[DETECT_AL_SIP_URI].url = DOC_URL DOC_VERSION "/rules/" KEYWORD_DOC;
112 sigmatch_table[DETECT_AL_SIP_URI].url = "/rules/" KEYWORD_DOC;
113113 sigmatch_table[DETECT_AL_SIP_URI].Setup = DetectSipUriSetup;
114114 sigmatch_table[DETECT_AL_SIP_URI].flags |= SIGMATCH_NOOPT;
115115
5858 #ifdef UNITTESTS
5959 sigmatch_table[DETECT_AL_SNMP_COMMUNITY].RegisterTests = DetectSNMPCommunityRegisterTests;
6060 #endif
61 sigmatch_table[DETECT_AL_SNMP_COMMUNITY].url = DOC_URL DOC_VERSION "/rules/snmp-keywords.html#snmp-community";
61 sigmatch_table[DETECT_AL_SNMP_COMMUNITY].url = "/rules/snmp-keywords.html#snmp-community";
6262
6363 sigmatch_table[DETECT_AL_SNMP_COMMUNITY].flags |= SIGMATCH_NOOPT|SIGMATCH_INFO_STICKY_BUFFER;
6464
6565 {
6666 sigmatch_table[DETECT_AL_SNMP_PDU_TYPE].name = "snmp.pdu_type";
6767 sigmatch_table[DETECT_AL_SNMP_PDU_TYPE].desc = "match SNMP PDU type";
68 sigmatch_table[DETECT_AL_SNMP_PDU_TYPE].url = DOC_URL DOC_VERSION "/rules/snmp-keywords.html#snmp-pdu-type";
68 sigmatch_table[DETECT_AL_SNMP_PDU_TYPE].url = "/rules/snmp-keywords.html#snmp-pdu-type";
6969 sigmatch_table[DETECT_AL_SNMP_PDU_TYPE].Match = NULL;
7070 sigmatch_table[DETECT_AL_SNMP_PDU_TYPE].AppLayerTxMatch = DetectSNMPPduTypeMatch;
7171 sigmatch_table[DETECT_AL_SNMP_PDU_TYPE].Setup = DetectSNMPPduTypeSetup;
7373 #ifdef UNITTESTS
7474 sigmatch_table[DETECT_AL_SNMP_PDU_TYPE].RegisterTests = DetectSNMPPduTypeRegisterTests;
7575 #endif
76 sigmatch_table[DETECT_AL_SNMP_PDU_TYPE].flags |= SIGMATCH_NOOPT;
7776
7877 DetectSetupParseRegexes(PARSE_REGEX, &parse_regex, &parse_regex_study);
7978
4242 enum DetectSNMPVersionMode {
4343 PROCEDURE_EQ = 1, /* equal */
4444 PROCEDURE_LT, /* less than */
45 PROCEDURE_LE, /* less than */
45 PROCEDURE_LE, /* less than or equal */
4646 PROCEDURE_GT, /* greater than */
47 PROCEDURE_GE, /* greater than */
47 PROCEDURE_GE, /* greater than or equal */
4848 };
4949
5050 typedef struct DetectSNMPVersionData_ {
7777 {
7878 sigmatch_table[DETECT_AL_SNMP_VERSION].name = "snmp.version";
7979 sigmatch_table[DETECT_AL_SNMP_VERSION].desc = "match SNMP version";
80 sigmatch_table[DETECT_AL_SNMP_VERSION].url = DOC_URL DOC_VERSION "/rules/snmp-keywords.html#snmp-version";
80 sigmatch_table[DETECT_AL_SNMP_VERSION].url = "/rules/snmp-keywords.html#snmp-version";
8181 sigmatch_table[DETECT_AL_SNMP_VERSION].Match = NULL;
8282 sigmatch_table[DETECT_AL_SNMP_VERSION].AppLayerTxMatch = DetectSNMPVersionMatch;
8383 sigmatch_table[DETECT_AL_SNMP_VERSION].Setup = DetectSNMPVersionSetup;
8585 #ifdef UNITTESTS
8686 sigmatch_table[DETECT_AL_SNMP_VERSION].RegisterTests = DetectSNMPVersionRegisterTests;
8787 #endif
88 sigmatch_table[DETECT_AL_SNMP_VERSION].flags |= SIGMATCH_NOOPT;
8988
9089 DetectSetupParseRegexes(PARSE_REGEX, &parse_regex, &parse_regex_study);
9190
7676 {
7777 sigmatch_table[DETECT_AL_SSH_PROTOVERSION].name = "ssh.protoversion";
7878 sigmatch_table[DETECT_AL_SSH_PROTOVERSION].desc = "match SSH protocol version";
79 sigmatch_table[DETECT_AL_SSH_PROTOVERSION].url = DOC_URL DOC_VERSION "/rules/ssh-keywords.html#ssh-protoversion";
79 sigmatch_table[DETECT_AL_SSH_PROTOVERSION].url = "/rules/ssh-keywords.html#ssh-protoversion";
8080 sigmatch_table[DETECT_AL_SSH_PROTOVERSION].AppLayerTxMatch = DetectSshVersionMatch;
8181 sigmatch_table[DETECT_AL_SSH_PROTOVERSION].Setup = DetectSshVersionSetup;
8282 sigmatch_table[DETECT_AL_SSH_PROTOVERSION].Free = DetectSshVersionFree;
105105 sigmatch_table[DETECT_AL_SSH_PROTOCOL].name = KEYWORD_NAME;
106106 sigmatch_table[DETECT_AL_SSH_PROTOCOL].alias = KEYWORD_NAME_LEGACY;
107107 sigmatch_table[DETECT_AL_SSH_PROTOCOL].desc = BUFFER_NAME " sticky buffer";
108 sigmatch_table[DETECT_AL_SSH_PROTOCOL].url = DOC_URL DOC_VERSION "/rules/" KEYWORD_DOC;
108 sigmatch_table[DETECT_AL_SSH_PROTOCOL].url = "/rules/" KEYWORD_DOC;
109109 sigmatch_table[DETECT_AL_SSH_PROTOCOL].Setup = DetectSshProtocolSetup;
110110 sigmatch_table[DETECT_AL_SSH_PROTOCOL].flags |= SIGMATCH_INFO_STICKY_BUFFER | SIGMATCH_NOOPT;
111111
9090 {
9191 sigmatch_table[DETECT_AL_SSH_SOFTWAREVERSION].name = "ssh.softwareversion";
9292 sigmatch_table[DETECT_AL_SSH_SOFTWAREVERSION].desc = "match SSH software string";
93 sigmatch_table[DETECT_AL_SSH_SOFTWAREVERSION].url = DOC_URL DOC_VERSION "/rules/ssh-keywords.html#ssh-softwareversion";
93 sigmatch_table[DETECT_AL_SSH_SOFTWAREVERSION].url = "/rules/ssh-keywords.html#ssh-softwareversion";
9494 sigmatch_table[DETECT_AL_SSH_SOFTWAREVERSION].AppLayerTxMatch = DetectSshSoftwareVersionMatch;
9595 sigmatch_table[DETECT_AL_SSH_SOFTWAREVERSION].Setup = DetectSshSoftwareVersionSetup;
9696 sigmatch_table[DETECT_AL_SSH_SOFTWAREVERSION].Free = DetectSshSoftwareVersionFree;
106106 sigmatch_table[DETECT_AL_SSH_SOFTWARE].name = KEYWORD_NAME;
107107 sigmatch_table[DETECT_AL_SSH_SOFTWARE].alias = KEYWORD_NAME_LEGACY;
108108 sigmatch_table[DETECT_AL_SSH_SOFTWARE].desc = BUFFER_NAME " sticky buffer";
109 sigmatch_table[DETECT_AL_SSH_SOFTWARE].url = DOC_URL DOC_VERSION "/rules/" KEYWORD_DOC;
109 sigmatch_table[DETECT_AL_SSH_SOFTWARE].url = "/rules/" KEYWORD_DOC;
110110 sigmatch_table[DETECT_AL_SSH_SOFTWARE].Setup = DetectSshSoftwareSetup;
111111 sigmatch_table[DETECT_AL_SSH_SOFTWARE].flags |= SIGMATCH_INFO_STICKY_BUFFER | SIGMATCH_NOOPT;
112112
0 /* Copyright (C) 2007-2016 Open Information Security Foundation
0 /* Copyright (C) 2007-2020 Open Information Security Foundation
11 *
22 * You can copy, redistribute or modify this Program under the terms of
33 * the GNU General Public License version 2 as published by the Free
8282 {
8383 sigmatch_table[DETECT_AL_SSL_STATE].name = "ssl_state";
8484 sigmatch_table[DETECT_AL_SSL_STATE].desc = "match the state of the SSL connection";
85 sigmatch_table[DETECT_AL_SSL_STATE].url = DOC_URL DOC_VERSION "/rules/tls-keywords.html#ssl-state";
85 sigmatch_table[DETECT_AL_SSL_STATE].url = "/rules/tls-keywords.html#ssl-state";
8686 sigmatch_table[DETECT_AL_SSL_STATE].AppLayerTxMatch = DetectSslStateMatch;
8787 sigmatch_table[DETECT_AL_SSL_STATE].Setup = DetectSslStateSetup;
8888 sigmatch_table[DETECT_AL_SSL_STATE].Free = DetectSslStateFree;
155155 *
156156 * \param arg Pointer to the string to be parsed.
157157 *
158 * \retval ssd Pointer to DetectSslStateData on succese.
158 * \retval ssd Pointer to DetectSslStateData on success.
159159 * \retval NULL On failure.
160160 */
161161 static DetectSslStateData *DetectSslStateParse(const char *arg)
164164 int ret = 0, res = 0;
165165 int ov1[MAX_SUBSTRINGS];
166166 int ov2[MAX_SUBSTRINGS];
167 const char *str1;
168 const char *str2;
167 char str1[64];
168 char str2[64];
169169 int negate = 0;
170170 uint32_t flags = 0, mask = 0;
171171 DetectSslStateData *ssd = NULL;
178178 goto error;
179179 }
180180
181 res = pcre_get_substring((char *)arg, ov1, MAX_SUBSTRINGS, 1, &str1);
181 res = pcre_copy_substring((char *)arg, ov1, MAX_SUBSTRINGS, 1, str1, sizeof(str1));
182182 if (res < 0) {
183 SCLogError(SC_ERR_PCRE_GET_SUBSTRING, "pcre_get_substring failed");
183 SCLogError(SC_ERR_PCRE_COPY_SUBSTRING, "pcre_copy_substring failed");
184184 goto error;
185185 }
186186 negate = !strcmp("!", str1);
187 pcre_free_substring(str1);
188
189 res = pcre_get_substring((char *)arg, ov1, MAX_SUBSTRINGS, 2, &str1);
187
188 res = pcre_copy_substring((char *)arg, ov1, MAX_SUBSTRINGS, 2, str1, sizeof(str1));
190189 if (res < 0) {
191 SCLogError(SC_ERR_PCRE_GET_SUBSTRING, "pcre_get_substring failed");
190 SCLogError(SC_ERR_PCRE_COPY_SUBSTRING, "pcre_copy_substring failed");
192191 goto error;
193192 }
194193
218217 goto error;
219218 }
220219
221 pcre_free_substring(str1);
222
223 res = pcre_get_substring((char *)arg, ov1, MAX_SUBSTRINGS, 3, &str1);
220 res = pcre_copy_substring((char *)arg, ov1, MAX_SUBSTRINGS, 3, str1, sizeof(str1));
224221 if (res < 0) {
225 SCLogError(SC_ERR_PCRE_GET_SUBSTRING, "pcre_get_substring failed");
222 SCLogError(SC_ERR_PCRE_COPY_SUBSTRING, "pcre_copy_substring failed");
226223 goto error;
227224 }
228225 while (res > 0) {
234231 goto error;
235232 }
236233
237 res = pcre_get_substring((char *)str1, ov2, MAX_SUBSTRINGS, 1, &str2);
234 res = pcre_copy_substring((char *)str1, ov2, MAX_SUBSTRINGS, 1, str2, sizeof(str2));
238235 if (res < 0) {
239 SCLogError(SC_ERR_PCRE_GET_SUBSTRING, "pcre_get_substring failed");
236 SCLogError(SC_ERR_PCRE_COPY_SUBSTRING, "pcre_copy_substring failed");
240237 goto error;
241238 }
242239 negate = !strcmp("!", str2);
243 pcre_free_substring(str2);
244
245 res = pcre_get_substring((char *)str1, ov2, MAX_SUBSTRINGS, 2, &str2);
240
241 res = pcre_copy_substring((char *)str1, ov2, MAX_SUBSTRINGS, 2, str2, sizeof(str2));
246242 if (res <= 0) {
247 SCLogError(SC_ERR_PCRE_GET_SUBSTRING, "pcre_get_substring failed");
243 SCLogError(SC_ERR_PCRE_COPY_SUBSTRING, "pcre_copy_substring failed");
248244 goto error;
249245 }
250246 if (strcmp("client_hello", str2) == 0) {
273269 goto error;
274270 }
275271
276 res = pcre_get_substring((char *)str1, ov2, MAX_SUBSTRINGS, 3, &str2);
272 res = pcre_copy_substring((char *)str1, ov2, MAX_SUBSTRINGS, 3, str2, sizeof(str2));
277273 if (res < 0) {
278 SCLogError(SC_ERR_PCRE_GET_SUBSTRING, "pcre_get_substring failed");
279 goto error;
280 }
281
282 pcre_free_substring(str1);
283 str1 = str2;
284 }
285 pcre_free_substring(str1);
274 SCLogError(SC_ERR_PCRE_COPY_SUBSTRING, "pcre_copy_substring failed");
275 goto error;
276 }
277
278 memcpy(str1, str2, sizeof(str1));
279 }
286280
287281 if ( (ssd = SCMalloc(sizeof(DetectSslStateData))) == NULL) {
288282 goto error;
7676 {
7777 sigmatch_table[DETECT_AL_SSL_VERSION].name = "ssl_version";
7878 sigmatch_table[DETECT_AL_SSL_VERSION].desc = "match version of SSL/TLS record";
79 sigmatch_table[DETECT_AL_SSL_VERSION].url = DOC_URL DOC_VERSION "/rules/tls-keywords.html#ssl-version";
79 sigmatch_table[DETECT_AL_SSL_VERSION].url = "/rules/tls-keywords.html#ssl-version";
8080 sigmatch_table[DETECT_AL_SSL_VERSION].AppLayerTxMatch = DetectSslVersionMatch;
8181 sigmatch_table[DETECT_AL_SSL_VERSION].Setup = DetectSslVersionSetup;
8282 sigmatch_table[DETECT_AL_SSL_VERSION].Free = DetectSslVersionFree;
207207 }
208208
209209 if (ret > 1) {
210 const char *str_ptr;
211 char *orig;
212210 uint8_t found = 0, neg = 0;
213211 char *tmp_str;
214212
219217
220218 int i;
221219 for (i = 1; i < ret; i++) {
222 res = pcre_get_substring((char *) str, ov, MAX_SUBSTRINGS, i, &str_ptr);
220 char ver_ptr[64];
221 res = pcre_copy_substring((char *) str, ov, MAX_SUBSTRINGS, i, ver_ptr, sizeof(ver_ptr));
223222 if (res < 0) {
224223 SCLogError(SC_ERR_PCRE_GET_SUBSTRING, "pcre_get_substring failed");
225224 if (found == 0)
227226 break;
228227 }
229228
230 orig = SCStrdup((char*) str_ptr);
231 if (unlikely(orig == NULL)) {
232 goto error;
233 }
234 tmp_str = orig;
229 tmp_str = ver_ptr;
235230
236231 /* Let's see if we need to scape "'s */
237232 if (tmp_str[0] == '"') {
270265 if (neg == 1)
271266 ssl->data[TLS13].flags |= DETECT_SSL_VERSION_NEGATED;
272267 } else if (strcmp(tmp_str, "") == 0) {
273 SCFree(orig);
274268 if (found == 0)
275269 goto error;
276270 break;
277271 } else {
278272 SCLogError(SC_ERR_INVALID_VALUE, "Invalid value");
279 SCFree(orig);
280273 goto error;
281274 }
282275
283276 found = 1;
284277 neg = 0;
285 SCFree(orig);
286 pcre_free_substring(str_ptr);
287278 }
288279 }
289280
5757 {
5858 sigmatch_table[DETECT_STREAM_SIZE].name = "stream_size";
5959 sigmatch_table[DETECT_STREAM_SIZE].desc = "match on amount of bytes of a stream";
60 sigmatch_table[DETECT_STREAM_SIZE].url = DOC_URL DOC_VERSION "/rules/flow-keywords.html#stream-size";
60 sigmatch_table[DETECT_STREAM_SIZE].url = "/rules/flow-keywords.html#stream-size";
6161 sigmatch_table[DETECT_STREAM_SIZE].Match = DetectStreamSizeMatch;
6262 sigmatch_table[DETECT_STREAM_SIZE].Setup = DetectStreamSizeSetup;
6363 sigmatch_table[DETECT_STREAM_SIZE].Free = DetectStreamSizeFree;
5252 /* description: listed in "suricata --list-keywords=all" */
5353 sigmatch_table[DETECT_TARGET].desc = "indicate to output module which side is the target of the attack";
5454 /* link to further documentation of the keyword. Normally on the Suricata redmine/wiki */
55 sigmatch_table[DETECT_TARGET].url = DOC_URL DOC_VERSION "/rules/meta.html#target";
55 sigmatch_table[DETECT_TARGET].url = "/rules/meta.html#target";
5656 /* match function is called when the signature is inspected on a packet */
5757 sigmatch_table[DETECT_TARGET].Match = NULL;
5858 /* setup function is called during signature parsing, when the target
5555 sigmatch_table[DETECT_ACK].name = "tcp.ack";
5656 sigmatch_table[DETECT_ACK].alias = "ack";
5757 sigmatch_table[DETECT_ACK].desc = "check for a specific TCP acknowledgement number";
58 sigmatch_table[DETECT_ACK].url = DOC_URL DOC_VERSION "/rules/header-keywords.html#ack";
58 sigmatch_table[DETECT_ACK].url = "/rules/header-keywords.html#ack";
5959 sigmatch_table[DETECT_ACK].Match = DetectAckMatch;
6060 sigmatch_table[DETECT_ACK].Setup = DetectAckSetup;
6161 sigmatch_table[DETECT_ACK].Free = DetectAckFree;
7474 sigmatch_table[DETECT_FLAGS].name = "tcp.flags";
7575 sigmatch_table[DETECT_FLAGS].alias = "flags";
7676 sigmatch_table[DETECT_FLAGS].desc = "detect which flags are set in the TCP header";
77 sigmatch_table[DETECT_FLAGS].url = DOC_URL DOC_VERSION "/rules/header-keywords.html#tcp-flags";
77 sigmatch_table[DETECT_FLAGS].url = "/rules/header-keywords.html#tcp-flags";
7878 sigmatch_table[DETECT_FLAGS].Match = DetectFlagsMatch;
7979 sigmatch_table[DETECT_FLAGS].Setup = DetectFlagsSetup;
8080 sigmatch_table[DETECT_FLAGS].Free = DetectFlagsFree;
5252 sigmatch_table[DETECT_SEQ].name = "tcp.seq";
5353 sigmatch_table[DETECT_SEQ].alias = "seq";
5454 sigmatch_table[DETECT_SEQ].desc = "check for a specific TCP sequence number";
55 sigmatch_table[DETECT_SEQ].url = DOC_URL DOC_VERSION "/rules/header-keywords.html#seq";
55 sigmatch_table[DETECT_SEQ].url = "/rules/header-keywords.html#seq";
5656 sigmatch_table[DETECT_SEQ].Match = DetectSeqMatch;
5757 sigmatch_table[DETECT_SEQ].Setup = DetectSeqSetup;
5858 sigmatch_table[DETECT_SEQ].Free = DetectSeqFree;
6060 sigmatch_table[DETECT_WINDOW].name = "tcp.window";
6161 sigmatch_table[DETECT_WINDOW].alias = "window";
6262 sigmatch_table[DETECT_WINDOW].desc = "check for a specific TCP window size";
63 sigmatch_table[DETECT_WINDOW].url = DOC_URL DOC_VERSION "/rules/header-keywords.html#window";
63 sigmatch_table[DETECT_WINDOW].url = "/rules/header-keywords.html#window";
6464 sigmatch_table[DETECT_WINDOW].Match = DetectWindowMatch;
6565 sigmatch_table[DETECT_WINDOW].Setup = DetectWindowSetup;
6666 sigmatch_table[DETECT_WINDOW].Free = DetectWindowFree;
5050 {
5151 sigmatch_table[DETECT_TCPHDR].name = "tcp.hdr";
5252 sigmatch_table[DETECT_TCPHDR].desc = "sticky buffer to match on the TCP header";
53 sigmatch_table[DETECT_TCPHDR].url = DOC_URL DOC_VERSION "/rules/header-keywords.html#tcphdr";
53 sigmatch_table[DETECT_TCPHDR].url = "/rules/header-keywords.html#tcphdr";
5454 sigmatch_table[DETECT_TCPHDR].Setup = DetectTcphdrSetup;
5555 sigmatch_table[DETECT_TCPHDR].flags |= SIGMATCH_NOOPT | SIGMATCH_INFO_STICKY_BUFFER;
5656 #ifdef UNITTESTS
5656 {
5757 sigmatch_table[DETECT_TCPMSS].name = "tcp.mss";
5858 sigmatch_table[DETECT_TCPMSS].desc = "match on TCP MSS option field";
59 sigmatch_table[DETECT_TCPMSS].url = DOC_URL DOC_VERSION "/rules/header-keywords.html#tcpmss";
59 sigmatch_table[DETECT_TCPMSS].url = "/rules/header-keywords.html#tcpmss";
6060 sigmatch_table[DETECT_TCPMSS].Match = DetectTcpmssMatch;
6161 sigmatch_table[DETECT_TCPMSS].Setup = DetectTcpmssSetup;
6262 sigmatch_table[DETECT_TCPMSS].Free = DetectTcpmssFree;
5656 {
5757 sigmatch_table[DETECT_TEMPLATE2].name = "template2";
5858 sigmatch_table[DETECT_TEMPLATE2].desc = "TODO describe the keyword";
59 sigmatch_table[DETECT_TEMPLATE2].url = DOC_URL DOC_VERSION "/rules/header-keywords.html#template2";
59 sigmatch_table[DETECT_TEMPLATE2].url = "/rules/header-keywords.html#template2";
6060 sigmatch_table[DETECT_TEMPLATE2].Match = DetectTemplate2Match;
6161 sigmatch_table[DETECT_TEMPLATE2].Setup = DetectTemplate2Setup;
6262 sigmatch_table[DETECT_TEMPLATE2].Free = DetectTemplate2Free;
0 /* Copyright (C) 2007-2013 Open Information Security Foundation
0 /* Copyright (C) 2007-2020 Open Information Security Foundation
11 *
22 * You can copy, redistribute or modify this Program under the terms of
33 * the GNU General Public License version 2 as published by the Free
7676 {
7777 sigmatch_table[DETECT_THRESHOLD].name = "threshold";
7878 sigmatch_table[DETECT_THRESHOLD].desc = "control the rule's alert frequency";
79 sigmatch_table[DETECT_THRESHOLD].url = DOC_URL DOC_VERSION "/rules/thresholding.html#threshold";
79 sigmatch_table[DETECT_THRESHOLD].url = "/rules/thresholding.html#threshold";
8080 sigmatch_table[DETECT_THRESHOLD].Match = DetectThresholdMatch;
8181 sigmatch_table[DETECT_THRESHOLD].Setup = DetectThresholdSetup;
8282 sigmatch_table[DETECT_THRESHOLD].Free = DetectThresholdFree;
228228 SigMatch *tmpm = NULL;
229229
230230 /* checks if there is a previous instance of detection_filter */
231 tmpm = DetectGetLastSMFromLists(s, DETECT_DETECTION_FILTER, -1);
231 tmpm = DetectGetLastSMFromLists(s, DETECT_THRESHOLD, DETECT_DETECTION_FILTER, -1);
232232 if (tmpm != NULL) {
233 SCLogError(SC_ERR_INVALID_SIGNATURE, "\"detection_filter\" and "
234 "\"threshold\" are not allowed in the same rule");
233 if (tmpm->type == DETECT_DETECTION_FILTER) {
234 SCLogError(SC_ERR_INVALID_SIGNATURE, "\"detection_filter\" and "
235 "\"threshold\" are not allowed in the same rule");
236 } else {
237 SCLogError(SC_ERR_INVALID_SIGNATURE, "multiple \"threshold\" "
238 "options are not allowed in the same rule");
239 }
235240 SCReturnInt(-1);
236241 }
237242
283288 /**
284289 * \test ThresholdTestParse01 is a test for a valid threshold options
285290 *
286 * \retval 1 on succces
291 * \retval 1 on success
287292 * \retval 0 on failure
288293 */
289294 static int ThresholdTestParse01(void)
301306 /**
302307 * \test ThresholdTestParse02 is a test for a invalid threshold options
303308 *
304 * \retval 1 on succces
309 * \retval 1 on success
305310 * \retval 0 on failure
306311 */
307312 static int ThresholdTestParse02(void)
319324 /**
320325 * \test ThresholdTestParse03 is a test for a valid threshold options in any order
321326 *
322 * \retval 1 on succces
327 * \retval 1 on success
323328 * \retval 0 on failure
324329 */
325330 static int ThresholdTestParse03(void)
338343 /**
339344 * \test ThresholdTestParse04 is a test for an invalid threshold options in any order
340345 *
341 * \retval 1 on succces
346 * \retval 1 on success
342347 * \retval 0 on failure
343348 */
344349 static int ThresholdTestParse04(void)
356361 /**
357362 * \test ThresholdTestParse05 is a test for a valid threshold options in any order
358363 *
359 * \retval 1 on succces
364 * \retval 1 on success
360365 * \retval 0 on failure
361366 */
362367 static int ThresholdTestParse05(void)
377382 * by setting up the signature and later testing its working by matching
378383 * the received packet against the sig.
379384 *
380 * \retval 1 on succces
385 * \retval 1 on success
381386 * \retval 0 on failure
382387 */
383388
481486 * by setting up the signature and later testing its working by matching
482487 * the received packet against the sig.
483488 *
484 * \retval 1 on succces
489 * \retval 1 on success
485490 * \retval 0 on failure
486491 */
487492
559564 * by setting up the signature and later testing its working by matching
560565 * the received packet against the sig.
561566 *
562 * \retval 1 on succces
567 * \retval 1 on success
563568 * \retval 0 on failure
564569 */
565570
664669 * by setting up the signature and later testing its working by matching
665670 * the received packet against the sig.
666671 *
667 * \retval 1 on succces
672 * \retval 1 on success
668673 * \retval 0 on failure
669674 */
670675
742747 * by setting up the signature and later testing its working by matching
743748 * the received packet against the sig.
744749 *
745 * \retval 1 on succces
750 * \retval 1 on success
746751 * \retval 0 on failure
747752 */
748753
7575 sigmatch_table[DETECT_AL_TLS_CERT_FINGERPRINT].name = "tls.cert_fingerprint";
7676 sigmatch_table[DETECT_AL_TLS_CERT_FINGERPRINT].alias = "tls_cert_fingerprint";
7777 sigmatch_table[DETECT_AL_TLS_CERT_FINGERPRINT].desc = "match on the TLS cert fingerprint buffer";
78 sigmatch_table[DETECT_AL_TLS_CERT_FINGERPRINT].url = DOC_URL DOC_VERSION "/rules/tls-keywords.html#tls-cert-fingerprint";
78 sigmatch_table[DETECT_AL_TLS_CERT_FINGERPRINT].url = "/rules/tls-keywords.html#tls-cert-fingerprint";
7979 sigmatch_table[DETECT_AL_TLS_CERT_FINGERPRINT].Setup = DetectTlsFingerprintSetup;
8080 #ifdef UNITTESTS
8181 sigmatch_table[DETECT_AL_TLS_CERT_FINGERPRINT].RegisterTests = DetectTlsFingerprintRegisterTests;
7171 sigmatch_table[DETECT_AL_TLS_CERT_ISSUER].name = "tls.cert_issuer";
7272 sigmatch_table[DETECT_AL_TLS_CERT_ISSUER].alias = "tls_cert_issuer";
7373 sigmatch_table[DETECT_AL_TLS_CERT_ISSUER].desc = "content modifier to match specifically and only on the TLS cert issuer buffer";
74 sigmatch_table[DETECT_AL_TLS_CERT_ISSUER].url = DOC_URL DOC_VERSION "/rules/tls-keywords.html#tls-cert-issuer";
74 sigmatch_table[DETECT_AL_TLS_CERT_ISSUER].url = "/rules/tls-keywords.html#tls-cert-issuer";
7575 sigmatch_table[DETECT_AL_TLS_CERT_ISSUER].Setup = DetectTlsIssuerSetup;
7676 #ifdef UNITTESTS
7777 sigmatch_table[DETECT_AL_TLS_CERT_ISSUER].RegisterTests = DetectTlsIssuerRegisterTests;
7575 sigmatch_table[DETECT_AL_TLS_CERT_SERIAL].name = "tls.cert_serial";
7676 sigmatch_table[DETECT_AL_TLS_CERT_SERIAL].alias = "tls_cert_serial";
7777 sigmatch_table[DETECT_AL_TLS_CERT_SERIAL].desc = "content modifier to match the TLS cert serial buffer";
78 sigmatch_table[DETECT_AL_TLS_CERT_SERIAL].url = DOC_URL DOC_VERSION "/rules/tls-keywords.html#tls-cert-serial";
78 sigmatch_table[DETECT_AL_TLS_CERT_SERIAL].url = "/rules/tls-keywords.html#tls-cert-serial";
7979 sigmatch_table[DETECT_AL_TLS_CERT_SERIAL].Setup = DetectTlsSerialSetup;
8080 #ifdef UNITTESTS
8181 sigmatch_table[DETECT_AL_TLS_CERT_SERIAL].RegisterTests = DetectTlsSerialRegisterTests;
7171 sigmatch_table[DETECT_AL_TLS_CERT_SUBJECT].name = "tls.cert_subject";
7272 sigmatch_table[DETECT_AL_TLS_CERT_SUBJECT].alias = "tls_cert_subject";
7373 sigmatch_table[DETECT_AL_TLS_CERT_SUBJECT].desc = "content modifier to match specifically and only on the TLS cert subject buffer";
74 sigmatch_table[DETECT_AL_TLS_CERT_SUBJECT].url = DOC_URL DOC_VERSION "/rules/tls-keywords.html#tls-cert-subject";
74 sigmatch_table[DETECT_AL_TLS_CERT_SUBJECT].url = "/rules/tls-keywords.html#tls-cert-subject";
7575 sigmatch_table[DETECT_AL_TLS_CERT_SUBJECT].Setup = DetectTlsSubjectSetup;
7676 #ifdef UNITTESTS
7777 sigmatch_table[DETECT_AL_TLS_CERT_SUBJECT].RegisterTests = DetectTlsSubjectRegisterTests;
8888 {
8989 sigmatch_table[DETECT_AL_TLS_NOTBEFORE].name = "tls_cert_notbefore";
9090 sigmatch_table[DETECT_AL_TLS_NOTBEFORE].desc = "match TLS certificate notBefore field";
91 sigmatch_table[DETECT_AL_TLS_NOTBEFORE].url = DOC_URL DOC_VERSION "/rules/tls-keywords.html#tls-cert-notbefore";
91 sigmatch_table[DETECT_AL_TLS_NOTBEFORE].url = "/rules/tls-keywords.html#tls-cert-notbefore";
9292 sigmatch_table[DETECT_AL_TLS_NOTBEFORE].AppLayerTxMatch = DetectTlsValidityMatch;
9393 sigmatch_table[DETECT_AL_TLS_NOTBEFORE].Setup = DetectTlsNotBeforeSetup;
9494 sigmatch_table[DETECT_AL_TLS_NOTBEFORE].Free = DetectTlsValidityFree;
9898
9999 sigmatch_table[DETECT_AL_TLS_NOTAFTER].name = "tls_cert_notafter";
100100 sigmatch_table[DETECT_AL_TLS_NOTAFTER].desc = "match TLS certificate notAfter field";
101 sigmatch_table[DETECT_AL_TLS_NOTAFTER].url = DOC_URL DOC_VERSION "/rules/tls-keywords.html#tls-cert-notafter";
101 sigmatch_table[DETECT_AL_TLS_NOTAFTER].url = "/rules/tls-keywords.html#tls-cert-notafter";
102102 sigmatch_table[DETECT_AL_TLS_NOTAFTER].AppLayerTxMatch = DetectTlsValidityMatch;
103103 sigmatch_table[DETECT_AL_TLS_NOTAFTER].Setup = DetectTlsNotAfterSetup;
104104 sigmatch_table[DETECT_AL_TLS_NOTAFTER].Free = DetectTlsValidityFree;
108108
109109 sigmatch_table[DETECT_AL_TLS_EXPIRED].name = "tls_cert_expired";
110110 sigmatch_table[DETECT_AL_TLS_EXPIRED].desc = "match expired TLS certificates";
111 sigmatch_table[DETECT_AL_TLS_EXPIRED].url = DOC_URL DOC_VERSION "/rules/tls-keywords.html#tls-cert-expired";
111 sigmatch_table[DETECT_AL_TLS_EXPIRED].url = "/rules/tls-keywords.html#tls-cert-expired";
112112 sigmatch_table[DETECT_AL_TLS_EXPIRED].AppLayerTxMatch = DetectTlsValidityMatch;
113113 sigmatch_table[DETECT_AL_TLS_EXPIRED].Setup = DetectTlsExpiredSetup;
114114 sigmatch_table[DETECT_AL_TLS_EXPIRED].Free = DetectTlsValidityFree;
119119
120120 sigmatch_table[DETECT_AL_TLS_VALID].name = "tls_cert_valid";
121121 sigmatch_table[DETECT_AL_TLS_VALID].desc = "match valid TLS certificates";
122 sigmatch_table[DETECT_AL_TLS_VALID].url = DOC_URL DOC_VERSION "/rules/tls-keywords.html#tls-cert-valid";
122 sigmatch_table[DETECT_AL_TLS_VALID].url = "/rules/tls-keywords.html#tls-cert-valid";
123123 sigmatch_table[DETECT_AL_TLS_VALID].AppLayerTxMatch = DetectTlsValidityMatch;
124124 sigmatch_table[DETECT_AL_TLS_VALID].Setup = DetectTlsValidSetup;
125125 sigmatch_table[DETECT_AL_TLS_VALID].Free = DetectTlsValidityFree;
8787 {
8888 sigmatch_table[DETECT_AL_TLS_CERTS].name = "tls.certs";
8989 sigmatch_table[DETECT_AL_TLS_CERTS].desc = "content modifier to match the TLS certificate sticky buffer";
90 sigmatch_table[DETECT_AL_TLS_CERTS].url = DOC_URL DOC_VERSION "/rules/tls-keywords.html#tls-certs";
90 sigmatch_table[DETECT_AL_TLS_CERTS].url = "/rules/tls-keywords.html#tls-certs";
9191 sigmatch_table[DETECT_AL_TLS_CERTS].Setup = DetectTlsCertsSetup;
9292 #ifdef UNITTESTS
9393 sigmatch_table[DETECT_AL_TLS_CERTS].RegisterTests = DetectTlsCertsRegisterTests;
7979 sigmatch_table[DETECT_AL_TLS_JA3_HASH].name = "ja3.hash";
8080 sigmatch_table[DETECT_AL_TLS_JA3_HASH].alias = "ja3_hash";
8181 sigmatch_table[DETECT_AL_TLS_JA3_HASH].desc = "content modifier to match the JA3 hash buffer";
82 sigmatch_table[DETECT_AL_TLS_JA3_HASH].url = DOC_URL DOC_VERSION "/rules/ja3-keywords.html#ja3-hash";
82 sigmatch_table[DETECT_AL_TLS_JA3_HASH].url = "/rules/ja3-keywords.html#ja3-hash";
8383 sigmatch_table[DETECT_AL_TLS_JA3_HASH].Setup = DetectTlsJa3HashSetup;
8484 #ifdef UNITTESTS
8585 sigmatch_table[DETECT_AL_TLS_JA3_HASH].RegisterTests = DetectTlsJa3HashRegisterTests;
7575 sigmatch_table[DETECT_AL_TLS_JA3_STRING].name = "ja3.string";
7676 sigmatch_table[DETECT_AL_TLS_JA3_STRING].alias = "ja3_string";
7777 sigmatch_table[DETECT_AL_TLS_JA3_STRING].desc = "content modifier to match the JA3 string buffer";
78 sigmatch_table[DETECT_AL_TLS_JA3_STRING].url = DOC_URL DOC_VERSION "/rules/ja3-keywords.html#ja3-string";
78 sigmatch_table[DETECT_AL_TLS_JA3_STRING].url = "/rules/ja3-keywords.html#ja3-string";
7979 sigmatch_table[DETECT_AL_TLS_JA3_STRING].Setup = DetectTlsJa3StringSetup;
8080 #ifdef UNITTESTS
8181 sigmatch_table[DETECT_AL_TLS_JA3_STRING].RegisterTests = DetectTlsJa3StringRegisterTests;
7878 {
7979 sigmatch_table[DETECT_AL_TLS_JA3S_HASH].name = "ja3s.hash";
8080 sigmatch_table[DETECT_AL_TLS_JA3S_HASH].desc = "content modifier to match the JA3S hash sticky buffer";
81 sigmatch_table[DETECT_AL_TLS_JA3S_HASH].url = DOC_URL DOC_VERSION "/rules/ja3-keywords.html#ja3s-hash";
81 sigmatch_table[DETECT_AL_TLS_JA3S_HASH].url = "/rules/ja3-keywords.html#ja3s-hash";
8282 sigmatch_table[DETECT_AL_TLS_JA3S_HASH].Setup = DetectTlsJa3SHashSetup;
8383 #ifdef UNITTESTS
8484 sigmatch_table[DETECT_AL_TLS_JA3S_HASH].RegisterTests = DetectTlsJa3SHashRegisterTests;
7474 {
7575 sigmatch_table[DETECT_AL_TLS_JA3S_STRING].name = "ja3s.string";
7676 sigmatch_table[DETECT_AL_TLS_JA3S_STRING].desc = "content modifier to match the JA3S string sticky buffer";
77 sigmatch_table[DETECT_AL_TLS_JA3S_STRING].url = DOC_URL DOC_VERSION "/rules/ja3-keywords.html#ja3s-string";
77 sigmatch_table[DETECT_AL_TLS_JA3S_STRING].url = "/rules/ja3-keywords.html#ja3s-string";
7878 sigmatch_table[DETECT_AL_TLS_JA3S_STRING].Setup = DetectTlsJa3SStringSetup;
7979 #ifdef UNITTESTS
8080 sigmatch_table[DETECT_AL_TLS_JA3S_STRING].RegisterTests = DetectTlsJa3SStringRegisterTests;
7171 sigmatch_table[DETECT_AL_TLS_SNI].name = "tls.sni";
7272 sigmatch_table[DETECT_AL_TLS_SNI].alias = "tls_sni";
7373 sigmatch_table[DETECT_AL_TLS_SNI].desc = "content modifier to match specifically and only on the TLS SNI buffer";
74 sigmatch_table[DETECT_AL_TLS_SNI].url = DOC_URL DOC_VERSION "/rules/tls-keywords.html#tls-sni";
74 sigmatch_table[DETECT_AL_TLS_SNI].url = "/rules/tls-keywords.html#tls-sni";
7575 sigmatch_table[DETECT_AL_TLS_SNI].Setup = DetectTlsSniSetup;
7676 #ifdef UNITTESTS
7777 sigmatch_table[DETECT_AL_TLS_SNI].RegisterTests = DetectTlsSniRegisterTests;
7575 {
7676 sigmatch_table[DETECT_AL_TLS_VERSION].name = "tls.version";
7777 sigmatch_table[DETECT_AL_TLS_VERSION].desc = "match on TLS/SSL version";
78 sigmatch_table[DETECT_AL_TLS_VERSION].url = DOC_URL DOC_VERSION "/rules/tls-keywords.html#tls-version";
78 sigmatch_table[DETECT_AL_TLS_VERSION].url = "/rules/tls-keywords.html#tls-version";
7979 sigmatch_table[DETECT_AL_TLS_VERSION].AppLayerTxMatch = DetectTlsVersionMatch;
8080 sigmatch_table[DETECT_AL_TLS_VERSION].Setup = DetectTlsVersionSetup;
8181 sigmatch_table[DETECT_AL_TLS_VERSION].Free = DetectTlsVersionFree;
163163 }
164164
165165 if (ret > 1) {
166 const char *str_ptr;
167 char *orig;
166 char ver_ptr[64];
168167 char *tmp_str;
169 res = pcre_get_substring((char *)str, ov, MAX_SUBSTRINGS, 1, &str_ptr);
168 res = pcre_copy_substring((char *)str, ov, MAX_SUBSTRINGS, 1, ver_ptr, sizeof(ver_ptr));
170169 if (res < 0) {
171 SCLogError(SC_ERR_PCRE_GET_SUBSTRING, "pcre_get_substring failed");
170 SCLogError(SC_ERR_PCRE_GET_SUBSTRING, "pcre_copy_substring failed");
172171 goto error;
173172 }
174173
177176 if (unlikely(tls == NULL))
178177 goto error;
179178
180 orig = SCStrdup((char*)str_ptr);
181 if (unlikely(orig == NULL)) {
182 goto error;
183 }
184 tmp_str=orig;
179 tmp_str = ver_ptr;
185180
186181 /* Let's see if we need to scape "'s */
187182 if (tmp_str[0] == '"')
203198 tls->flags |= DETECT_TLS_VERSION_FLAG_RAW;
204199 } else {
205200 SCLogError(SC_ERR_INVALID_VALUE, "Invalid value");
206 SCFree(orig);
207201 goto error;
208202 }
209203
210204 tls->ver = temp;
211
212 SCFree(orig);
213205
214206 SCLogDebug("will look for tls %"PRIu16"", tls->ver);
215207 }
116116 {
117117 sigmatch_table[DETECT_AL_TLS_SUBJECT].name = "tls.subject";
118118 sigmatch_table[DETECT_AL_TLS_SUBJECT].desc = "match TLS/SSL certificate Subject field";
119 sigmatch_table[DETECT_AL_TLS_SUBJECT].url = DOC_URL DOC_VERSION "/rules/tls-keywords.html#tls-subject";
119 sigmatch_table[DETECT_AL_TLS_SUBJECT].url = "/rules/tls-keywords.html#tls-subject";
120120 sigmatch_table[DETECT_AL_TLS_SUBJECT].AppLayerTxMatch = DetectTlsSubjectMatch;
121121 sigmatch_table[DETECT_AL_TLS_SUBJECT].Setup = DetectTlsSubjectSetup;
122122 sigmatch_table[DETECT_AL_TLS_SUBJECT].Free = DetectTlsSubjectFree;
126126
127127 sigmatch_table[DETECT_AL_TLS_ISSUERDN].name = "tls.issuerdn";
128128 sigmatch_table[DETECT_AL_TLS_ISSUERDN].desc = "match TLS/SSL certificate IssuerDN field";
129 sigmatch_table[DETECT_AL_TLS_ISSUERDN].url = DOC_URL DOC_VERSION "/rules/tls-keywords.html#tls-issuerdn";
129 sigmatch_table[DETECT_AL_TLS_ISSUERDN].url = "/rules/tls-keywords.html#tls-issuerdn";
130130 sigmatch_table[DETECT_AL_TLS_ISSUERDN].AppLayerTxMatch = DetectTlsIssuerDNMatch;
131131 sigmatch_table[DETECT_AL_TLS_ISSUERDN].Setup = DetectTlsIssuerDNSetup;
132132 sigmatch_table[DETECT_AL_TLS_ISSUERDN].Free = DetectTlsIssuerDNFree;
136136
137137 sigmatch_table[DETECT_AL_TLS_FINGERPRINT].name = "tls.fingerprint";
138138 sigmatch_table[DETECT_AL_TLS_FINGERPRINT].desc = "match TLS/SSL certificate SHA1 fingerprint";
139 sigmatch_table[DETECT_AL_TLS_FINGERPRINT].url = DOC_URL DOC_VERSION "/rules/tls-keywords.html#tls-fingerprint";
139 sigmatch_table[DETECT_AL_TLS_FINGERPRINT].url = "/rules/tls-keywords.html#tls-fingerprint";
140140 sigmatch_table[DETECT_AL_TLS_FINGERPRINT].AppLayerTxMatch = DetectTlsFingerprintMatch;
141141 sigmatch_table[DETECT_AL_TLS_FINGERPRINT].Setup = DetectTlsFingerprintSetup;
142142 sigmatch_table[DETECT_AL_TLS_FINGERPRINT].Free = DetectTlsFingerprintFree;
147147 sigmatch_table[DETECT_AL_TLS_STORE].name = "tls_store";
148148 sigmatch_table[DETECT_AL_TLS_STORE].alias = "tls.store";
149149 sigmatch_table[DETECT_AL_TLS_STORE].desc = "store TLS/SSL certificate on disk";
150 sigmatch_table[DETECT_AL_TLS_STORE].url = DOC_URL DOC_VERSION "/rules/tls-keywords.html#tls-store";
150 sigmatch_table[DETECT_AL_TLS_STORE].url = "/rules/tls-keywords.html#tls-store";
151151 sigmatch_table[DETECT_AL_TLS_STORE].Match = DetectTlsStorePostMatch;
152152 sigmatch_table[DETECT_AL_TLS_STORE].Setup = DetectTlsStoreSetup;
153153 sigmatch_table[DETECT_AL_TLS_STORE].Free = NULL;
7070 sigmatch_table[DETECT_TOS].flags =
7171 (SIGMATCH_QUOTES_OPTIONAL|SIGMATCH_HANDLE_NEGATION);
7272 sigmatch_table[DETECT_TOS].url =
73 DOC_URL DOC_VERSION "/rules/header-keywords.html#tos";
73 "/rules/header-keywords.html#tos";
7474
7575 DetectSetupParseRegexes(PARSE_REGEX, &parse_regex, &parse_regex_study);
7676 }
4545 "modify buffer to compress consecutive whitespace characters "
4646 "into a single one before inspection";
4747 sigmatch_table[DETECT_TRANSFORM_COMPRESS_WHITESPACE].url =
48 DOC_URL DOC_VERSION "/rules/transforms.html#compress-whitespace";
48 "/rules/transforms.html#compress-whitespace";
4949 sigmatch_table[DETECT_TRANSFORM_COMPRESS_WHITESPACE].Transform =
5050 TransformCompressWhitespace;
5151 sigmatch_table[DETECT_TRANSFORM_COMPRESS_WHITESPACE].Setup =
4646 sigmatch_table[DETECT_TRANSFORM_DOTPREFIX].desc =
4747 "modify buffer to extract the dotprefix";
4848 sigmatch_table[DETECT_TRANSFORM_DOTPREFIX].url =
49 DOC_URL DOC_VERSION "/rules/transforms.html#dotprefix";
49 "/rules/transforms.html#dotprefix";
5050 sigmatch_table[DETECT_TRANSFORM_DOTPREFIX].Transform = TransformDotPrefix;
5151 sigmatch_table[DETECT_TRANSFORM_DOTPREFIX].Setup = DetectTransformDotPrefixSetup;
5252 sigmatch_table[DETECT_TRANSFORM_DOTPREFIX].RegisterTests =
4545 sigmatch_table[DETECT_TRANSFORM_MD5].desc =
4646 "convert to md5 hash of the buffer";
4747 sigmatch_table[DETECT_TRANSFORM_MD5].url =
48 DOC_URL DOC_VERSION "/rules/transforms.html#to-md5";
48 "/rules/transforms.html#to-md5";
4949 sigmatch_table[DETECT_TRANSFORM_MD5].Setup =
5050 DetectTransformToMd5Setup;
5151 #ifdef HAVE_NSS
4545 sigmatch_table[DETECT_TRANSFORM_SHA1].desc =
4646 "convert to sha1 hash of the buffer";
4747 sigmatch_table[DETECT_TRANSFORM_SHA1].url =
48 DOC_URL DOC_VERSION "/rules/transforms.html#to-sha1";
48 "/rules/transforms.html#to-sha1";
4949 sigmatch_table[DETECT_TRANSFORM_SHA1].Setup =
5050 DetectTransformToSha1Setup;
5151 #ifdef HAVE_NSS
4545 sigmatch_table[DETECT_TRANSFORM_SHA256].desc =
4646 "convert to sha256 hash of the buffer";
4747 sigmatch_table[DETECT_TRANSFORM_SHA256].url =
48 DOC_URL DOC_VERSION "/rules/transforms.html#to-sha256";
48 "/rules/transforms.html#to-sha256";
4949 sigmatch_table[DETECT_TRANSFORM_SHA256].Setup =
5050 DetectTransformToSha256Setup;
5151 #ifdef HAVE_NSS
4444 sigmatch_table[DETECT_TRANSFORM_STRIP_WHITESPACE].desc =
4545 "modify buffer to strip whitespace before inspection";
4646 sigmatch_table[DETECT_TRANSFORM_STRIP_WHITESPACE].url =
47 DOC_URL DOC_VERSION "/rules/transforms.html#strip-whitespace";
47 "/rules/transforms.html#strip-whitespace";
4848 sigmatch_table[DETECT_TRANSFORM_STRIP_WHITESPACE].Transform =
4949 TransformStripWhitespace;
5050 sigmatch_table[DETECT_TRANSFORM_STRIP_WHITESPACE].Setup =
6060 {
6161 sigmatch_table[DETECT_TTL].name = "ttl";
6262 sigmatch_table[DETECT_TTL].desc = "check for a specific IP time-to-live value";
63 sigmatch_table[DETECT_TTL].url = DOC_URL DOC_VERSION "/rules/header-keywords.html#ttl";
63 sigmatch_table[DETECT_TTL].url = "/rules/header-keywords.html#ttl";
6464 sigmatch_table[DETECT_TTL].Match = DetectTtlMatch;
6565 sigmatch_table[DETECT_TTL].Setup = DetectTtlSetup;
6666 sigmatch_table[DETECT_TTL].Free = DetectTtlFree;
4949 {
5050 sigmatch_table[DETECT_UDPHDR].name = "udp.hdr";
5151 sigmatch_table[DETECT_UDPHDR].desc = "sticky buffer to match on the UDP header";
52 sigmatch_table[DETECT_UDPHDR].url = DOC_URL DOC_VERSION "/rules/header-keywords.html#udphdr";
52 sigmatch_table[DETECT_UDPHDR].url = "/rules/header-keywords.html#udphdr";
5353 sigmatch_table[DETECT_UDPHDR].Setup = DetectUdphdrSetup;
5454 sigmatch_table[DETECT_UDPHDR].flags |= SIGMATCH_NOOPT | SIGMATCH_INFO_STICKY_BUFFER;
5555 #ifdef UNITTESTS
6868 {
6969 sigmatch_table[DETECT_URICONTENT].name = "uricontent";
7070 sigmatch_table[DETECT_URICONTENT].desc = "legacy keyword to match on the request URI buffer";
71 sigmatch_table[DETECT_URICONTENT].url = DOC_URL DOC_VERSION "/rules/http-keywords.html#uricontent";
71 sigmatch_table[DETECT_URICONTENT].url = "/rules/http-keywords.html#uricontent";
7272 sigmatch_table[DETECT_URICONTENT].Match = NULL;
7373 sigmatch_table[DETECT_URICONTENT].Setup = DetectUricontentSetup;
7474 sigmatch_table[DETECT_URICONTENT].Free = DetectUricontentFree;
6565 {
6666 sigmatch_table[DETECT_AL_URILEN].name = "urilen";
6767 sigmatch_table[DETECT_AL_URILEN].desc = "match on the length of the HTTP uri";
68 sigmatch_table[DETECT_AL_URILEN].url = DOC_URL DOC_VERSION "/rules/http-keywords.html#urilen";
68 sigmatch_table[DETECT_AL_URILEN].url = "/rules/http-keywords.html#urilen";
6969 sigmatch_table[DETECT_AL_URILEN].Match = NULL;
7070 sigmatch_table[DETECT_AL_URILEN].Setup = DetectUrilenSetup;
7171 sigmatch_table[DETECT_AL_URILEN].Free = DetectUrilenFree;
5151 {
5252 sigmatch_table[DETECT_WITHIN].name = "within";
5353 sigmatch_table[DETECT_WITHIN].desc = "indicate that this content match has to be within a certain distance of the previous content keyword match";
54 sigmatch_table[DETECT_WITHIN].url = DOC_URL DOC_VERSION "/rules/payload-keywords.html#within";
54 sigmatch_table[DETECT_WITHIN].url = "/rules/payload-keywords.html#within";
5555 sigmatch_table[DETECT_WITHIN].Match = NULL;
5656 sigmatch_table[DETECT_WITHIN].Setup = DetectWithinSetup;
5757 sigmatch_table[DETECT_WITHIN].Free = NULL;
6565 {
6666 sigmatch_table[DETECT_XBITS].name = "xbits";
6767 sigmatch_table[DETECT_XBITS].desc = "operate on bits";
68 sigmatch_table[DETECT_XBITS].url = DOC_URL DOC_VERSION "/rules/xbits.html";
68 sigmatch_table[DETECT_XBITS].url = "/rules/xbits.html";
6969 sigmatch_table[DETECT_XBITS].Match = DetectXbitMatch;
7070 sigmatch_table[DETECT_XBITS].Setup = DetectXbitSetup;
7171 sigmatch_table[DETECT_XBITS].Free = DetectXbitFree;
0 /* Copyright (C) 2007-2014 Open Information Security Foundation
0 /* Copyright (C) 2007-2020 Open Information Security Foundation
11 *
22 * You can copy, redistribute or modify this Program under the terms of
33 * the GNU General Public License version 2 as published by the Free
14751475 Signature *DetectGetTagSignature(void);
14761476
14771477
1478 int DetectUnregisterThreadCtxFuncs(DetectEngineCtx *, DetectEngineThreadCtx *,void *data, const char *name);
14781479 int DetectRegisterThreadCtxFuncs(DetectEngineCtx *, const char *name, void *(*InitFunc)(void *), void *data, void (*FreeFunc)(void *), int);
14791480 void *DetectThreadCtxGetKeywordThreadCtx(DetectEngineThreadCtx *, int);
14801481
751751 */
752752 memset(&ts, 0, sizeof(ts));
753753
754 /* don't start our activities until time is setup */
755 while (!TimeModeIsReady()) {
756 if (suricata_ctl_flags != 0)
757 return TM_ECODE_OK;
758 }
759
754760 while (1)
755761 {
756762 if (TmThreadsCheckFlag(th_v, THV_PAUSE)) {
6161 #include "stream.h"
6262
6363 #include "app-layer-parser.h"
64 #include "app-layer-expectation.h"
6465
6566 #define FLOW_DEFAULT_EMERGENCY_RECOVERY 30
6667
10441045 {
10451046 SCEnter();
10461047
1048 if (unlikely(f->flags & FLOW_HAS_EXPECTATION)) {
1049 AppLayerExpectationClean(f);
1050 }
1051
10471052 /* call the protocol specific free function if we have one */
10481053 if (flow_freefuncs[proto_map].Freefunc != NULL) {
10491054 flow_freefuncs[proto_map].Freefunc(f->protoctx);
103103 #define FLOW_WRONG_THREAD BIT_U32(25)
104104 /** Protocol detection told us flow is picked up in wrong direction (midstream) */
105105 #define FLOW_DIR_REVERSED BIT_U32(26)
106 /** Indicate that the flow did trigger an expectation creation */
107 #define FLOW_HAS_EXPECTATION BIT_U32(27)
106108
107109 /* File flags */
108110
9898 TAILQ_FOREACH(response, &tx->response_list, next) {
9999 /* handle multiple lines within the response, \r\n delimited */
100100 uint8_t *where = response->str;
101 uint16_t length = response->len;
101 uint16_t length = response->len ? response->len -1 : 0;
102102 uint16_t pos;
103103 while ((pos = JsonGetNextLineFromBuffer((const char *)where, length)) != UINT16_MAX) {
104104 uint16_t offset = 0;
384384 if (!StatsEnabled()) {
385385 SCLogError(SC_ERR_STATS_LOG_GENERIC,
386386 "stats.json: stats are disabled globally: set stats.enabled to true. "
387 "See %s%s/configuration/suricata-yaml.html#stats", DOC_URL, DOC_VERSION);
387 "See %s/configuration/suricata-yaml.html#stats", GetDocURL());
388388 return result;
389389 }
390390
463463 if (!StatsEnabled()) {
464464 SCLogError(SC_ERR_STATS_LOG_GENERIC,
465465 "eve.stats: stats are disabled globally: set stats.enabled to true. "
466 "See %s%s/configuration/suricata-yaml.html#stats", DOC_URL, DOC_VERSION);
466 "See %s/configuration/suricata-yaml.html#stats", GetDocURL());
467467 return result;
468468 }
469469
549549 _Q_INVALIDATE((elm)->field.cqe_next); \
550550 } while (0)
551551
552 #define CIRCLEQ_FOREACH_SAFE(var, head, field, tvar) \
553 for ((var) = CIRCLEQ_FIRST(head); \
554 (var) != CIRCLEQ_END(head) && \
555 ((tvar) = CIRCLEQ_NEXT(var, field), 1); \
556 (var) = (tvar))
557
558 #define CIRCLEQ_FOREACH_REVERSE_SAFE(var, head, headname, field, tvar) \
559 for ((var) = CIRCLEQ_LAST(head, headname); \
560 (var) != CIRCLEQ_END(head) && \
561 ((tvar) = CIRCLEQ_PREV(var, headname, field), 1); \
562 (var) = (tvar))
563
552564 #endif /* !_SYS_QUEUE_H_ */
663663 }
664664 const char *value = json_string_value(varg);
665665
666 SCLogNotice("dataset-add: %s type %s value %s", set_name, type, value);
666 SCLogDebug("dataset-add: %s type %s value %s", set_name, type, value);
667667
668668 enum DatasetTypes t = DatasetGetTypeFromString(type);
669 if (t == DATASET_TYPE_NOTSET) {
670 json_object_set_new(answer, "message", json_string("unknown settype"));
671 return TM_ECODE_FAILED;
672 }
669673
670674 Dataset *set = DatasetFind(set_name, t);
671675 if (set == NULL) {
682686 return TM_ECODE_OK;
683687 } else {
684688 json_object_set_new(answer, "message", json_string("failed to add data"));
689 return TM_ECODE_FAILED;
690 }
691 }
692
693 TmEcode UnixSocketDatasetRemove(json_t *cmd, json_t* answer, void *data)
694 {
695 /* 1 get dataset name */
696 json_t *narg = json_object_get(cmd, "setname");
697 if (!json_is_string(narg)) {
698 json_object_set_new(answer, "message", json_string("setname is not a string"));
699 return TM_ECODE_FAILED;
700 }
701 const char *set_name = json_string_value(narg);
702
703 /* 2 get the data type */
704 json_t *targ = json_object_get(cmd, "settype");
705 if (!json_is_string(targ)) {
706 json_object_set_new(answer, "message", json_string("settype is not a string"));
707 return TM_ECODE_FAILED;
708 }
709 const char *type = json_string_value(targ);
710
711 /* 3 get value */
712 json_t *varg = json_object_get(cmd, "datavalue");
713 if (!json_is_string(varg)) {
714 json_object_set_new(answer, "message", json_string("datavalue is not string"));
715 return TM_ECODE_FAILED;
716 }
717 const char *value = json_string_value(varg);
718
719 SCLogDebug("dataset-remove: %s type %s value %s", set_name, type, value);
720
721 enum DatasetTypes t = DatasetGetTypeFromString(type);
722 if (t == DATASET_TYPE_NOTSET) {
723 json_object_set_new(answer, "message", json_string("unknown settype"));
724 return TM_ECODE_FAILED;
725 }
726
727 Dataset *set = DatasetFind(set_name, t);
728 if (set == NULL) {
729 json_object_set_new(answer, "message", json_string("set not found or wrong type"));
730 return TM_ECODE_FAILED;
731 }
732
733 int r = DatasetRemoveSerialized(set, value);
734 if (r == 1) {
735 json_object_set_new(answer, "message", json_string("data removed"));
736 return TM_ECODE_OK;
737 } else if (r == 0) {
738 json_object_set_new(answer, "message", json_string("data is busy, try again"));
739 return TM_ECODE_OK;
740 } else {
741 json_object_set_new(answer, "message", json_string("failed to remove data"));
685742 return TM_ECODE_FAILED;
686743 }
687744 }
3131
3232 #ifdef BUILD_UNIX_SOCKET
3333 TmEcode UnixSocketDatasetAdd(json_t *cmd, json_t* answer, void *data);
34 TmEcode UnixSocketDatasetRemove(json_t *cmd, json_t* answer, void *data);
3435 TmEcode UnixSocketRegisterTenantHandler(json_t *cmd, json_t* answer, void *data);
3536 TmEcode UnixSocketUnregisterTenantHandler(json_t *cmd, json_t* answer, void *data);
3637 TmEcode UnixSocketRegisterTenant(json_t *cmd, json_t* answer, void *data);
0 /* Copyright (C) 2010-2014 Open Information Security Foundation
0 /* Copyright (C) 2010-2020 Open Information Security Foundation
11 *
22 * You can copy, redistribute or modify this Program under the terms of
33 * the GNU General Public License version 2 as published by the Free
349349 if (top == NULL) {
350350 if (errno == EAGAIN) {
351351 if (dtv->dagstream & 0x1) {
352 TmThreadsCaptureHandleTimeout(tv, dtv->slot, NULL);
352353 usleep(10 * 1000);
353354 dtv->btm = dtv->top;
354355 }
431432
432433 /* Only support ethernet at this time. */
433434 switch (hdr_type & 0x7f) {
434 case TYPE_PAD:
435 case ERF_TYPE_PAD:
436 case ERF_TYPE_META:
435437 /* Skip. */
436438 continue;
437 case TYPE_DSM_COLOR_ETH:
438 case TYPE_COLOR_ETH:
439 case TYPE_COLOR_HASH_ETH:
439 case ERF_TYPE_DSM_COLOR_ETH:
440 case ERF_TYPE_COLOR_ETH:
441 case ERF_TYPE_COLOR_HASH_ETH:
440442 /* In these types the color value overwrites the lctr
441443 * (drop count). */
442444 break;
443 case TYPE_ETH:
445 case ERF_TYPE_ETH:
444446 if (dr->lctr) {
445447 StatsAddUI64(ewtn->tv, ewtn->drops, SCNtohs(dr->lctr));
446448 }
0 /* Copyright (C) 2012-2017 Open Information Security Foundation
0 /* Copyright (C) 2012-2020 Open Information Security Foundation
11 *
22 * You can copy, redistribute or modify this Program under the terms of
33 * the GNU General Public License version 2 as published by the Free
368368
369369 /* Napatech returns packets 1 at a time */
370370 status = NT_NetRxGet(ntv->rx_stream, &packet_buffer, 1000);
371 if (unlikely(status == NT_STATUS_TIMEOUT || status == NT_STATUS_TRYAGAIN)) {
371 if (unlikely(
372 status == NT_STATUS_TIMEOUT || status == NT_STATUS_TRYAGAIN)) {
373 if (status == NT_STATUS_TIMEOUT) {
374 TmThreadsCaptureHandleTimeout(tv, ntv->slot, NULL);
375 }
372376 continue;
373377 } else if (unlikely(status != NT_SUCCESS)) {
374378 NAPATECH_ERROR(SC_ERR_NAPATECH_OPEN_FAILED, status);
393397 switch (NT_NET_GET_PKT_TIMESTAMP_TYPE(packet_buffer)) {
394398 case NT_TIMESTAMP_TYPE_NATIVE_UNIX:
395399 p->ts.tv_sec = pkt_ts / 100000000;
396 p->ts.tv_usec = ((pkt_ts % 100000000) / 100) + (pkt_ts % 100) > 50 ? 1 : 0;
400 p->ts.tv_usec = ((pkt_ts % 100000000) / 100) + ((pkt_ts % 100) > 50 ? 1 : 0);
397401 break;
398402 case NT_TIMESTAMP_TYPE_PCAP:
399403 p->ts.tv_sec = pkt_ts >> 32;
401405 break;
402406 case NT_TIMESTAMP_TYPE_PCAP_NANOTIME:
403407 p->ts.tv_sec = pkt_ts >> 32;
404 p->ts.tv_usec = ( (pkt_ts & 0xFFFFFFFF) / 1000)
405 + (pkt_ts % 1000) > 500 ? 1 : 0;
408 p->ts.tv_usec = ((pkt_ts & 0xFFFFFFFF) / 1000) + ((pkt_ts % 1000) > 500 ? 1 : 0);
406409 break;
407410 case NT_TIMESTAMP_TYPE_NATIVE_NDIS:
408411 /* number of seconds between 1/1/1601 and 1/1/1970 */
409412 p->ts.tv_sec = (pkt_ts / 100000000) - 11644473600;
410 p->ts.tv_usec = ( (pkt_ts % 100000000) / 100)
411 + (pkt_ts % 100) > 50 ? 1 : 0;
413 p->ts.tv_usec = ((pkt_ts % 100000000) / 100) + ((pkt_ts % 100) > 50 ? 1 : 0);
412414 break;
413415 default:
414416 SCLogError(SC_ERR_NAPATECH_TIMESTAMP_TYPE_NOT_SUPPORTED,
118118 TmEcode PcapFileDispatch(PcapFileFileVars *ptv)
119119 {
120120 SCEnter();
121
122 /* initialize all the threads initial timestamp */
123 if (likely(ptv->first_pkt_hdr != NULL)) {
124 TmThreadsInitThreadsTimestamp(&ptv->first_pkt_ts);
125 PcapFileCallbackLoop((char *)ptv, ptv->first_pkt_hdr, (u_char *)ptv->first_pkt_data);
126 ptv->first_pkt_hdr = NULL;
127 ptv->first_pkt_data = NULL;
128 }
121129
122130 int packet_q_len = 64;
123131 int r;
159167 SCReturnInt(loop_result);
160168 }
161169
170 /** \internal
171 * \brief get the timestamp of the first packet and rewind
172 * \retval bool true on success, false on error
173 */
174 static bool PeekFirstPacketTimestamp(PcapFileFileVars *pfv)
175 {
176 int r = pcap_next_ex(pfv->pcap_handle, &pfv->first_pkt_hdr, &pfv->first_pkt_data);
177 if (r <= 0 || pfv->first_pkt_hdr == NULL) {
178 SCLogError(SC_ERR_PCAP_OPEN_OFFLINE,
179 "failed to get first packet timestamp. pcap_next_ex(): %d", r);
180 return false;
181 }
182 pfv->first_pkt_ts.tv_sec = pfv->first_pkt_hdr->ts.tv_sec;
183 pfv->first_pkt_ts.tv_usec = pfv->first_pkt_hdr->ts.tv_usec;
184 return true;
185 }
186
162187 TmEcode InitPcapFile(PcapFileFileVars *pfv)
163188 {
164189 char errbuf[PCAP_ERRBUF_SIZE] = "";
195220 pfv->datalink = pcap_datalink(pfv->pcap_handle);
196221 SCLogDebug("datalink %" PRId32 "", pfv->datalink);
197222
223 if (!PeekFirstPacketTimestamp(pfv))
224 SCReturnInt(TM_ECODE_FAILED);
225
198226 DecoderFunc temp;
199227 TmEcode validated = ValidateLinkType(pfv->datalink, &temp);
200228 SCReturnInt(validated);
201229 }
202230
203 TmEcode ValidateLinkType(int datalink, DecoderFunc *decoder)
231 TmEcode ValidateLinkType(int datalink, DecoderFunc *DecoderFn)
204232 {
205233 switch (datalink) {
206234 case LINKTYPE_LINUX_SLL:
207 *decoder = DecodeSll;
235 *DecoderFn = DecodeSll;
208236 break;
209237 case LINKTYPE_ETHERNET:
210 *decoder = DecodeEthernet;
238 *DecoderFn = DecodeEthernet;
211239 break;
212240 case LINKTYPE_PPP:
213 *decoder = DecodePPP;
241 *DecoderFn = DecodePPP;
214242 break;
215243 case LINKTYPE_IPV4:
216244 case LINKTYPE_RAW:
217245 case LINKTYPE_RAW2:
218246 case LINKTYPE_GRE_OVER_IP:
219 *decoder = DecodeRaw;
247 *DecoderFn = DecodeRaw;
220248 break;
221249 case LINKTYPE_NULL:
222 *decoder = DecodeNull;
250 *DecoderFn = DecodeNull;
223251 break;
224252
225253 default:
226 SCLogError(
227 SC_ERR_UNIMPLEMENTED,
228 "datalink type %" PRId32 " not (yet) supported in module PcapFile.",
229 datalink
230 );
254 SCLogError(SC_ERR_UNIMPLEMENTED,
255 "datalink type %"PRId32" not (yet) supported in module PcapFile.",
256 datalink);
231257 SCReturnInt(TM_ECODE_FAILED);
232258 }
233259
0 /* Copyright (C) 2007-2010 Open Information Security Foundation
0 /* Copyright (C) 2007-2020 Open Information Security Foundation
11 *
22 * You can copy, redistribute or modify this Program under the terms of
33 * the GNU General Public License version 2 as published by the Free
7373 struct bpf_program filter;
7474
7575 PcapFileSharedVars *shared;
76
77 /* fields used to get the first packets timestamp early,
78 * so it can be used to setup the time subsys. */
79 const u_char *first_pkt_data;
80 struct pcap_pkthdr *first_pkt_hdr;
81 struct timeval first_pkt_ts;
7682 } PcapFileFileVars;
7783
7884 /**
8888 #define STREAM_SEQ_RIGHT_EDGE(stream) (stream)->segs_right_edge
8989 #define STREAM_RIGHT_EDGE(stream) (STREAM_BASE_OFFSET((stream)) + (STREAM_SEQ_RIGHT_EDGE((stream)) - (stream)->base_seq))
9090 /* return true if we have seen data segments. */
91 #define STREAM_HAS_SEEN_DATA(stream) (!RB_EMPTY(&(stream)->sb.sbb_tree) || (stream)->sb.stream_offset)
91 #define STREAM_HAS_SEEN_DATA(stream) (!RB_EMPTY(&(stream)->sb.sbb_tree) || (stream)->sb.stream_offset || (stream)->sb.buf_offset)
9292
9393 typedef struct TcpStream_ {
9494 uint16_t flags:12; /**< Flag specific to the stream e.g. Timestamp */
641641 TCP_SEG_LEN(seg) = size;
642642 seg->seq = TCP_GET_SEQ(p);
643643
644 /* HACK: for TFO SYN packets the seq for data starts at + 1 */
645 if (TCP_HAS_TFO(p) && p->payload_len && p->tcph->th_flags == TH_SYN)
646 seg->seq += 1;
647
644648 /* proto detection skipped, but now we do get data. Set event. */
645649 if (RB_EMPTY(&stream->seg_tree) &&
646650 stream->flags & STREAMTCP_STREAM_FLAG_APPPROTO_DETECTION_SKIPPED) {
657661 }
658662
659663 static uint8_t StreamGetAppLayerFlags(TcpSession *ssn, TcpStream *stream,
660 Packet *p, enum StreamUpdateDir dir)
664 Packet *p)
661665 {
662666 uint8_t flag = 0;
663667
677681 flag |= STREAM_EOF;
678682 }
679683
680 if (dir == UPDATE_DIR_OPPOSING) {
681 if (p->flowflags & FLOW_PKT_TOSERVER) {
682 flag |= STREAM_TOCLIENT;
683 } else {
684 flag |= STREAM_TOSERVER;
685 }
684 if (&ssn->client == stream) {
685 flag |= STREAM_TOSERVER;
686686 } else {
687 if (p->flowflags & FLOW_PKT_TOSERVER) {
688 flag |= STREAM_TOSERVER;
689 } else {
690 flag |= STREAM_TOCLIENT;
691 }
692 }
693
687 flag |= STREAM_TOCLIENT;
688 }
694689 if (stream->flags & STREAMTCP_STREAM_FLAG_DEPTH_REACHED) {
695690 flag |= STREAM_DEPTH;
696691 }
10281023
10291024 int r = AppLayerHandleTCPData(tv, ra_ctx, p, p->flow, ssn, stream,
10301025 NULL, mydata_len,
1031 StreamGetAppLayerFlags(ssn, *stream, p, dir)|STREAM_GAP);
1026 StreamGetAppLayerFlags(ssn, *stream, p)|STREAM_GAP);
10321027 AppLayerProfilingStore(ra_ctx->app_tctx, p);
10331028
10341029 StreamTcpSetEvent(p, STREAM_REASSEMBLY_SEQ_GAP);
10861081 /* update the app-layer */
10871082 (void)AppLayerHandleTCPData(tv, ra_ctx, p, p->flow, ssn, stream,
10881083 (uint8_t *)mydata, mydata_len,
1089 StreamGetAppLayerFlags(ssn, *stream, p, dir));
1084 StreamGetAppLayerFlags(ssn, *stream, p));
10901085 AppLayerProfilingStore(ra_ctx->app_tctx, p);
10911086
10921087 SCReturnInt(0);
11331128 /* send EOF to app layer */
11341129 AppLayerHandleTCPData(tv, ra_ctx, p, p->flow, ssn, &stream,
11351130 NULL, 0,
1136 StreamGetAppLayerFlags(ssn, stream, p, dir));
1131 StreamGetAppLayerFlags(ssn, stream, p));
11371132 AppLayerProfilingStore(ra_ctx->app_tctx, p);
11381133
11391134 SCReturnInt(0);
496496
497497 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof(arr[0]))
498498
499 #ifndef NAME_MAX
500 #define NAME_MAX 255
501 #endif
502
499503 #endif /* __SURICATA_COMMON_H__ */
500504
10431043 #else
10441044 g_detect_disabled = suri->disabled_detect = 0;
10451045 #endif
1046 }
1047
1048 const char *GetDocURL(void)
1049 {
1050 const char *prog_ver = GetProgramVersion();
1051 if (strstr(prog_ver, "RELEASE") != NULL) {
1052 return DOC_URL "suricata-" PROG_VER;
1053 }
1054 return DOC_URL "latest";
10461055 }
10471056
10481057 /** \brief get string with program version
8383 #define DEFAULT_PID_FILENAME DEFAULT_PID_DIR DEFAULT_PID_BASENAME
8484
8585 #define DOC_URL "https://suricata.readthedocs.io/en/"
86
87 #if defined RELEASE
88 #define DOC_VERSION "suricata-" PROG_VER
89 #else
90 #define DOC_VERSION "latest"
91 #endif
86 const char *GetDocURL(void);
9287
9388 /* runtime engine control flags */
9489 #define SURICATA_STOP (1 << 0) /**< gracefully stop the engine: process all
3939 TEST_FAIL("AA");
4040 TEST_FAIL("5A");
4141 TEST_FAIL("A5");
42 TEST_FAIL("10000000001");
43 TEST_OK(" 1000000001 ", DETECT_BSIZE_EQ, 1000000001, 0);
4244 PASS;
4345 }
4446
22702270 int type;
22712271 int in_use; /**< bool to indicate this is in use */
22722272
2273 struct timeval ts; /**< current time of this thread (offline mode) */
2273 struct timeval pktts; /**< current packet time of this thread
2274 * (offline mode) */
2275 uint32_t sys_sec_stamp; /**< timestamp in seconds of the real system
2276 * time when the pktts was last updated. */
22742277 } Thread;
22752278
22762279 typedef struct Threads_ {
23872390 SCMutexUnlock(&thread_store_lock);
23882391 }
23892392
2393 #define COPY_TIMESTAMP(src,dst) ((dst)->tv_sec = (src)->tv_sec, (dst)->tv_usec = (src)->tv_usec) // XXX unify with flow-util.h
23902394 void TmThreadsSetThreadTimestamp(const int id, const struct timeval *ts)
23912395 {
23922396 SCMutexLock(&thread_store_lock);
23972401
23982402 int idx = id - 1;
23992403 Thread *t = &thread_store.threads[idx];
2400 t->ts.tv_sec = ts->tv_sec;
2401 t->ts.tv_usec = ts->tv_usec;
2404 COPY_TIMESTAMP(ts, &t->pktts);
2405 struct timeval systs;
2406 gettimeofday(&systs, NULL);
2407 t->sys_sec_stamp = (uint32_t)systs.tv_sec;
24022408 SCMutexUnlock(&thread_store_lock);
24032409 }
24042410
2405 #define COPY_TIMESTAMP(src,dst) ((dst)->tv_sec = (src)->tv_sec, (dst)->tv_usec = (src)->tv_usec) // XXX unify with flow-util.h
2406 void TmreadsGetMinimalTimestamp(struct timeval *ts)
2411 bool TmThreadsTimeSubsysIsReady(void)
2412 {
2413 bool ready = true;
2414 SCMutexLock(&thread_store_lock);
2415 for (size_t s = 0; s < thread_store.threads_size; s++) {
2416 Thread *t = &thread_store.threads[s];
2417 if (!t->in_use)
2418 break;
2419 if (t->sys_sec_stamp == 0) {
2420 ready = false;
2421 break;
2422 }
2423 }
2424 SCMutexUnlock(&thread_store_lock);
2425 return ready;
2426 }
2427
2428 void TmThreadsInitThreadsTimestamp(const struct timeval *ts)
2429 {
2430 struct timeval systs;
2431 gettimeofday(&systs, NULL);
2432 SCMutexLock(&thread_store_lock);
2433 for (size_t s = 0; s < thread_store.threads_size; s++) {
2434 Thread *t = &thread_store.threads[s];
2435 if (!t->in_use)
2436 break;
2437 COPY_TIMESTAMP(ts, &t->pktts);
2438 t->sys_sec_stamp = (uint32_t)systs.tv_sec;
2439 }
2440 SCMutexUnlock(&thread_store_lock);
2441 }
2442
2443 void TmThreadsGetMinimalTimestamp(struct timeval *ts)
24072444 {
24082445 struct timeval local, nullts;
24092446 memset(&local, 0, sizeof(local));
24102447 memset(&nullts, 0, sizeof(nullts));
24112448 int set = 0;
24122449 size_t s;
2450 struct timeval systs;
2451 gettimeofday(&systs, NULL);
24132452
24142453 SCMutexLock(&thread_store_lock);
24152454 for (s = 0; s < thread_store.threads_size; s++) {
24162455 Thread *t = &thread_store.threads[s];
2417 if (t == NULL || t->in_use == 0)
2418 continue;
2419 if (!(timercmp(&t->ts, &nullts, ==))) {
2456 if (t->in_use == 0)
2457 break;
2458 if (!(timercmp(&t->pktts, &nullts, ==))) {
2459 /* ignore sleeping threads */
2460 if (t->sys_sec_stamp + 1 < (uint32_t)systs.tv_sec)
2461 continue;
2462
24202463 if (!set) {
2421 local.tv_sec = t->ts.tv_sec;
2422 local.tv_usec = t->ts.tv_usec;
2464 local.tv_sec = t->pktts.tv_sec;
2465 local.tv_usec = t->pktts.tv_usec;
24232466 set = 1;
24242467 } else {
2425 if (timercmp(&t->ts, &local, <)) {
2426 COPY_TIMESTAMP(&t->ts, &local);
2468 if (timercmp(&t->pktts, &local, <)) {
2469 COPY_TIMESTAMP(&t->pktts, &local);
24272470 }
24282471 }
24292472 }
284284 void TmThreadsUnregisterThread(const int id);
285285 int TmThreadsInjectPacketsById(Packet **, int id);
286286
287 void TmThreadsInitThreadsTimestamp(const struct timeval *ts);
287288 void TmThreadsSetThreadTimestamp(const int id, const struct timeval *ts);
288 void TmreadsGetMinimalTimestamp(struct timeval *ts);
289 void TmThreadsGetMinimalTimestamp(struct timeval *ts);
290 bool TmThreadsTimeSubsysIsReady(void);
289291
290292 #endif /* __TM_THREADS_H__ */
10821082 UnixManagerRegisterCommand("memcap-list", UnixSocketShowAllMemcap, NULL, 0);
10831083
10841084 UnixManagerRegisterCommand("dataset-add", UnixSocketDatasetAdd, &command, UNIX_CMD_TAKE_ARGS);
1085 UnixManagerRegisterCommand("dataset-remove", UnixSocketDatasetRemove, &command, UNIX_CMD_TAKE_ARGS);
10851086
10861087 return 0;
10871088 }
7373 size_t size = strlen(name) + 1;
7474 char tmp[size];
7575 strlcpy(tmp, name, size);
76 if (tmp[size - 2] == '/')
76 if (size > 2 && tmp[size - 2] == '/') // > 2 to allow just /
7777 tmp[size - 2] = '\0';
7878
7979 return ConfSetFinal("default-data-dir", tmp) ? TM_ECODE_OK : TM_ECODE_FAILED;
0 /* Copyright (C) 2007-2010 Open Information Security Foundation
0 /* Copyright (C) 2007-2020 Open Information Security Foundation
11 *
22 * You can copy, redistribute or modify this Program under the terms of
33 * the GNU General Public License version 2 as published by the Free
932932 return;
933933 }
934934
935 static inline const char *SCLogGetDefaultLogFormat(void)
936 {
937 const char *prog_ver = GetProgramVersion();
938 if (strstr(prog_ver, "RELEASE") != NULL) {
939 return SC_LOG_DEF_LOG_FORMAT_REL;
940 }
941 return SC_LOG_DEF_LOG_FORMAT_DEV;
942 }
943
935944 /**
936945 * \brief Internal function used to set the logging module global_log_format
937946 * during the initialization phase
953962
954963 /* deal with the global log format to be used */
955964 if (format == NULL || strlen(format) > SC_LOG_MAX_LOG_FORMAT_LEN) {
956 format = SC_LOG_DEF_LOG_FORMAT;
965 format = SCLogGetDefaultLogFormat();
957966 #ifndef UNITTESTS
958967 if (sc_lid != NULL) {
959968 printf("Warning: Invalid/No global_log_format supplied by user or format "
13251334 }
13261335
13271336 if (ConfGet("logging.default-log-format", &sc_lid->global_log_format) != 1)
1328 sc_lid->global_log_format = SC_LOG_DEF_LOG_FORMAT;
1337 sc_lid->global_log_format = SCLogGetDefaultLogFormat();
13291338
13301339 (void)ConfGet("logging.default-output-filter", &sc_lid->op_filter);
13311340
15131522 FAIL_IF_NOT(sc_log_config->op_ifaces != NULL &&
15141523 SC_LOG_DEF_LOG_OP_IFACE == sc_log_config->op_ifaces->iface);
15151524 FAIL_IF_NOT(sc_log_config->log_format != NULL &&
1516 strcmp(SC_LOG_DEF_LOG_FORMAT, sc_log_config->log_format) == 0);
1525 strcmp(SCLogGetDefaultLogFormat(), sc_log_config->log_format) == 0);
15171526
15181527 SCLogDeInitLogModule();
15191528
15671576 sc_log_config->op_ifaces->next != NULL &&
15681577 SC_LOG_OP_IFACE_CONSOLE == sc_log_config->op_ifaces->next->iface);
15691578 FAIL_IF_NOT(sc_log_config->log_format != NULL &&
1570 strcmp(SC_LOG_DEF_LOG_FORMAT, sc_log_config->log_format) == 0);
1579 strcmp(SCLogGetDefaultLogFormat(), sc_log_config->log_format) == 0);
15711580 FAIL_IF_NOT(sc_log_config->op_ifaces != NULL &&
15721581 sc_log_config->op_ifaces->log_format != NULL &&
15731582 strcmp("%m - %d", sc_log_config->op_ifaces->log_format) == 0);
7979 } SCLogOPType;
8080
8181 /* The default log_format, if it is not supplied by the user */
82 #ifdef RELEASE
83 #define SC_LOG_DEF_LOG_FORMAT "%t - <%d> - "
84 #else
85 #define SC_LOG_DEF_LOG_FORMAT "[%i] %t - (%f:%l) <%d> (%n) -- "
86 #endif
82 #define SC_LOG_DEF_LOG_FORMAT_REL "%t - <%d> - "
83 #define SC_LOG_DEF_LOG_FORMAT_DEV "[%i] %t - (%f:%l) <%d> (%n) -- "
8784
8885 /* The maximum length of the log message */
8986 #define SC_LOG_MAX_LOG_MSG_LEN 2048
00 /* Copyright (C) 2012 BAE Systems
1 * Copyright (C) 2020 Open Information Security Foundation
12 *
23 * You can copy, redistribute or modify this Program under the terms of
34 * the GNU General Public License version 2 as published by the Free
18291830 * \param search_start The start of the search (ie. boundary=\")
18301831 * \param search_end The end of the search (ie. \")
18311832 * \param tlen The output length of the token (if found)
1833 * \param max_len The maximum offset in which to search
1834 * \param toolong Set if the field value was truncated to max_len.
1835 *
1836 * \return A pointer to the token if found, otherwise NULL if not found
1837 */
1838 static uint8_t * FindMimeHeaderTokenRestrict(MimeDecField *field, const char *search_start,
1839 const char *search_end, uint32_t *tlen, uint32_t max_len, bool *toolong)
1840 {
1841 uint8_t *fptr, *tptr = NULL, *tok = NULL;
1842
1843 if (toolong)
1844 *toolong = false;
1845
1846 SCLogDebug("Looking for token: %s", search_start);
1847
1848 /* Check for token definition */
1849 size_t ss_len = strlen(search_start);
1850 fptr = FindBuffer(field->value, field->value_len, (const uint8_t *)search_start, ss_len);
1851 if (fptr != NULL) {
1852 fptr += ss_len; /* Start at end of start string */
1853 uint32_t offset = fptr - field->value;
1854 if (offset > field->value_len) {
1855 return tok;
1856 }
1857 tok = GetToken(fptr, field->value_len - offset, search_end, &tptr, tlen);
1858 if (tok == NULL) {
1859 return tok;
1860 }
1861 SCLogDebug("Found mime token");
1862
1863 /* Compare the actual token length against the maximum */
1864 if (toolong && max_len && *tlen > max_len) {
1865 SCLogDebug("Token length %d exceeds length restriction %d; truncating", *tlen, max_len);
1866 *toolong = true;
1867 *tlen = max_len;
1868 }
1869 }
1870
1871 return tok;
1872 }
1873
1874 /**
1875 * \brief Finds a mime header token within the specified field
1876 *
1877 * \param field The current field
1878 * \param search_start The start of the search (ie. boundary=\")
1879 * \param search_end The end of the search (ie. \")
1880 * \param tlen The output length of the token (if found)
18321881 *
18331882 * \return A pointer to the token if found, otherwise NULL if not found
18341883 */
18351884 static uint8_t * FindMimeHeaderToken(MimeDecField *field, const char *search_start,
18361885 const char *search_end, uint32_t *tlen)
18371886 {
1838 uint8_t *fptr, *tptr = NULL, *tok = NULL;
1839
1840 SCLogDebug("Looking for token: %s", search_start);
1841
1842 /* Check for token definition */
1843 fptr = FindBuffer(field->value, field->value_len, (const uint8_t *)search_start, strlen(search_start));
1844 if (fptr != NULL) {
1845 fptr += strlen(search_start); /* Start at end of start string */
1846 tok = GetToken(fptr, field->value_len - (fptr - field->value), search_end,
1847 &tptr, tlen);
1848 if (tok != NULL) {
1849 SCLogDebug("Found mime token");
1850 }
1851 }
1852
1853 return tok;
1887 return FindMimeHeaderTokenRestrict(field, search_start, search_end, tlen, 0, NULL);
18541888 }
18551889
18561890 /**
18981932 /* Check for file attachment in content disposition */
18991933 field = MimeDecFindField(entity, CTNT_DISP_STR);
19001934 if (field != NULL) {
1901 bptr = FindMimeHeaderToken(field, "filename=", TOK_END_STR, &blen);
1935 bool truncated_name = false;
1936 bptr = FindMimeHeaderTokenRestrict(field, "filename=", TOK_END_STR, &blen, NAME_MAX, &truncated_name);
19021937 if (bptr != NULL) {
19031938 SCLogDebug("File attachment found in disposition");
19041939 entity->ctnt_flags |= CTNT_IS_ATTACHMENT;
19111946 }
19121947 memcpy(entity->filename, bptr, blen);
19131948 entity->filename_len = blen;
1949
1950 if (truncated_name) {
1951 state->stack->top->data->anomaly_flags |= ANOM_LONG_FILENAME;
1952 state->msg->anomaly_flags |= ANOM_LONG_FILENAME;
1953 }
19141954 }
19151955 }
19161956
19401980
19411981 /* Look for file name (if not already found) */
19421982 if (!(entity->ctnt_flags & CTNT_IS_ATTACHMENT)) {
1943 bptr = FindMimeHeaderToken(field, "name=", TOK_END_STR, &blen);
1983 bool truncated_name = false;
1984 bptr = FindMimeHeaderTokenRestrict(field, "name=", TOK_END_STR, &blen, NAME_MAX, &truncated_name);
19441985 if (bptr != NULL) {
19451986 SCLogDebug("File attachment found");
19461987 entity->ctnt_flags |= CTNT_IS_ATTACHMENT;
19531994 }
19541995 memcpy(entity->filename, bptr, blen);
19551996 entity->filename_len = blen;
1997
1998 if (truncated_name) {
1999 state->stack->top->data->anomaly_flags |= ANOM_LONG_FILENAME;
2000 state->msg->anomaly_flags |= ANOM_LONG_FILENAME;
2001 }
19562002 }
19572003 }
19582004
30343080 }
30353081 #undef TEST
30363082
3083 static int MimeDecParseLongFilename01(void)
3084 {
3085 /* contains 276 character filename -- length restricted to 255 chars */
3086 char mimemsg[] = "Content-Disposition: attachment; filename=\""
3087 "12characters12characters12characters12characters"
3088 "12characters12characters12characters12characters"
3089 "12characters12characters12characters12characters"
3090 "12characters12characters12characters12characters"
3091 "12characters12characters12characters12characters"
3092 "12characters12characters12characters.exe\"";
3093
3094 uint32_t line_count = 0;
3095
3096 MimeDecGetConfig()->decode_base64 = 1;
3097 MimeDecGetConfig()->decode_quoted_printable = 1;
3098 MimeDecGetConfig()->extract_urls = 1;
3099
3100 /* Init parser */
3101 MimeDecParseState *state = MimeDecInitParser(&line_count,
3102 TestDataChunkCallback);
3103
3104 const char *str = "From: Sender1";
3105 FAIL_IF_NOT(MIME_DEC_OK == MimeDecParseLine((uint8_t *)str, strlen(str), 1, state));
3106
3107 str = "To: Recipient1";
3108 FAIL_IF_NOT(MIME_DEC_OK == MimeDecParseLine((uint8_t *)str, strlen(str), 1, state));
3109
3110 str = "Content-Type: text/plain";
3111 FAIL_IF_NOT(MIME_DEC_OK == MimeDecParseLine((uint8_t *)str, strlen(str), 1, state));
3112
3113 /* Contains 276 character filename */
3114 FAIL_IF_NOT(MIME_DEC_OK == MimeDecParseLine((uint8_t *)mimemsg, strlen(mimemsg), 1, state));
3115
3116 str = "";
3117 FAIL_IF_NOT(MIME_DEC_OK == MimeDecParseLine((uint8_t *)str, strlen(str), 1, state));
3118
3119 str = "A simple message line 1";
3120 FAIL_IF_NOT(MIME_DEC_OK == MimeDecParseLine((uint8_t *)str, strlen(str), 1, state));
3121
3122 /* Completed */
3123 FAIL_IF_NOT(MIME_DEC_OK == MimeDecParseComplete(state));
3124
3125 MimeDecEntity *msg = state->msg;
3126 FAIL_IF_NOT(msg);
3127
3128 FAIL_IF_NOT(msg->anomaly_flags & ANOM_LONG_FILENAME);
3129 FAIL_IF_NOT(msg->filename_len == NAME_MAX);
3130
3131 MimeDecFreeEntity(msg);
3132
3133 /* De Init parser */
3134 MimeDecDeInitParser(state);
3135
3136 PASS;
3137 }
3138
3139 static int MimeDecParseLongFilename02(void)
3140 {
3141 /* contains 40 character filename and 500+ characters following filename */
3142 char mimemsg[] = "Content-Disposition: attachment; filename=\""
3143 "12characters12characters12characters.exe\"; "
3144 "somejunkasfdasfsafasafdsasdasassdssdsd"
3145 "somejunkasfdasfsafasafdsasdasassdssdsd"
3146 "somejunkasfdasfsafasafdsasdasassdssdsd"
3147 "somejunkasfdasfsafasafdsasdasassdssdsd"
3148 "somejunkasfdasfsafasafdsasdasassdssdsd"
3149 "somejunkasfdasfsafasafdsasdasassdssdsd"
3150 "somejunkasfdasfsafasafdsasdasassdssdsd"
3151 "somejunkasfdasfsafasafdsasdasassdssdsd"
3152 "somejunkasfdasfsafasafdsasdasassdssdsd"
3153 "somejunkasfdasfsafasafdsasdasassdssdsd"
3154 "somejunkasfdasfsafasafdsasdasassdssdsd"
3155 "somejunkasfdasfsafasafdsasdasassdssdsd"
3156 "somejunkasfdasfsafasafdsasdasassdssdsd";
3157
3158 uint32_t line_count = 0;
3159
3160 MimeDecGetConfig()->decode_base64 = 1;
3161 MimeDecGetConfig()->decode_quoted_printable = 1;
3162 MimeDecGetConfig()->extract_urls = 1;
3163
3164 /* Init parser */
3165 MimeDecParseState *state = MimeDecInitParser(&line_count,
3166 TestDataChunkCallback);
3167
3168 const char *str = "From: Sender1";
3169 FAIL_IF_NOT(MIME_DEC_OK == MimeDecParseLine((uint8_t *)str, strlen(str), 1, state));
3170
3171 str = "To: Recipient1";
3172 FAIL_IF_NOT(MIME_DEC_OK == MimeDecParseLine((uint8_t *)str, strlen(str), 1, state));
3173
3174 str = "Content-Type: text/plain";
3175 FAIL_IF_NOT(MIME_DEC_OK == MimeDecParseLine((uint8_t *)str, strlen(str), 1, state));
3176
3177 /* Contains 40 character filename */
3178 FAIL_IF_NOT(MIME_DEC_OK == MimeDecParseLine((uint8_t *)mimemsg, strlen(mimemsg), 1, state));
3179
3180 str = "";
3181 FAIL_IF_NOT(MIME_DEC_OK == MimeDecParseLine((uint8_t *)str, strlen(str), 1, state));
3182
3183 str = "A simple message line 1";
3184 FAIL_IF_NOT(MIME_DEC_OK == MimeDecParseLine((uint8_t *)str, strlen(str), 1, state));
3185
3186 /* Completed */
3187 FAIL_IF_NOT(MIME_DEC_OK == MimeDecParseComplete(state));
3188
3189 MimeDecEntity *msg = state->msg;
3190 FAIL_IF_NOT(msg);
3191
3192 /* filename is not too long */
3193 FAIL_IF(msg->anomaly_flags & ANOM_LONG_FILENAME);
3194
3195 MimeDecFreeEntity(msg);
3196
3197 /* De Init parser */
3198 MimeDecDeInitParser(state);
3199
3200 PASS;
3201 }
3202
30373203 #endif /* UNITTESTS */
30383204
30393205 void MimeDecRegisterTests(void)
30473213 UtRegisterTest("MimeIsExeURLTest01", MimeIsExeURLTest01);
30483214 UtRegisterTest("MimeIsIpv4HostTest01", MimeIsIpv4HostTest01);
30493215 UtRegisterTest("MimeIsIpv6HostTest01", MimeIsIpv6HostTest01);
3216 UtRegisterTest("MimeDecParseLongFilename01", MimeDecParseLongFilename01);
3217 UtRegisterTest("MimeDecParseLongFilename02", MimeDecParseLongFilename02);
30503218 #endif /* UNITTESTS */
30513219 }
5151
5252 /* Anomaly Flags */
5353 #define ANOM_INVALID_BASE64 1 /* invalid base64 chars */
54 #define ANOM_INVALID_QP 2 /* invalid qouted-printable chars */
54 #define ANOM_INVALID_QP 2 /* invalid quoted-printable chars */
5555 #define ANOM_LONG_HEADER_NAME 4 /* header is abnormally long */
5656 #define ANOM_LONG_HEADER_VALUE 8 /* header value is abnormally long
5757 * (includes multi-line) */
5959 #define ANOM_LONG_ENC_LINE 32 /* Lines that exceed 76 octets */
6060 #define ANOM_MALFORMED_MSG 64 /* Misc msg format errors found */
6161 #define ANOM_LONG_BOUNDARY 128 /* Boundary too long */
62 #define ANOM_LONG_FILENAME 256 /* filename truncated */
6263
6364 /* Publicly exposed size constants */
6465 #define DATA_CHUNK_SIZE 3072 /* Should be divisible by 3 */
4444 CASE_CODE (SC_ERR_ACTION_ORDER);
4545 CASE_CODE (SC_ERR_PCRE_MATCH);
4646 CASE_CODE (SC_ERR_PCRE_GET_SUBSTRING);
47 CASE_CODE (SC_ERR_PCRE_COPY_SUBSTRING);
4748 CASE_CODE (SC_ERR_PCRE_COMPILE);
4849 CASE_CODE (SC_ERR_PCRE_STUDY);
4950 CASE_CODE (SC_ERR_PCRE_PARSE);
354354 SC_ERR_DATASET,
355355 SC_WARN_ANOMALY_CONFIG,
356356 SC_WARN_ALERT_CONFIG,
357 SC_ERR_PCRE_COPY_SUBSTRING,
357358
358359 SC_ERR_MAX
359360 } SCError;
203203 #define GET_VAR(prefix,name) \
204204 snprintf(varname, sizeof(varname), "%s.%s", (prefix), (name))
205205
206 static void THashConfigValidate(const char *confvalue, const char *varname)
207 {
208 for (size_t i = 0; i < strlen(confvalue); i++) {
209 if (!isdigit(confvalue[i])) {
210 FatalError(SC_ERR_SIZE_PARSE, "Error parsing %s "
211 "from key %s. Killing Engine",
212 confvalue, varname);
213 }
214 }
215 }
216
206217 /** \brief initialize the configuration
207218 * \warning Not thread safe */
208219 static void THashInitConfig(THashTableContext *ctx, const char *cnf_prefix)
229240 GET_VAR(cnf_prefix, "hash-size");
230241 if ((ConfGet(varname, &conf_val)) == 1)
231242 {
243 /* validate hash-size value is a numerical value */
244 THashConfigValidate(conf_val, varname);
245
232246 if (ByteExtractStringUint32(&configval, 10, strlen(conf_val),
233247 conf_val) > 0) {
234248 ctx->config.hash_size = configval;
238252 GET_VAR(cnf_prefix, "prealloc");
239253 if ((ConfGet(varname, &conf_val)) == 1)
240254 {
255 /* validate prealloc value is a numerical value */
256 THashConfigValidate(conf_val, varname);
257
241258 if (ByteExtractStringUint32(&configval, 10, strlen(conf_val),
242259 conf_val) > 0) {
243260 ctx->config.prealloc = configval;
743760
744761 return NULL;
745762 }
763
764 /**
765 * \retval int -1 not found
766 * \retval int 0 found, but it was busy (ref cnt)
767 * \retval int 1 found and removed */
768 int THashRemoveFromHash (THashTableContext *ctx, void *data)
769 {
770 /* get the key to our bucket */
771 uint32_t key = THashGetKey(&ctx->config, data);
772 /* get our hash bucket and lock it */
773 THashHashRow *hb = &ctx->array[key];
774
775 HRLOCK_LOCK(hb);
776 THashData *h = hb->head;
777 while (h != NULL) {
778 /* see if this is the data we are looking for */
779 if (THashCompare(&ctx->config, h->data, data) == 0) {
780 h = h->next;
781 continue;
782 }
783
784 SCMutexLock(&h->m);
785 if (SC_ATOMIC_GET(h->use_cnt) > 0) {
786 SCMutexUnlock(&h->m);
787 HRLOCK_UNLOCK(hb);
788 return 0;
789 }
790
791 /* remove from the hash */
792 if (h->prev != NULL)
793 h->prev->next = h->next;
794 if (h->next != NULL)
795 h->next->prev = h->prev;
796 if (hb->head == h)
797 hb->head = h->next;
798 if (hb->tail == h)
799 hb->tail = h->prev;
800
801 h->next = NULL;
802 h->prev = NULL;
803 SCMutexUnlock(&h->m);
804 HRLOCK_UNLOCK(hb);
805 THashDataFree(ctx, h);
806 SCLogDebug("found and removed");
807 return 1;
808 }
809
810 HRLOCK_UNLOCK(hb);
811 SCLogDebug("data not found");
812 return -1;
813 }
210210 THashDataQueue *THashDataQueueNew(void);
211211 void THashCleanup(THashTableContext *ctx);
212212 int THashWalk(THashTableContext *, THashFormatFunc, THashOutputFunc, void *);
213 int THashRemoveFromHash (THashTableContext *ctx, void *data);
213214
214215 #endif /* __THASH_H__ */
6868 #endif
6969 //static SCMutex current_time_mutex = SCMUTEX_INITIALIZER;
7070 static SCSpinlock current_time_spinlock;
71 static char live = TRUE;
71 static bool live_time_tracking = true;
7272
7373 struct tm *SCLocalTime(time_t timep, struct tm *result);
7474 struct tm *SCUtcTime(time_t timep, struct tm *result);
8686 SCSpinDestroy(&current_time_spinlock);
8787 }
8888
89 bool TimeModeIsReady(void)
90 {
91 if (live_time_tracking)
92 return true;
93 return TmThreadsTimeSubsysIsReady();
94 }
95
8996 void TimeModeSetLive(void)
9097 {
91 live = TRUE;
98 live_time_tracking = true;
9299 SCLogDebug("live time mode enabled");
93100 }
94101
95102 void TimeModeSetOffline (void)
96103 {
97 live = FALSE;
104 live_time_tracking = false;
98105 SCLogDebug("offline time mode enabled");
99106 }
100107
101 int TimeModeIsLive(void)
102 {
103 return live;
108 bool TimeModeIsLive(void)
109 {
110 return live_time_tracking;
104111 }
105112
106113 void TimeSetByThread(const int thread_id, const struct timeval *tv)
107114 {
108 if (live == TRUE)
115 if (live_time_tracking)
109116 return;
110117
111118 TmThreadsSetThreadTimestamp(thread_id, tv);
114121 #ifdef UNITTESTS
115122 void TimeSet(struct timeval *tv)
116123 {
117 if (live == TRUE)
124 if (live_time_tracking)
118125 return;
119126
120127 if (tv == NULL)
147154 if (tv == NULL)
148155 return;
149156
150 if (live == TRUE) {
157 if (live_time_tracking) {
151158 gettimeofday(tv, NULL);
152159 } else {
153160 #ifdef UNITTESTS
158165 SCSpinUnlock(&current_time_spinlock);
159166 } else {
160167 #endif
161 TmreadsGetMinimalTimestamp(tv);
168 TmThreadsGetMinimalTimestamp(tv);
162169 #ifdef UNITTESTS
163170 }
164171 #endif
2323 #ifndef __UTIL_TIME_H__
2424 #define __UTIL_TIME_H__
2525
26 /**
27 * A timeval with 32 bit fields.
28 *
29 * Used by the unified on disk file format.
30 */
31 typedef struct SCTimeval32_ {
32 uint32_t tv_sec;
33 uint32_t tv_usec;
34 } SCTimeval32;
35
3626 void TimeInit(void);
3727 void TimeDeinit(void);
3828
4838 void TimeSetIncrementTime(uint32_t);
4939 #endif
5040
41 bool TimeModeIsReady(void);
5142 void TimeModeSetLive(void);
5243 void TimeModeSetOffline (void);
53 int TimeModeIsLive(void);
44 bool TimeModeIsLive(void);
5445
5546 struct tm *SCLocalTime(time_t timep, struct tm *result);
5647 void CreateTimeString(const struct timeval *ts, char *str, size_t size);
11
22 python:
33 - "2.7"
4 - "3.4"
54 - "3.5"
65 - "3.6"
76
00 # Change Log
1
2 ## 1.1.2 - 2020-04-17
3 - Better error on bad modify filter:
4 https://redmine.openinfosecfoundation.org/issues/3536
5 - Optimization for modify filters:
6 https://redmine.openinfosecfoundation.org/issues/3620
17
28 ## 1.1.1 - 2019-12-11
39 - If Suricata is less than 5, and Rust is not enabled, disable
121121 am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP)
122122 am__DIST_COMMON = $(srcdir)/Makefile.in
123123 DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
124 ACLOCAL = ${SHELL} /tmp/suricata-1581591507/missing aclocal-1.15
124 ACLOCAL = ${SHELL} /tmp/suricata-1588068380/missing aclocal-1.15
125125 AMTAR = $${TAR-tar}
126126 AM_DEFAULT_VERBOSITY = 0
127127 AR = ar
128 AUTOCONF = ${SHELL} /tmp/suricata-1581591507/missing autoconf
129 AUTOHEADER = ${SHELL} /tmp/suricata-1581591507/missing autoheader
130 AUTOMAKE = ${SHELL} /tmp/suricata-1581591507/missing automake-1.15
128 AUTOCONF = ${SHELL} /tmp/suricata-1588068380/missing autoconf
129 AUTOHEADER = ${SHELL} /tmp/suricata-1588068380/missing autoheader
130 AUTOMAKE = ${SHELL} /tmp/suricata-1588068380/missing automake-1.15
131131 AWK = gawk
132132 CARGO = /home/victor/.cargo/bin//cargo
133133 CARGO_HOME =
134134 CC = gcc
135135 CCDEPMODE = depmode=gcc3
136136 CFLAGS = -g -O2 -march=native -I${srcdir}/../rust/gen/c-headers
137 CLANG = /usr/bin/clang
137 CLANG = /usr/local/bin/clang
138138 CLANG_CFLAGS =
139139 CONFIGURE_DATAROOTDIR = /usr/local/share
140140 CONFIGURE_LOCALSTATEDIR = /usr/local/var
141141 CONFIGURE_PREFIX = /usr/local
142142 CONFIGURE_SYSCONDIR = /usr/local/etc
143143 CPP = gcc -E
144 CPPFLAGS = -I${srcdir}/../libhtp/ -I/usr/include/nspr -I/usr/include/nss -I/usr/include/nspr
144 CPPFLAGS = -I${srcdir}/../libhtp/ -I/usr/local/include/hs -I/usr/include/nspr -I/usr/include/nss -I/usr/include/nspr
145145 CYGPATH_W = echo
146146 DEFS = -DHAVE_CONFIG_H
147147 DEPDIR = .deps
190190 LIBPRELUDE_LIBS =
191191 LIBPRELUDE_PREFIX =
192192 LIBPRELUDE_PTHREAD_CFLAGS =
193 LIBS = -lmagic -lcap-ng -lpcap -lnet -ljansson -lpthread -lyaml -lpcre -lz -lplds4 -lplc4 -lnspr4 -lnss3 -lnssutil3 -lsmime3 -lssl3 -lplds4 -lplc4 -lnspr4
193 LIBS = -lmagic -lcap-ng -lpcap -lnet -ljansson -lpthread -lyaml -lhs -lpcre -lz -L/usr/local/lib -lhs -lplds4 -lplc4 -lnspr4 -lnss3 -lnssutil3 -lsmime3 -lssl3 -lplds4 -lplc4 -lnspr4
194194 LIBTOOL = $(SHELL) $(top_builddir)/libtool
195195 LIPO =
196196 LLC =
202202 LUA_CFLAGS =
203203 LUA_INT8 =
204204 LUA_LIBS =
205 MAKEINFO = ${SHELL} /tmp/suricata-1581591507/missing makeinfo
205 MAKEINFO = ${SHELL} /tmp/suricata-1588068380/missing makeinfo
206206 MANIFEST_TOOL = :
207207 MKDIR_P = /bin/mkdir -p
208208 NM = /usr/bin/nm -B
215215 PACKAGE = suricata
216216 PACKAGE_BUGREPORT =
217217 PACKAGE_NAME = suricata
218 PACKAGE_STRING = suricata 5.0.2
218 PACKAGE_STRING = suricata 5.0.3
219219 PACKAGE_TARNAME = suricata
220220 PACKAGE_URL =
221 PACKAGE_VERSION = 5.0.2
221 PACKAGE_VERSION = 5.0.3
222222 PATH_SEPARATOR = :
223223 PCAP_CFLAGS = -I/usr/include
224224 PCAP_LIBS =
238238 SHELL = /bin/bash
239239 STRIP = strip
240240 SURICATA_UPDATE_DIR = suricata-update
241 VERSION = 5.0.2
242 abs_builddir = /tmp/suricata-1581591507/suricata-update
243 abs_srcdir = /tmp/suricata-1581591507/suricata-update
244 abs_top_builddir = /tmp/suricata-1581591507
245 abs_top_srcdir = /tmp/suricata-1581591507
241 VERSION = 5.0.3
242 abs_builddir = /tmp/suricata-1588068380/suricata-update
243 abs_srcdir = /tmp/suricata-1588068380/suricata-update
244 abs_top_builddir = /tmp/suricata-1588068380
245 abs_top_srcdir = /tmp/suricata-1588068380
246246 ac_ct_AR = ar
247247 ac_ct_CC = gcc
248248 ac_ct_DUMPBIN =
272272 e_magic_file =
273273 e_magic_file_comment = #
274274 e_rundir = /usr/local/var/run/
275 e_rustdir = /tmp/suricata-1581591507/rust
275 e_rustdir = /tmp/suricata-1588068380/rust
276276 e_sysconfdir = /usr/local/etc/suricata/
277277 exec_prefix = ${prefix}
278278 have_cargo_vendor_bin =
285285 htmldir = ${docdir}
286286 includedir = ${prefix}/include
287287 infodir = ${datarootdir}/info
288 install_sh = ${SHELL} /tmp/suricata-1581591507/install-sh
288 install_sh = ${SHELL} /tmp/suricata-1588068380/install-sh
289289 libdir = ${exec_prefix}/lib
290290 libexecdir = ${exec_prefix}/libexec
291 libhs_CFLAGS =
292 libhs_LIBS =
291 libhs_CFLAGS = -I/usr/local/include/hs
292 libhs_LIBS = -L/usr/local/lib -lhs
293293 libhtp_CFLAGS =
294294 libhtp_LIBS =
295295 libnetfilter_queue_CFLAGS =
431431 maintainer-clean-generic:
432432 @echo "This command is intended for maintainers to use"
433433 @echo "it deletes files that may require special tools to rebuild."
434 #uninstall-local:
435 #uninstall-local:
436 #uninstall-local:
437 #distclean-local:
438 #distclean-local:
439 #distclean-local:
434440 #clean-local:
435441 #clean-local:
436442 #clean-local:
437 #distclean-local:
438 #distclean-local:
439 #distclean-local:
440 #uninstall-local:
441 #uninstall-local:
442 #uninstall-local:
443443 #install-exec-local:
444444 #install-exec-local:
445445 #install-exec-local:
431431 maintainer-clean-generic:
432432 @echo "This command is intended for maintainers to use"
433433 @echo "it deletes files that may require special tools to rebuild."
434 @HAVE_PYTHON_DISTUTILS_FALSE@uninstall-local:
435 @HAVE_PYTHON_FALSE@uninstall-local:
436 @HAVE_PYTHON_YAML_FALSE@uninstall-local:
437 @HAVE_PYTHON_DISTUTILS_FALSE@distclean-local:
438 @HAVE_PYTHON_FALSE@distclean-local:
439 @HAVE_PYTHON_YAML_FALSE@distclean-local:
434440 @HAVE_PYTHON_DISTUTILS_FALSE@clean-local:
435441 @HAVE_PYTHON_FALSE@clean-local:
436442 @HAVE_PYTHON_YAML_FALSE@clean-local:
437 @HAVE_PYTHON_DISTUTILS_FALSE@distclean-local:
438 @HAVE_PYTHON_FALSE@distclean-local:
439 @HAVE_PYTHON_YAML_FALSE@distclean-local:
440 @HAVE_PYTHON_DISTUTILS_FALSE@uninstall-local:
441 @HAVE_PYTHON_FALSE@uninstall-local:
442 @HAVE_PYTHON_YAML_FALSE@uninstall-local:
443443 @HAVE_PYTHON_DISTUTILS_FALSE@install-exec-local:
444444 @HAVE_PYTHON_FALSE@install-exec-local:
445445 @HAVE_PYTHON_YAML_FALSE@install-exec-local:
466466 line = line.rsplit(" #")[0]
467467
468468 line = re.sub(r'\\\$', '$', line) # needed to escape $ in pp
469 rule_filter = ModifyRuleFilter.parse(line)
470 if rule_filter:
471 filters.append(rule_filter)
472 else:
473 log.error("Failed to parse modify filter: %s" % (line))
469 try:
470 rule_filter = ModifyRuleFilter.parse(line)
471 if rule_filter:
472 filters.append(rule_filter)
473 except Exception as err:
474 raise exceptions.ApplicationError(
475 "Failed to parse modify filter: {}".format(line))
474476
475477 return filters
476478
14621464 rulemap[rule.id] = fltr.run(rule)
14631465 drop_count += 1
14641466
1465 # Apply modify filters.
1466 for fltr in modify_filters:
1467 for key, rule in rulemap.items():
1467 for fltr in modify_filters:
14681468 if fltr.match(rule):
14691469 new_rule = fltr.run(rule)
1470 if new_rule and new_rule.format() != rule.format():
1470 if new_rule:
14711471 rulemap[rule.id] = new_rule
14721472 modify_count += 1
14731473
33 # Alpha: 1.0.0a1
44 # Development: 1.0.0dev0
55 # Release candidate: 1.0.0rc1
6 version = "1.1.1"
6 version = "1.1.2"
33 # and then run "tox" from this directory.
44
55 [tox]
6 envlist = py27, py34, py35, py36, py37
6 envlist = py27, py35, py36, py37
77
88 [testenv]
99 commands = python ./tests/integration_tests.py
33 # and then run "tox" from this directory.
44
55 [tox]
6 envlist = py27, py34, py35, py36, py37
6 envlist = py27, py35, py36, py37
77
88 [testenv]
99 commands = pytest
4444 FILE_DATA_PORTS: "[$HTTP_PORTS,110,143]"
4545 FTP_PORTS: 21
4646 VXLAN_PORTS: 4789
47 TEREDO_PORTS: 3544
4748
4849 ##
4950 ## Step 2: select outputs to enable
13321333 # as it will sometimes detect non-teredo as teredo.
13331334 teredo:
13341335 enabled: true
1336 # ports to look for Teredo. Max 4 ports. If no ports are given, or
1337 # the value is set to 'any', Teredo detection runs on _all_ UDP packets.
1338 ports: $TEREDO_PORTS # syntax: '[3544, 1234]' or '3533' or 'any'.
1339
13351340 # VXLAN decoder is assigned to up to 4 UDP ports. By default only the
13361341 # IANA assigned port 4789 is enabled.
13371342 vxlan:
13381343 enabled: true
13391344 ports: $VXLAN_PORTS # syntax: '8472, 4789'
1345 # ERSPAN Type I decode support
1346 erspan:
1347 typeI:
1348 enabled: false
13401349
13411350
13421351 ##