141edb306SCy Schubert
241edb306SCy Schubert /*
341edb306SCy Schubert * Copyright (C) 2000-2004 by Darren Reed.
441edb306SCy Schubert *
541edb306SCy Schubert * See the IPFILTER.LICENCE file for details on licencing.
641edb306SCy Schubert *
741edb306SCy Schubert * $Id: tcp_flags.c,v 1.8.2.1 2006/06/16 17:21:17 darrenr Exp $
841edb306SCy Schubert */
941edb306SCy Schubert
1041edb306SCy Schubert #include "ipf.h"
1141edb306SCy Schubert
1241edb306SCy Schubert extern char flagset[];
13*347dd053SRichard Scheffenegger extern uint16_t flags[];
1441edb306SCy Schubert
1541edb306SCy Schubert
tcp_flags(char * flgs,uint16_t * mask,int linenum)16*347dd053SRichard Scheffenegger uint16_t tcp_flags(char *flgs, uint16_t *mask, int linenum)
1741edb306SCy Schubert {
18*347dd053SRichard Scheffenegger uint16_t tcpf = 0, tcpfm = 0;
1941edb306SCy Schubert char *s;
2041edb306SCy Schubert
2141edb306SCy Schubert s = strchr(flgs, '/');
2241edb306SCy Schubert if (s)
2341edb306SCy Schubert *s++ = '\0';
2441edb306SCy Schubert
2541edb306SCy Schubert if (*flgs == '0') {
2641edb306SCy Schubert tcpf = strtol(flgs, NULL, 0);
2741edb306SCy Schubert } else {
2841edb306SCy Schubert tcpf = tcpflags(flgs);
2941edb306SCy Schubert }
3041edb306SCy Schubert
3141edb306SCy Schubert if (s != NULL) {
3241edb306SCy Schubert if (*s == '0')
3341edb306SCy Schubert tcpfm = strtol(s, NULL, 0);
3441edb306SCy Schubert else
3541edb306SCy Schubert tcpfm = tcpflags(s);
3641edb306SCy Schubert }
3741edb306SCy Schubert
3841edb306SCy Schubert if (!tcpfm) {
3941edb306SCy Schubert if (tcpf == TH_SYN)
40*347dd053SRichard Scheffenegger tcpfm = TH_FLAGS & ~(TH_ECN|TH_CWR);
4141edb306SCy Schubert else
42*347dd053SRichard Scheffenegger tcpfm = TH_FLAGS & ~(TH_ECN);
4341edb306SCy Schubert }
4441edb306SCy Schubert *mask = tcpfm;
452582ae57SCy Schubert return (tcpf);
4641edb306SCy Schubert }
47