#!/bin/bash # # (C) 2013 by Arturo Borrero Gonzalez # # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # This is a small testbench for adding nftables rules to kernel # in XML format. BINARY="../examples/nft-rule-xml-add" NFT="$( which nft )" MKTEMP="$( which mktemp )" TMPFILE="$( $MKTEMP )" if [ ! -x "$BINARY" ] ; then echo "E: Binary not found $BINARY" exit 1 fi if [ ! -x "$MKTEMP" ] ; then echo "E: mktemp not found. Is mandatory." exit 1 fi if [ ! -w "$TMPFILE" ] ; then echo "E: Unable to create tempfile with mktemp" exit 1 fi [ ! -x "$NFT" ] && echo "W: nftables main binary not found but continuing anyway $NFT" XML=" 0 127 0 0 1 4 1 eq 1 0x04000000 1 1 12 4 1 eq 1 0x96d60496 1 1 16 4 1 eq 1 0x96d60329 1 1 9 1 1 eq 1 0x06000000 state 0 123123 321321 LOG 0 " $NFT add table filter 2>/dev/null >&2 $NFT add chain filter INPUT 2>/dev/null >&2 echo $XML > $TMPFILE if ! $BINARY "$TMPFILE" ; then echo "E: Unable to add XML." rm -rf $TMPFILE 2>/dev/null exit 1 fi rm -rf $TMPFILE 2>/dev/null echo "I: Test OK"