From owner-svn-src-all@freebsd.org Wed Nov 22 05:49:22 2017 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id A3FD7DE1706; Wed, 22 Nov 2017 05:49:22 +0000 (UTC) (envelope-from ae@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 701CA6D41A; Wed, 22 Nov 2017 05:49:22 +0000 (UTC) (envelope-from ae@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id vAM5nLW8097349; Wed, 22 Nov 2017 05:49:21 GMT (envelope-from ae@FreeBSD.org) Received: (from ae@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id vAM5nLrt097346; Wed, 22 Nov 2017 05:49:21 GMT (envelope-from ae@FreeBSD.org) Message-Id: <201711220549.vAM5nLrt097346@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ae set sender to ae@FreeBSD.org using -f From: "Andrey V. Elsukov" Date: Wed, 22 Nov 2017 05:49:21 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r326086 - head/sys/netpfil/ipfw X-SVN-Group: head X-SVN-Commit-Author: ae X-SVN-Commit-Paths: head/sys/netpfil/ipfw X-SVN-Commit-Revision: 326086 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 22 Nov 2017 05:49:22 -0000 Author: ae Date: Wed Nov 22 05:49:21 2017 New Revision: 326086 URL: https://svnweb.freebsd.org/changeset/base/326086 Log: Add ipfw_add_protected_rule() function that creates rule with 65535 number in the reserved set 31. Use this function to create default rule. Obtained from: Yandex LLC MFC after: 1 week Sponsored by: Yandex LLC Modified: head/sys/netpfil/ipfw/ip_fw2.c head/sys/netpfil/ipfw/ip_fw_private.h head/sys/netpfil/ipfw/ip_fw_sockopt.c Modified: head/sys/netpfil/ipfw/ip_fw2.c ============================================================================== --- head/sys/netpfil/ipfw/ip_fw2.c Wed Nov 22 05:27:18 2017 (r326085) +++ head/sys/netpfil/ipfw/ip_fw2.c Wed Nov 22 05:49:21 2017 (r326086) @@ -2842,11 +2842,6 @@ vnet_ipfw_init(const void *unused) ipfw_init_srv(chain); ipfw_init_counters(); - /* insert the default rule and create the initial map */ - chain->n_rules = 1; - chain->map = malloc(sizeof(struct ip_fw *), M_IPFW, M_WAITOK | M_ZERO); - rule = ipfw_alloc_rule(chain, sizeof(struct ip_fw)); - /* Set initial number of tables */ V_fw_tables_max = default_fw_tables; error = ipfw_init_tables(chain, first); @@ -2857,19 +2852,16 @@ vnet_ipfw_init(const void *unused) return (ENOSPC); } + IPFW_LOCK_INIT(chain); + /* fill and insert the default rule */ - rule->act_ofs = 0; - rule->rulenum = IPFW_DEFAULT_RULE; + rule = ipfw_alloc_rule(chain, sizeof(struct ip_fw)); rule->cmd_len = 1; - rule->set = RESVD_SET; rule->cmd[0].len = 1; rule->cmd[0].opcode = default_to_accept ? O_ACCEPT : O_DENY; - chain->default_rule = chain->map[0] = rule; - chain->id = rule->id = 1; - /* Pre-calculate rules length for legacy dump format */ - chain->static_len = sizeof(struct ip_fw_rule0); + chain->default_rule = rule; + ipfw_add_protected_rule(chain, rule, 0); - IPFW_LOCK_INIT(chain); ipfw_dyn_init(chain); ipfw_eaction_init(chain, first); #ifdef LINEAR_SKIPTO Modified: head/sys/netpfil/ipfw/ip_fw_private.h ============================================================================== --- head/sys/netpfil/ipfw/ip_fw_private.h Wed Nov 22 05:27:18 2017 (r326085) +++ head/sys/netpfil/ipfw/ip_fw_private.h Wed Nov 22 05:49:21 2017 (r326086) @@ -625,6 +625,8 @@ void ipfw_destroy_skipto_cache(struct ip_fw_chain *cha int ipfw_find_rule(struct ip_fw_chain *chain, uint32_t key, uint32_t id); int ipfw_ctl3(struct sockopt *sopt); int ipfw_chk(struct ip_fw_args *args); +int ipfw_add_protected_rule(struct ip_fw_chain *chain, struct ip_fw *rule, + int locked); void ipfw_reap_add(struct ip_fw_chain *chain, struct ip_fw **head, struct ip_fw *rule); void ipfw_reap_rules(struct ip_fw *head); Modified: head/sys/netpfil/ipfw/ip_fw_sockopt.c ============================================================================== --- head/sys/netpfil/ipfw/ip_fw_sockopt.c Wed Nov 22 05:27:18 2017 (r326085) +++ head/sys/netpfil/ipfw/ip_fw_sockopt.c Wed Nov 22 05:49:21 2017 (r326086) @@ -790,6 +790,30 @@ commit_rules(struct ip_fw_chain *chain, struct rule_ch return (0); } +int +ipfw_add_protected_rule(struct ip_fw_chain *chain, struct ip_fw *rule, + int locked) +{ + struct ip_fw **map; + + map = get_map(chain, 1, locked); + if (map == NULL) + return (ENOMEM); + if (chain->n_rules > 0) + bcopy(chain->map, map, + chain->n_rules * sizeof(struct ip_fw *)); + map[chain->n_rules] = rule; + rule->rulenum = IPFW_DEFAULT_RULE; + rule->set = RESVD_SET; + rule->id = chain->id + 1; + /* We add rule in the end of chain, no need to update skipto cache */ + map = swap_map(chain, map, chain->n_rules + 1); + chain->static_len += RULEUSIZE0(rule); + IPFW_UH_WUNLOCK(chain); + free(map, M_IPFW); + return (0); +} + /* * Adds @rule to the list of rules to reap */