• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

OISF / suricata / 23225337378

18 Mar 2026 01:52AM UTC coverage: 79.323%. First build
23225337378

Pull #15048

github

web-flow
Merge 66b63c09c into e9f8e17b1
Pull Request #15048: rust: format all the rust - v6

3059 of 5090 new or added lines in 86 files covered. (60.1%)

266907 of 336483 relevant lines covered (79.32%)

4583399.41 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

74.75
/rust/src/dns/lua.rs
1
/* Copyright (C) 2017 Open Information Security Foundation
2
 *
3
 * You can copy, redistribute or modify this Program under the terms of
4
 * the GNU General Public License version 2 as published by the Free
5
 * Software Foundation.
6
 *
7
 * This program is distributed in the hope that it will be useful,
8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 * GNU General Public License for more details.
11
 *
12
 * You should have received a copy of the GNU General Public License
13
 * version 2 along with this program; if not, write to the Free Software
14
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
15
 * 02110-1301, USA.
16
 */
17

18
use std::os::raw::c_int;
19

20
use crate::dns::dns::*;
21
use crate::dns::log::*;
22
use crate::lua::*;
23

24
#[no_mangle]
25
pub extern "C" fn SCDnsLuaGetTxId(clua: &mut CLuaState, tx: &mut DNSTransaction) -> c_int {
12✔
26
    let lua = LuaState { lua: clua };
12✔
27

12✔
28
    lua.pushinteger(tx.tx_id() as i64);
12✔
29
    return 1;
12✔
30
}
12✔
31

32
#[no_mangle]
33
pub extern "C" fn SCDnsLuaGetRrname(clua: &mut CLuaState, tx: &mut DNSTransaction) -> c_int {
89✔
34
    let lua = LuaState { lua: clua };
89✔
35

36
    if let Some(request) = &tx.request {
89✔
37
        if let Some(query) = request.queries.first() {
88✔
38
            lua.pushstring(&String::from_utf8_lossy(&query.name.value));
88✔
39
            return 1;
88✔
40
        }
×
41
    } else if let Some(response) = &tx.response {
1✔
42
        if let Some(query) = response.queries.first() {
1✔
43
            lua.pushstring(&String::from_utf8_lossy(&query.name.value));
1✔
44
            return 1;
1✔
45
        }
×
46
    }
×
47

48
    return 0;
×
49
}
89✔
50

51
#[no_mangle]
52
pub extern "C" fn SCDnsLuaGetRcode(clua: &mut CLuaState, tx: &mut DNSTransaction) -> c_int {
1✔
53
    let lua = LuaState { lua: clua };
1✔
54
    lua.pushinteger(tx.rcode() as i64);
1✔
55
    return 1;
1✔
56
}
1✔
57

58
#[no_mangle]
59
pub extern "C" fn SCDnsLuaGetRcodeString(clua: &mut CLuaState, tx: &mut DNSTransaction) -> c_int {
11✔
60
    let lua = LuaState { lua: clua };
11✔
61
    lua.pushstring(&dns_rcode_string(tx.rcode()));
11✔
62
    return 1;
11✔
63
}
11✔
64

65
#[no_mangle]
66
pub extern "C" fn SCDnsLuaGetQueryTable(clua: &mut CLuaState, tx: &mut DNSTransaction) -> c_int {
16✔
67
    let lua = LuaState { lua: clua };
16✔
68

16✔
69
    let mut i: i64 = 0;
16✔
70

16✔
71
    // Create table now to be consistent with C that always returns
16✔
72
    // table even in the absence of any authorities.
16✔
73
    lua.newtable();
16✔
74

75
    // We first look in the request for queries. However, if there is
76
    // no request, check the response for queries.
77
    if let Some(request) = &tx.request {
16✔
78
        for query in &request.queries {
16✔
79
            lua.pushinteger(i);
8✔
80
            i += 1;
8✔
81

8✔
82
            lua.newtable();
8✔
83

8✔
84
            lua.pushstring("type");
8✔
85
            lua.pushstring(&dns_rrtype_string(query.rrtype));
8✔
86
            lua.settable(-3);
8✔
87

8✔
88
            lua.pushstring("rrname");
8✔
89
            lua.pushstring(&String::from_utf8_lossy(&query.name.value));
8✔
90
            lua.settable(-3);
8✔
91

8✔
92
            lua.settable(-3);
8✔
93
        }
8✔
94
    } else if let Some(response) = &tx.response {
8✔
95
        for query in &response.queries {
16✔
96
            lua.pushinteger(i);
8✔
97
            i += 1;
8✔
98

8✔
99
            lua.newtable();
8✔
100

8✔
101
            lua.pushstring("type");
8✔
102
            lua.pushstring(&dns_rrtype_string(query.rrtype));
8✔
103
            lua.settable(-3);
8✔
104

8✔
105
            lua.pushstring("rrname");
8✔
106
            lua.pushstring(&String::from_utf8_lossy(&query.name.value));
8✔
107
            lua.settable(-3);
8✔
108

8✔
109
            lua.settable(-3);
8✔
110
        }
8✔
111
    }
×
112

113
    // Again, always return 1 to be consistent with C, even if the
114
    // table is empty.
115
    return 1;
16✔
116
}
16✔
117

