Changeset View
Changeset View
Standalone View
Standalone View
sys/netpfil/ipfw/nat64/nat64stl_control.c
- This file was copied to sys/netpfil/ipfw/nat64/nat64clat_control.c.
/*- | /*- | ||||
* Copyright (c) 2015-2016 Yandex LLC | * SPDX-License-Identifier: BSD-2-Clause-FreeBSD | ||||
* Copyright (c) 2015-2016 Andrey V. Elsukov <ae@FreeBSD.org> | * | ||||
* Copyright (c) 2015-2019 Yandex LLC | |||||
* Copyright (c) 2015 Alexander V. Chernikov <melifaro@FreeBSD.org> | * Copyright (c) 2015 Alexander V. Chernikov <melifaro@FreeBSD.org> | ||||
* All rights reserved. | * Copyright (c) 2015-2019 Andrey V. Elsukov <ae@FreeBSD.org> | ||||
* | * | ||||
* Redistribution and use in source and binary forms, with or without | * Redistribution and use in source and binary forms, with or without | ||||
* modification, are permitted provided that the following conditions | * modification, are permitted provided that the following conditions | ||||
* are met: | * are met: | ||||
* | * | ||||
* 1. Redistributions of source code must retain the above copyright | * 1. Redistributions of source code must retain the above copyright | ||||
* notice, this list of conditions and the following disclaimer. | * notice, this list of conditions and the following disclaimer. | ||||
* 2. Redistributions in binary form must reproduce the above copyright | * 2. Redistributions in binary form must reproduce the above copyright | ||||
▲ Show 20 Lines • Show All 80 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
static void | static void | ||||
nat64stl_export_config(struct ip_fw_chain *ch, struct nat64stl_cfg *cfg, | nat64stl_export_config(struct ip_fw_chain *ch, struct nat64stl_cfg *cfg, | ||||
ipfw_nat64stl_cfg *uc) | ipfw_nat64stl_cfg *uc) | ||||
{ | { | ||||
struct named_object *no; | struct named_object *no; | ||||
uc->prefix6 = cfg->base.prefix6; | uc->prefix6 = cfg->base.plat_prefix; | ||||
uc->plen6 = cfg->base.plen6; | uc->plen6 = cfg->base.plat_plen; | ||||
uc->flags = cfg->base.flags & NAT64STL_FLAGSMASK; | uc->flags = cfg->base.flags & NAT64STL_FLAGSMASK; | ||||
uc->set = cfg->no.set; | uc->set = cfg->no.set; | ||||
strlcpy(uc->name, cfg->no.name, sizeof(uc->name)); | strlcpy(uc->name, cfg->no.name, sizeof(uc->name)); | ||||
no = ipfw_objhash_lookup_table_kidx(ch, cfg->map64); | no = ipfw_objhash_lookup_table_kidx(ch, cfg->map64); | ||||
ipfw_export_obj_ntlv(no, &uc->ntlv6); | ipfw_export_obj_ntlv(no, &uc->ntlv6); | ||||
no = ipfw_objhash_lookup_table_kidx(ch, cfg->map46); | no = ipfw_objhash_lookup_table_kidx(ch, cfg->map46); | ||||
ipfw_export_obj_ntlv(no, &uc->ntlv4); | ipfw_export_obj_ntlv(no, &uc->ntlv4); | ||||
▲ Show 20 Lines • Show All 84 Lines • ▼ Show 20 Lines | nat64stl_create(struct ip_fw_chain *ch, ip_fw3_opheader *op3, | ||||
/* XXX: check types of tables */ | /* XXX: check types of tables */ | ||||
ni = CHAIN_TO_SRV(ch); | ni = CHAIN_TO_SRV(ch); | ||||
error = 0; | error = 0; | ||||
IPFW_UH_RLOCK(ch); | IPFW_UH_RLOCK(ch); | ||||
if (nat64stl_find(ni, uc->name, uc->set) != NULL) { | if (nat64stl_find(ni, uc->name, uc->set) != NULL) { | ||||
IPFW_UH_RUNLOCK(ch); | IPFW_UH_RUNLOCK(ch); | ||||
return (EEXIST); | return (ENOENT); | ||||
} | } | ||||
IPFW_UH_RUNLOCK(ch); | IPFW_UH_RUNLOCK(ch); | ||||
cfg = nat64stl_alloc_config(uc->name, uc->set); | cfg = nat64stl_alloc_config(uc->name, uc->set); | ||||
cfg->base.prefix6 = uc->prefix6; | cfg->base.plat_prefix = uc->prefix6; | ||||
cfg->base.plen6 = uc->plen6; | cfg->base.plat_plen = uc->plen6; | ||||
cfg->base.flags = uc->flags & NAT64STL_FLAGSMASK; | cfg->base.flags = (uc->flags & NAT64STL_FLAGSMASK) | NAT64_PLATPFX; | ||||
if (IN6_IS_ADDR_WKPFX(&cfg->base.prefix6)) | if (IN6_IS_ADDR_WKPFX(&cfg->base.plat_prefix)) | ||||
cfg->base.flags |= NAT64_WKPFX; | cfg->base.flags |= NAT64_WKPFX; | ||||
IPFW_UH_WLOCK(ch); | IPFW_UH_WLOCK(ch); | ||||
if (nat64stl_find(ni, uc->name, uc->set) != NULL) { | if (nat64stl_find(ni, uc->name, uc->set) != NULL) { | ||||
IPFW_UH_WUNLOCK(ch); | IPFW_UH_WUNLOCK(ch); | ||||
nat64stl_free_config(cfg); | nat64stl_free_config(cfg); | ||||
return (EEXIST); | return (ENOENT); | ||||
} | } | ||||
error = nat64stl_create_internal(ch, cfg, uc); | error = nat64stl_create_internal(ch, cfg, uc); | ||||
if (error == 0) { | if (error == 0) { | ||||
/* Okay, let's link data */ | /* Okay, let's link data */ | ||||
SRV_OBJECT(ch, cfg->no.kidx) = cfg; | SRV_OBJECT(ch, cfg->no.kidx) = cfg; | ||||
IPFW_UH_WUNLOCK(ch); | IPFW_UH_WUNLOCK(ch); | ||||
return (0); | return (0); | ||||
} | } | ||||
Show All 39 Lines | if (ipfw_check_object_name_generic(oh->ntlv.name) != 0 || | ||||
return (EINVAL); | return (EINVAL); | ||||
ni = CHAIN_TO_SRV(ch); | ni = CHAIN_TO_SRV(ch); | ||||
if (sd->sopt->sopt_dir == SOPT_GET) { | if (sd->sopt->sopt_dir == SOPT_GET) { | ||||
IPFW_UH_RLOCK(ch); | IPFW_UH_RLOCK(ch); | ||||
cfg = nat64stl_find(ni, oh->ntlv.name, oh->ntlv.set); | cfg = nat64stl_find(ni, oh->ntlv.name, oh->ntlv.set); | ||||
if (cfg == NULL) { | if (cfg == NULL) { | ||||
IPFW_UH_RUNLOCK(ch); | IPFW_UH_RUNLOCK(ch); | ||||
return (EEXIST); | return (ENOENT); | ||||
} | } | ||||
nat64stl_export_config(ch, cfg, uc); | nat64stl_export_config(ch, cfg, uc); | ||||
IPFW_UH_RUNLOCK(ch); | IPFW_UH_RUNLOCK(ch); | ||||
return (0); | return (0); | ||||
} | } | ||||
IPFW_UH_WLOCK(ch); | IPFW_UH_WLOCK(ch); | ||||
cfg = nat64stl_find(ni, oh->ntlv.name, oh->ntlv.set); | cfg = nat64stl_find(ni, oh->ntlv.name, oh->ntlv.set); | ||||
if (cfg == NULL) { | if (cfg == NULL) { | ||||
IPFW_UH_WUNLOCK(ch); | IPFW_UH_WUNLOCK(ch); | ||||
return (EEXIST); | return (ENOENT); | ||||
} | } | ||||
/* | /* | ||||
* For now allow to change only following values: | * For now allow to change only following values: | ||||
* flags. | * flags. | ||||
*/ | */ | ||||
cfg->base.flags &= ~NAT64STL_FLAGSMASK; | cfg->base.flags &= ~NAT64STL_FLAGSMASK; | ||||
cfg->base.flags |= uc->flags & NAT64STL_FLAGSMASK; | cfg->base.flags |= uc->flags & NAT64STL_FLAGSMASK; | ||||
Show All 34 Lines | nat64stl_destroy(struct ip_fw_chain *ch, ip_fw3_opheader *op3, | ||||
oh = (ipfw_obj_header *)sd->kbuf; | oh = (ipfw_obj_header *)sd->kbuf; | ||||
if (ipfw_check_object_name_generic(oh->ntlv.name) != 0) | if (ipfw_check_object_name_generic(oh->ntlv.name) != 0) | ||||
return (EINVAL); | return (EINVAL); | ||||
IPFW_UH_WLOCK(ch); | IPFW_UH_WLOCK(ch); | ||||
cfg = nat64stl_find(CHAIN_TO_SRV(ch), oh->ntlv.name, oh->ntlv.set); | cfg = nat64stl_find(CHAIN_TO_SRV(ch), oh->ntlv.name, oh->ntlv.set); | ||||
if (cfg == NULL) { | if (cfg == NULL) { | ||||
IPFW_UH_WUNLOCK(ch); | IPFW_UH_WUNLOCK(ch); | ||||
return (ESRCH); | return (ENOENT); | ||||
} | } | ||||
if (cfg->no.refcnt > 0) { | if (cfg->no.refcnt > 0) { | ||||
IPFW_UH_WUNLOCK(ch); | IPFW_UH_WUNLOCK(ch); | ||||
return (EBUSY); | return (EBUSY); | ||||
} | } | ||||
ipfw_reset_eaction_instance(ch, V_nat64stl_eid, cfg->no.kidx); | ipfw_reset_eaction_instance(ch, V_nat64stl_eid, cfg->no.kidx); | ||||
SRV_OBJECT(ch, cfg->no.kidx) = NULL; | SRV_OBJECT(ch, cfg->no.kidx) = NULL; | ||||
▲ Show 20 Lines • Show All 91 Lines • ▼ Show 20 Lines | nat64stl_stats(struct ip_fw_chain *ch, ip_fw3_opheader *op, | ||||
if (oh == NULL) | if (oh == NULL) | ||||
return (EINVAL); | return (EINVAL); | ||||
memset(&stats, 0, sizeof(stats)); | memset(&stats, 0, sizeof(stats)); | ||||
IPFW_UH_RLOCK(ch); | IPFW_UH_RLOCK(ch); | ||||
cfg = nat64stl_find(CHAIN_TO_SRV(ch), oh->ntlv.name, oh->ntlv.set); | cfg = nat64stl_find(CHAIN_TO_SRV(ch), oh->ntlv.name, oh->ntlv.set); | ||||
if (cfg == NULL) { | if (cfg == NULL) { | ||||
IPFW_UH_RUNLOCK(ch); | IPFW_UH_RUNLOCK(ch); | ||||
return (ESRCH); | return (ENOENT); | ||||
} | } | ||||
export_stats(ch, cfg, &stats); | export_stats(ch, cfg, &stats); | ||||
IPFW_UH_RUNLOCK(ch); | IPFW_UH_RUNLOCK(ch); | ||||
ctlv = (ipfw_obj_ctlv *)(oh + 1); | ctlv = (ipfw_obj_ctlv *)(oh + 1); | ||||
memset(ctlv, 0, sizeof(*ctlv)); | memset(ctlv, 0, sizeof(*ctlv)); | ||||
ctlv->head.type = IPFW_TLV_COUNTERS; | ctlv->head.type = IPFW_TLV_COUNTERS; | ||||
ctlv->head.length = sz - sizeof(ipfw_obj_header); | ctlv->head.length = sz - sizeof(ipfw_obj_header); | ||||
Show All 24 Lines | nat64stl_reset_stats(struct ip_fw_chain *ch, ip_fw3_opheader *op, | ||||
if (ipfw_check_object_name_generic(oh->ntlv.name) != 0 || | if (ipfw_check_object_name_generic(oh->ntlv.name) != 0 || | ||||
oh->ntlv.set >= IPFW_MAX_SETS) | oh->ntlv.set >= IPFW_MAX_SETS) | ||||
return (EINVAL); | return (EINVAL); | ||||
IPFW_UH_WLOCK(ch); | IPFW_UH_WLOCK(ch); | ||||
cfg = nat64stl_find(CHAIN_TO_SRV(ch), oh->ntlv.name, oh->ntlv.set); | cfg = nat64stl_find(CHAIN_TO_SRV(ch), oh->ntlv.name, oh->ntlv.set); | ||||
if (cfg == NULL) { | if (cfg == NULL) { | ||||
IPFW_UH_WUNLOCK(ch); | IPFW_UH_WUNLOCK(ch); | ||||
return (ESRCH); | return (ENOENT); | ||||
} | } | ||||
COUNTER_ARRAY_ZERO(cfg->base.stats.cnt, NAT64STATS); | COUNTER_ARRAY_ZERO(cfg->base.stats.cnt, NAT64STATS); | ||||
IPFW_UH_WUNLOCK(ch); | IPFW_UH_WUNLOCK(ch); | ||||
return (0); | return (0); | ||||
} | } | ||||
static struct ipfw_sopt_handler scodes[] = { | static struct ipfw_sopt_handler scodes[] = { | ||||
▲ Show 20 Lines • Show All 124 Lines • Show Last 20 Lines |