mnl: Remove dead code
Phil Sutter
reviewerPATCH 1/1 mnl: Remove dead code
Remove the functions mnl_nft_rule_add() and *_delete() since they are not used throughout the code. Commit a72315d2bad47 ("src: add rule batching support") changed their only caller to use the batch variant introduced at the same time.
--- include/mnl.h | 4 ---- src/mnl.c | 28 ---------------------------- 2 files changed, 32 deletions(-)
include/mnl.h +0 -4
@@ -33,10 +33,6 @@ int mnl_nft_rule_batch_del(struct nftnl_rule *nlr, struct nftnl_batch *batch,int mnl_nft_rule_batch_replace (struct nftnl_rule *nlr,struct nftnl_batch *batch,unsigned int flags,uint32_t seqnum); -int mnl_nft_rule_add (struct mnl_socket *nf_sock,struct nftnl_rule *r, -unsigned int flags); -int mnl_nft_rule_delete (struct mnl_socket *nf_sock,struct nftnl_rule *r, -unsigned int flags);struct nftnl_rule_list *mnl_nft_rule_dump (struct mnl_socket *nf_sock,int family);
src/mnl.c +0 -28
@@ -339,34 +339,6 @@ int mnl_nft_rule_batch_del(struct nftnl_rule *nlr, struct nftnl_batch *batch,/* * Rule */ -int mnl_nft_rule_add (struct mnl_socket *nf_sock,struct nftnl_rule *nlr, -unsigned int flags) -{ -char buf[MNL_SOCKET_BUFFER_SIZE ]; -struct nlmsghdr *nlh; - - nlh =nftnl_nlmsg_build_hdr (buf,NFT_MSG_NEWRULE , -nftnl_rule_get_u32 (nlr,NFTNL_RULE_FAMILY ), -NLM_F_ACK |NLM_F_CREATE | flags, seq); -nftnl_rule_nlmsg_build_payload (nlh, nlr); - -return nft_mnl_talk (nf_sock, nlh, nlh->nlmsg_len,NULL ,NULL ); -} - -int mnl_nft_rule_delete (struct mnl_socket *nf_sock,struct nftnl_rule *nlr, -unsigned int flags) -{ -char buf[MNL_SOCKET_BUFFER_SIZE ]; -struct nlmsghdr *nlh; - - nlh =nftnl_nlmsg_build_hdr (buf,NFT_MSG_DELRULE , -nftnl_rule_get_u32 (nlr,NFTNL_RULE_FAMILY ), -NLM_F_ACK , seq); -nftnl_rule_nlmsg_build_payload (nlh, nlr); - -return nft_mnl_talk (nf_sock, nlh, nlh->nlmsg_len,NULL ,NULL ); -} -static int rule_cb (const struct nlmsghdr *nlh,void *data) {struct nftnl_rule_list *nlr_list = data;
Signature · 1 line
2.13.1
Pablo Neira Ayuso
maintainerCc'ing Pablo Bermudo.
Quoted 4 lines · Phil Sutter
Remove the functions
mnl_nft_rule_add()and*_delete()since they are not used throughout the code. Commita72315d2bad47("src: add rule batching support") changed their only caller to use the batch variant introduced at the same time.
I think there are more useless functions. Pablo Bermudo mentioned this to me a while ago. At least I remember some of them in netlink.c?
If not much asking, it would be good if we can kill them all in one go.
2017-07-27 10:46 GMT+02:00 Pablo Neira Ayuso <[email protected]>:
Quoted 8 lines
Cc'ing Pablo Bermudo.
Quoted 4 lines · Phil Sutter
Remove the functions
mnl_nft_rule_add()and*_delete()since they are not used throughout the code. Commita72315d2bad47("src: add rule batching support") changed their only caller to use the batch variant introduced at the same time.
Quoted 4 lines
I think there are more useless functions. Pablo Bermudo mentioned this to me a while ago. At least I remember some of them in
netlink.c?If not much asking, it would be good if we can kill them all in one go.
I am using a combination of compiler and linker options in order to obtain a list of unused functions:
$ make -j5 CFLAGS="-ffunction-sections -fdata-sections -Wl,--gc-sections,--print-gc-sections"
You can find more information about --gc-sections and its pitfalls here [1]. The listing is printed on stderr by --print-gc-sections and it looks like this:
/usr/bin/ld: Removing unused section '.text.xt_stmt_xlate' in file 'statement.o' /usr/bin/ld: Removing unused section '.text.xt_stmt_release' in file 'statement.o'/usr/bin/ld: Removing unused section '.text.xt_stmt_print' in file 'statement.o'
...
There is also a small utility called callcatcher [2], written by LibreOffice developer Caolán McNamara. But it seems not to be recursive, so unused functions invoked from other unused functions are not shown until the callers are deleted.
The complete list contains some functions that I think are not worth removing, because are part of a "consolidated API" (e.g. those related to the implementation of the red–black tree). A bunch of unused functions are from the auto-generated file scanner.c.
The current list is attached.
--
[1] http://elinux.org/images/2/2d/ELC2010-gc-sections_Denys_Vlasenko.pdf
[2] http://www.skynet.ie/~caolan/Packages/callcatcher.html