[Swan] converting Pluto externs to file-statics, and more
D. Hugh Redelmeier
hugh at mimosa.com
Wed Jan 8 05:33:06 EET 2014
I don't know as much as I should of the structure of the Libreswan
source code. I think that there is a lot of junk DNA there.
One goal I have is to reduce the scope of variables and functions.
Today, I'm trying to convert externals to file-statics if they are not
used outside the file in which they are defined.
That's kind of laborious to do by hand: an awful lot of grepping. So
I'm using the compiler to help.
I've not built a script to do this, but here are the commands that I
used.
make clean programs
Build the userland .o files
find . -name '*.o' -print | while read x ; do nm "$x" | sed -n 's/^ [A-Z] //p' ; done | sort -u >imports
For each object file, list the imports, and sort them into an
alphabetic list with duplicates removed, putting the result in the
file "imports".
find . -name '*.o' -print | while read x ; do nm "$x" | sed -n 's/^[0-9a-f]............... [A-Z] //p' ; done | sort -u >exports
Similarly, create an alphabetic list of exports,
with duplicates removed, putting the result in the file "exports"
comm -23 exports imports
List all the exports that are not imported.
This gives me a large list of candidates to examine.
- I mostly ignored code used by KLIPS since I didn't have .o files for
KLIPS. And I don't understand how it all fits together
- I ignored code that had been copied into libreswan (e.g. zlib and
DES)
- I ignored generic library routines like atodata etc.
- I was fairly circumspect of things in parsers since I didn't know if
yacc or lex generated code would use them.
The compiler warns about unused file-statics but doesn't know to warn
about unused externs. So by making unimported things file-static, I
enabled the compiler to warned about unused things.
I deleted most things that were not used at all.
I left a few that I imagine maybe should have been used.
Questions:
==========
It looks as if programs/pluto/stubs.c is pointless. Can we delete it?
It looks as if a number of files are not compiled. Should these be
deleted?
programs/spi/spi.c
programs/addconn/addconn.c
programs/readwriteconf/readwriteconf.c
programs/showhostkey/showhostkey.c
These important-looking functions are not used. Should they be?
linux/net/ipsec/pfkey_v2_parser.c:3561:int pfkey_build_reply(struct sadb_msg *pfkey_msg,
programs/pf_key/pf_key.c:296: pfkey_print(msg, stdout);
programs/pluto/state.c:363:void rehash_state(struct state *st)
programs/pluto/state.c:883:void rekey_p2states_by_connection(struct connection *c)
programs/pluto/state.c:1879:void replace_states_by_peer(const ip_address *peer)
lib/libswan/certload.c:202:bool same_cert(const cert_t *a, const cert_t *b)
lib/libswan/udpfromto.c:186:int sendfromto(int s, void *buf, size_t len, int flags,
programs/pluto/kernel.c:3049:bool update_ipsec_sa(struct state *st USED_BY_KLIPS)
delete_p2states_by_connection
get_x509cert
get_x509_private_key
ikev2_acceptable_group
kernel_alg_esp_sadb_alg
Some things are only used by files that are not compiled. Should they
too be deleted? For example, these are used by spi.c
kernel_alg_proc_read
kernel_alg_sadb_alg_get
These kernel externs appear pointless (a very small sample of the odd
code):
linux/net/ipsec/radij.c:464:unsigned char *dumper;
modobj/radij.c:464:unsigned char *dumper;
linux/net/ipsec/radij.c:465:int dumper_len;
modobj/radij.c:465:int dumper_len;
More information about the Swan
mailing list