From owner-freebsd-ipfw@freebsd.org Mon Jan 25 14:29:52 2021 Return-Path: Delivered-To: freebsd-ipfw@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 1D76C4E43E1 for ; Mon, 25 Jan 2021 14:29:52 +0000 (UTC) (envelope-from eksffa@freebsdbrasil.com.br) Received: from leviatan.freebsdbrasil.com.br (leviatan.freebsdbrasil.com.br [177.10.156.9]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4DPXM31pxHz4Vsl for ; Mon, 25 Jan 2021 14:29:50 +0000 (UTC) (envelope-from eksffa@freebsdbrasil.com.br) Received: (qmail 78536 invoked from network); 25 Jan 2021 11:29:48 -0300 Received: by simscan 1.4.0 ppid: 78527, pid: 78533, t: 0.4430s scanners: attach: 1.4.0 clamav: 0.102.3/m:59/d:25889 Received: from unknown ([10.69.64.13]) (envelope-sender ) by capeta.freebsdbrasil.com.br (qmail-ldap-1.03) with SMTP for ; 25 Jan 2021 11:29:48 -0300 From: Patrick Tracanelli Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.40.0.2.32\)) Subject: Re: Lookup tables with dst-port as argument Date: Mon, 25 Jan 2021 11:29:46 -0300 References: <2BBD30C7-044F-4846-9845-C7605306CB5B@freebsdbrasil.com.br> To: freebsd-ipfw@freebsd.org In-Reply-To: <2BBD30C7-044F-4846-9845-C7605306CB5B@freebsdbrasil.com.br> Message-Id: X-Mailer: Apple Mail (2.3654.40.0.2.32) X-Rspamd-Queue-Id: 4DPXM31pxHz4Vsl X-Spamd-Bar: / Authentication-Results: mx1.freebsd.org; dkim=none; dmarc=none; spf=pass (mx1.freebsd.org: domain of eksffa@freebsdbrasil.com.br designates 177.10.156.9 as permitted sender) smtp.mailfrom=eksffa@freebsdbrasil.com.br X-Spamd-Result: default: False [-0.88 / 15.00]; RCVD_TLS_LAST(0.00)[]; RBL_DBL_DONT_QUERY_IPS(0.00)[177.10.156.9:from]; NEURAL_SPAM_SHORT(0.92)[0.919]; MID_RHS_MATCH_FROM(0.00)[]; FROM_HAS_DN(0.00)[]; MV_CASE(0.50)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[multipart/alternative,text/plain]; TO_DN_NONE(0.00)[]; PREVIOUSLY_DELIVERED(0.00)[freebsd-ipfw@freebsd.org]; RCPT_COUNT_ONE(0.00)[1]; SPAMHAUS_ZRD(0.00)[177.10.156.9:from:127.0.2.255]; ARC_NA(0.00)[]; R_SPF_ALLOW(-0.20)[+ip4:177.10.156.0/25]; NEURAL_HAM_LONG(-1.00)[-1.000]; DMARC_NA(0.00)[freebsdbrasil.com.br]; NEURAL_HAM_MEDIUM(-1.00)[-1.000]; FROM_EQ_ENVFROM(0.00)[]; R_DKIM_NA(0.00)[]; MIME_TRACE(0.00)[0:+,1:+,2:~]; ASN(0.00)[asn:61894, ipnet:177.10.156.0/24, country:BR]; RCVD_COUNT_TWO(0.00)[2]; MAILMAN_DEST(0.00)[freebsd-ipfw] Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Content-Filtered-By: Mailman/MimeDel 2.1.34 X-BeenThere: freebsd-ipfw@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: IPFW Technical Discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 25 Jan 2021 14:29:52 -0000 Hello again, Thank you Andrey V. Elsukov, Actually I could do what I wanted using flow lookup. For the archives, = how it was done and tested preliminarily: a) Setup a flow table and a rule to use entries indexed with tabelar 1: # ipfw table idpsflow create type flow:src-ip,dst-port # ipfw add 1 count log all from any to any flow 'table(idpsflow,1)=E2=80=99= in b) Add some flows and args # ipfw table idpsflow add 201.71.251.91,6969 1 # ipfw table idpsflow add 201.71.251.91,22 2 # ipfw table idpsflow add 177.10.156.20,8080 1 c) See what we have # ipfw table idpsflow list 201.71.251.91,6969 1 177.10.156.20,8080 1 201.71.251.91,22 2 # ipfw table idpsflow detail --- table(idpsflow), set(0) --- kindex: 3, type: flow:src-ip,dst-port references: 1, valtype: legacy algorithm: flow:hash items: 3, size: 656 algorithm hash info size: 512 items: 3 itemsize4: 32 itemsize6: 56 d) Check wether it=E2=80=99s matching # ipfw show 1 00001 1189 69888 count log logamount 100 ip from any to any = flow table(idpsflow,1) in The idea behind the 1 and 2 rationale was to abstract the IDS priority = of severity rules adding entries of severity 1, 2, 3, and so on. I did not need the new features of ipfw ever before and know that I just = did, I realized how powerful it became. Actually I have converted over a = couple dozen rules into just 3 rules. This is huge! I don=E2=80=99t know when it those lookup table improvements was = committed and by who, who did it please let me know your ether walled so = I can pay you a beer (for real, distance is no excuse anymore). I don=E2=80=99t know if it=E2=80=99s performance costy but hope someone = could implement table match counters, as we have the bytes and packets = counters per rule, having it per table entry would keep visibility of = what is matching. The only thing I miss converting by 38 rules firewall = into a just 3 is that I only have 3 counters which are almost = meaningless now. Best, Patrick Tracanelli > On 20.01.2021 18:26, Patrick Tracanelli wrote: > > Hello FreeBSD community, > >=20 > > I need to dynamically allocate filtering ports on a tuplet, table > > would do the job, can I lookup the port argument from a table? > > Something like: > >=20 > > ipfw add count all from =E2=80=9Ctable(blist)=E2=80=9D to any = dst-port tablearg in > >=20 > > In the above example table blist was created as =E2=80=9Cipfw table = blist > > create type number=E2=80=9D. > >=20 > > It certainly won=E2=80=99t work as above written since tablearg is = not > > supported for dst-port. > >=20 > > Is there any other approach possible to reach this desired behavior? >=20 > Hi, >=20 > it seems you need to take alook at the 'lookup dst-port tablename' = opcode. >=20 > --=20 > WBR, Andrey V. Elsukov