118
#[no_mangle]
119
pub extern "C" fn SCDnsLuaGetAnswerTable(clua: &mut CLuaState, tx: &mut DNSTransaction) -> c_int {
12✔
120
    let lua = LuaState { lua: clua };
12✔
121

12✔
122
    let mut i: i64 = 0;
12✔
123

12✔
124
    // Create table now to be consistent with C that always returns
12✔
125
    // table even in the absence of any authorities.
12✔
126
    lua.newtable();
12✔
127

128
    if let Some(response) = &tx.response {
12✔
129
        for answer in &response.answers {
14✔
130
            lua.pushinteger(i);
8✔
131
            i += 1;
8✔
132

8✔
133
            lua.newtable();
8✔
134
            lua.pushstring("type");
8✔
135
            lua.pushstring(&dns_rrtype_string(answer.rrtype));
8✔
136
            lua.settable(-3);
8✔
137

8✔
138
            lua.pushstring("ttl");
8✔
139
            lua.pushinteger(answer.ttl as i64);
8✔
140
            lua.settable(-3);
8✔
141

8✔
142
            lua.pushstring("rrname");
8✔
143
            lua.pushstring(&String::from_utf8_lossy(&answer.name.value));
8✔
144
            lua.settable(-3);
8✔
145

8✔
146
            // All rdata types are pushed to "addr" for backwards compatibility
8✔
147
            match &answer.data {
8✔
148
                DNSRData::A(ref bytes) | DNSRData::AAAA(ref bytes) => {
6✔
149
                    if !bytes.is_empty() {
6✔
150
                        lua.pushstring("addr");
6✔
151
                        lua.pushstring(&dns_print_addr(bytes));
6✔
152
                        lua.settable(-3);
6✔
153
                    }
6✔
154
                }
155
                DNSRData::CNAME(name)
2✔
156
                | DNSRData::MX(name)
×
157
                | DNSRData::NS(name)
×
158
                | DNSRData::PTR(name) => {
×
159
                    if !name.value.is_empty() {
2✔
160
                        lua.pushstring("addr");
2✔
161
                        lua.pushstring(&String::from_utf8_lossy(&name.value));
2✔
162
                        lua.settable(-3);
2✔
163
                    }
2✔
164
                }
165
                DNSRData::TXT(ref txt) => {
×
166
                    if !txt.is_empty() {
×
167
                        lua.pushstring("addr");
×
168
                        let combined = txt
×
169
                            .iter()
×
170
                            .map(|s| String::from_utf8_lossy(s))
×
171
                            .collect::<Vec<_>>()
×
172
                            .join(" ");
×
173
                        lua.pushstring(&combined);
×
174
                        lua.settable(-3);
×
175
                    }
×
176
                }
NEW
177
                DNSRData::NULL(ref bytes) | DNSRData::Unknown(ref bytes) => {
×
178
                    if !bytes.is_empty() {
×
179
                        lua.pushstring("addr");
×
180
                        lua.pushstring(&String::from_utf8_lossy(bytes));
×
181
                        lua.settable(-3);
×
182
                    }
×
183
                }
184
                DNSRData::SOA(ref soa) => {
×
185
                    if !soa.mname.value.is_empty() {
×
186
                        lua.pushstring("addr");
×
187
                        lua.pushstring(&String::from_utf8_lossy(&soa.mname.value));
×
188
                        lua.settable(-3);
×
189
                    }
×
190
                }
191
                DNSRData::SSHFP(ref sshfp) => {
×
192
                    lua.pushstring("addr");
×
193
                    lua.pushstring(&String::from_utf8_lossy(&sshfp.fingerprint));
×
194
                    lua.settable(-3);
×
195
                }
×
196
                DNSRData::SRV(ref srv) => {
×
197
                    lua.pushstring("addr");
×
198
                    lua.pushstring(&String::from_utf8_lossy(&srv.target.value));
×
199
                    lua.settable(-3);
×
200
                }
×
201
                DNSRData::OPT(ref opt) => {
×
202
                    if !opt.is_empty() {
×
203
                        lua.pushstring("addr");
×
204
                        for option in opt.iter() {
×
205
                            lua.pushstring(&String::from_utf8_lossy(&option.code.to_be_bytes()));
×
206
                            lua.pushstring(&String::from_utf8_lossy(&option.data));
×
207
                        }
×
208
                        lua.settable(-3);
×
209
                    }
×
210
                }
211
            }
212
            lua.settable(-3);
8✔
213
        }
214
    }
6✔
215

216
    // Again, always return 1 to be consistent with C, even if the
217
    // table is empty.
218
    return 1;
12✔
219
}
12✔
220

221
#[no_mangle]
222
pub extern "C" fn SCDnsLuaGetAuthorityTable(
12✔
223
    clua: &mut CLuaState, tx: &mut DNSTransaction,
12✔
224
) -> c_int {
12✔
225
    let lua = LuaState { lua: clua };
12✔
226

12✔
227
    let mut i: i64 = 0;
12✔
228

12✔
229
    // Create table now to be consistent with C that always returns
12✔
230
    // table even in the absence of any authorities.
12✔
231
    lua.newtable();
12✔
232

233
    if let Some(response) = &tx.response {
12✔
234
        for answer in &response.authorities {
7✔
235
            lua.pushinteger(i);
1✔
236
            i += 1;
1✔
237

1✔
238
            lua.newtable();
1✔
239
            lua.pushstring("type");
1✔
240
            lua.pushstring(&dns_rrtype_string(answer.rrtype));
1✔
241
            lua.settable(-3);
1✔
242

1✔
243
            lua.pushstring("ttl");
1✔
244
            lua.pushinteger(answer.ttl as i64);
1✔
245
            lua.settable(-3);
1✔
246

1✔
247
            lua.pushstring("rrname");
1✔
248
            lua.pushstring(&String::from_utf8_lossy(&answer.name.value));
1✔
249
            lua.settable(-3);
1✔
250

1✔
251
            lua.settable(-3);
1✔
252
        }
1✔
253
    }
6✔
254

255
    // Again, always return 1 to be consistent with C, even if the
256
    // table is empty.
257
    return 1;
12✔
258
}
12✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc