Skip to content

Commit

Permalink
datapath: Check the export of public functions in linux/compat/linux/.
Browse files Browse the repository at this point in the history
This commit adds check in datapath/Makefile to make sure that all public
functions and exported symbols in linux/compat/ are either rpl_ or ovs_
prefixed, except those defined in compat/build-aux/export-check-whitelist.

Signed-off-by: Alex Wang <[email protected]>
Acked-by: Jesse Gross <[email protected]>
  • Loading branch information
yew011 committed Apr 26, 2015
1 parent bedf02f commit b296b82
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 1 deletion.
31 changes: 30 additions & 1 deletion datapath/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,33 @@ print-build-modules:
echo "Could not find any kernel module."; \
exit 1; \
fi
@echo "$(build_modules)" | tr '_' '-';
@echo "$(build_modules)" | tr '_' '-';

COMPAT_GET_FUNCTIONS := find $(top_srcdir)/datapath/linux/compat -name "*.h" \
-exec sed -n '/^[a-z][a-z]* \*\?[A-Za-z0-9_][A-Za-z0-9_]*([a-z]/p; /^struct [a-z0-9_][a-z0-9_]* \*\?[A-Za-z0-9_][A-Za-z0-9_]*([a-z]/p' {} \; | tr -d '*' | cut -d '(' -f1 | rev | cut -d ' ' -f1 | rev
COMPAT_GET_EXPORTS := find $(top_srcdir)/datapath/linux/compat -name "*.c" \
-exec sed -n 's/^EXPORT_SYMBOL[A-Z_]*(\([a-z_][a-z_]*\));$$/\1/p' {} \;
COMPAT_FUNCTIONS := $(shell $(COMPAT_GET_FUNCTIONS))
COMPAT_EXPORTS := $(shell $(COMPAT_GET_EXPORTS))

# Checks that all public functions are 'rpl_' or 'ovs_' prefixed.
# Checks that all EXPORT_SYMBOL_GPL() export 'rpl_' or 'ovs_' prefixed functions.
check-export-symbol:
@for fun_ in $(COMPAT_FUNCTIONS); do \
if ! grep -- $${fun_} $(top_srcdir)/datapath/linux/compat/build-aux/export-check-whitelist > /dev/null; then \
if [[ ! $${fun_} =~ ^rpl_* ]] \
&& [[ ! $${fun_} =~ ^ovs_* ]]; then \
echo "Should prefix $${fun_} with rpl_ or ovs_."; \
exit 1; \
fi; \
fi; \
done
@for fun_ in $(COMPAT_EXPORTS); do \
if [[ ! $${fun_} =~ ^rpl_* ]] \
&& [[ ! $${fun_} =~ ^ovs_* ]]; then \
echo "Should prefix $${fun_} with rpl_ or ovs_."; \
exit 1; \
fi; \
done

all-local: check-export-symbol
16 changes: 16 additions & 0 deletions datapath/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -246,3 +246,19 @@ The other rules for flow keys are much less subtle:
composes it the same way. This allows userspace to hash and
compare entire flow keys that it may not be able to fully
interpret.


Coding rules
============

Compatibility
-------------

Please implement the headers and codes for compatibility with older kernel
in linux/compat/ directory. All public functions should be exported using
EXPORT_SYMBOL macro. Public function replacing the same-named kernel
function should be prefixed with 'rpl_'. Otherwise, the function should be
prefixed with 'ovs_'. For special case when it is not possible to follow
this rule (e.g., the pskb_expand_head() function), the function name must
be added to linux/compat/build-aux/export-check-whitelist, otherwise, the
compilation check 'check-export-symbol' will fail.
1 change: 1 addition & 0 deletions datapath/linux/Modules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,4 @@ openvswitch_headers += \
linux/compat/include/net/sock.h \
linux/compat/include/net/vxlan.h \
linux/compat/include/net/sctp/checksum.h
EXTRA_DIST += linux/compat/build-aux/export-check-whitelist
1 change: 1 addition & 0 deletions datapath/linux/compat/build-aux/export-check-whitelist
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pskb_expand_head

0 comments on commit b296b82

Please sign in to comment.