KNET_HAN...LE_FILTER(3)
π knet_handle_enable_filter β from the Kronosnet Programmer's Manual π
okay bestie, sit down, hydrate, and let's talk about knet_handle_enable_filter(3) because this one is genuinely a glow-up. it's the page in the kronosnet section of the programmer's manual that teaches you how to install a filter so you get to decide where packets go. yes, you. main character energy.
β¨ NAME β¨
knet_handle_enable_filter β install a filter to route packets π
β¨ SYNOPSIS β¨
#include <libknet.h>
int knet_handle_enable_filter(
knet_handle_t knet_h,
void *dst_host_filter_fn_private_data,
int(*)(void *private_data, const unsigned char *outdata, ssize_t outdata_len, uint8_t tx_rx, knet_node_id_t this_host_id, knet_node_id_t src_host_id, int8_t *channel, knet_node_id_t *dst_host_ids, size_t *dst_host_ids_entries) dst_host_filter_fn
);
πΈ DESCRIPTION πΈ
so like. knet_handle_enable_filter is literally the function that lets you be the air traffic controller of your own packets. no cap.
here's the cast of characters, one by one, because they all matter:
knet_hβ pointer to aknet_handle_t. your handle. your baby. π«Άdst_host_filter_fn_private_dataβ avoidpointer to data that can be used to identify the callback. it's your little name tag so the callback knows who it is.dst_host_filter_fnβ THE callback function, and she is booked and busy: she gets invoked every single time a packet hitsdatafd(peepknet_handle_new(3)for the deets on that). the whole point of her is to let users tell libknet where the packet has to be delivered. she's the bouncer. she's the velvet rope. she decides. π
and here's what the callback actually receives, parameter by parameter:
const unsigned char *outdataβ a pointer to the current packet π¦ssize_t outdata_lenβ the length of the above datauint8_t tx_rxβ the filter is called on tx or rx (KNET_NOTIFY_TX,KNET_NOTIFY_RX)knet_node_id_t this_host_idβ thehost_idprocessing the packetknet_node_id_t src_host_idβ thehost_idthat generated the packetknet_node_id_t *dst_host_idsβ array ofKNET_MAX_HOSTknet_node_id_twhere to store the destinations (uninitialized by caller, callee should never read it) β οΈ yes, never read it. the caller leaves it messy on purpose, that's just how it is.size_t *dst_host_ids_entriesβ number of hosts to send the message
and now the moment you've been waiting for β what does the callback return? this part is important, bestie, write it on your hand:
-1β error, and the packet is discarded. it's giving π0β the packet is unicast and should be sent todst_host_ids, and there aredst_host_ids_entriesin the buffer. iconic, precise, focused.1β the packet is broadcast/multicast and is sent to all hosts. the contents ofdst_host_idsanddst_host_ids_entriesare ignored π so don't bother filling them in, she doesn't care.
π RETURN VALUE π
knet_handle_enable_filter returns 0 on success, -1 on error β and when it errors, errno is set. classic. always check your errno, bestie, she's trying to tell you something.
π¦ SEE ALSO π¦
the whole friend group showed up, and honestly? obsessed. go read these too:
knet_handle_remove_datafd(3)knet_handle_get_stats(3)knet_host_add(3)knet_handle_pmtud_setfreq(3)knet_handle_pmtud_get(3)knet_handle_crypto_use_config(3)knet_host_get_id_by_host_name(3)knet_host_get_status(3)knet_link_add_acl(3)knet_link_get_pong_count(3)knet_link_get_priority(3)knet_handle_free(3)knet_handle_enable_sock_notify(3)knet_handle_get_datafd(3)knet_recv(3)knet_link_get_ping_timers(3)knet_log_get_subsystem_id(3)knet_host_remove(3)knet_host_enable_status_change_notify(3)knet_strtoaddr(3)knet_link_rm_acl(3)knet_send(3)knet_handle_enable_pmtud_notify(3)knet_get_crypto_cipher_list(3)knet_handle_get_transport_reconnect_interval(3)knet_link_get_enable(3)knet_link_set_priority(3)knet_log_set_loglevel(3)knet_handle_get_channel(3)knet_link_get_config(3)knet_link_get_link_list(3)knet_get_crypto_hash_list(3)knet_get_transport_list(3)knet_get_transport_id_by_name(3)knet_log_get_loglevel_id(3)knet_handle_new_ex(3)knet_host_set_name(3)knet_addrtostr(3)knet_handle_setfwd(3)knet_get_compress_list(3)knet_host_set_policy(3)knet_get_transport_name_by_id(3)knet_handle_crypto_rx_clear_traffic(3)knet_handle_compress(3)knet_link_get_status(3)knet_handle_add_datafd(3)knet_send_sync(3)knet_log_get_loglevel_name(3)knet_handle_enable_access_lists(3)knet_host_get_host_list(3)knet_host_get_policy(3)knet_link_set_enable(3)knet_link_set_pong_count(3)knet_log_get_subsystem_name(3)knet_host_get_name_by_host_id(3)knet_link_clear_config(3)knet_log_get_loglevel(3)knet_handle_new(3)knet_handle_pmtud_getfreq(3)knet_handle_pmtud_set(3)knet_handle_clear_stats(3)knet_link_set_config(3)knet_handle_crypto_set_config(3)knet_handle_crypto(3)knet_get_crypto_list(3)knet_handle_set_transport_reconnect_interval(3)knet_link_clear_acl(3)knet_link_set_ping_timers(3)knet_handle_setprio_dscp(3)knet_link_insert_acl(3)
π COPYRIGHT π
Copyright (C) 2010-2026 Red Hat, Inc. All rights reserved.
and that's the whole page, bestie π go install that filter, route those packets, and remember: -1 means the packet is gone gone.
kronosnet Β· 2026-07-20 Β· KNET_HAN...LE_FILTER(3) β mwah, bye β¨ππ¦
π¦ where this page comes from
- fedora 43: libknet1-devel 1.35-1.fc43 Β· LGPL-2.1-or-later
- fedora 43: libknet1-devel 1.35-1.fc43 Β· LGPL-2.1-or-later
- fedora 44: libknet1-devel 1.35-1.fc44 Β· LGPL-2.1-or-later
- fedora 44: libknet1-devel 1.35-1.fc44 Β· LGPL-2.1-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms