Skip to content

Commit ed415d3

Browse files
dipeshwaliadehydr8
andauthored
fix: handle PREF_DECODE_AS_RANGE in wg_set_pref
* set pref failing for sip and diameter * empty commit * c-ares seems to be 404 * fix: handle PREF_DECODE_AS_RANGE in wg_set_pref --------- Co-authored-by: Osama Khalid <[email protected]>
1 parent 2c41246 commit ed415d3

File tree

4 files changed

+81
-1
lines changed

4 files changed

+81
-1
lines changed

lib/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ clean: mostlyclean
7373
# CARES
7474
#
7575
CARES_VERSION := 1.15.0
76-
CARES_URL := https://c-ares.org/download/c-ares-$(CARES_VERSION).tar.gz
76+
CARES_URL := https://github.com/c-ares/c-ares/releases/download/cares-$(subst .,_,$(CARES_VERSION))/c-ares-$(CARES_VERSION).tar.gz
7777
CARES_CHECKSUM := a1de6c5e7e1a6a13c926aae690e83d5caa51e7313d63da1cf2af6bc757c41d585aad5466bc3ba7b7f7793cb1748fa589f40972b196728851c8b059cfc8c3be50
7878

7979
$(TARBALLS)/c-ares-$(CARES_VERSION).tar.gz:

lib/wiregasm/wiregasm.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,45 @@ SetPrefResponse wg_set_pref(string module_name, string pref_name, string value)
309309
{
310310
SetPrefResponse res;
311311

312+
module_t *mod = prefs_find_module(module_name.c_str());
313+
pref_t *p = prefs_find_preference(mod, pref_name.c_str());
314+
315+
if (p == NULL)
316+
{
317+
res.code = -1;
318+
res.error = "Preference not found";
319+
return res;
320+
}
321+
322+
int type = prefs_get_type(p);
323+
324+
// handle decode as range ourselves
325+
if (type == PREF_DECODE_AS_RANGE) {
326+
range_t *new_range = NULL;
327+
convert_ret_t ret = range_convert_str(NULL, &new_range, value.c_str(), prefs_get_max_value(p));
328+
329+
if (ret != CVT_NO_ERROR) {
330+
res.code = -1;
331+
res.error = "Invalid range";
332+
return res;
333+
}
334+
335+
if (prefs_set_range_value(p, new_range, pref_stashed)) {
336+
pref_unstash_data_t unstashed_data;
337+
338+
unstashed_data.module = mod;
339+
unstashed_data.handle_decode_as = true;
340+
341+
pref_unstash(p, &unstashed_data);
342+
prefs_apply(mod);
343+
}
344+
345+
res.code = 0;
346+
return res;
347+
}
348+
349+
// use prefs_set_pref for all other types for now
350+
312351
char pref[4096];
313352
prefs_set_pref_e ret;
314353
char *errmsg = NULL;

samples/diameter_non_standard.pcap

672 Bytes
Binary file not shown.

src/index.test.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,47 @@ describe("Wiregasm Library - Set Preferences", () => {
271271
expect(pref2.type).toBe(PrefType.PREF_DECODE_AS_RANGE);
272272
expect(pref2.range_value).toBe("8001");
273273
});
274+
275+
test("set preferences works for diameter", async () => {
276+
277+
const pref = wg.get_pref("diameter", "tcp.port");
278+
expect(pref.type).toBe(PrefType.PREF_DECODE_AS_RANGE);
279+
expect(pref.range_value).toBe(
280+
"3868"
281+
);
282+
283+
wg.set_pref("diameter", "tcp.port", "3871");
284+
285+
const pref2 = wg.get_pref("diameter", "tcp.port");
286+
expect(pref2.type).toBe(PrefType.PREF_DECODE_AS_RANGE);
287+
expect(pref2.range_value).toBe("3871");
288+
289+
const data = await fs.readFile("samples/diameter_non_standard.pcap");
290+
const ret = wg.load("diameter_non_standard.pcap", data);
291+
292+
expect(ret.code).toEqual(0);
293+
294+
const frame = wg.frame(1);
295+
const last_tree = frame.tree.get(frame.tree.size() - 1);
296+
297+
expect(last_tree.label).toBe("Diameter Protocol");
298+
});
299+
300+
test("set preferences works for sip", async () => {
301+
const pref = wg.get_pref("sip", "tcp.port");
302+
expect(pref.type).toBe(PrefType.PREF_DECODE_AS_RANGE);
303+
expect(pref.range_value).toBe(
304+
"5060"
305+
);
306+
307+
wg.set_pref("sip", "tcp.port", "8001");
308+
309+
const pref2 = wg.get_pref("sip", "tcp.port");
310+
expect(pref2.type).toBe(PrefType.PREF_DECODE_AS_RANGE);
311+
expect(pref2.range_value).toBe("8001");
312+
});
313+
314+
274315
});
275316

276317
describe("Wiregasm Library - nghttp2", () => {

0 commit comments

Comments
 (0)