Lines Matching +full:cs +full:- +full:out
3 /*-
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
76 ((const struct sockaddr_if *)(const void *)(a))->sif_name
80 #define FSTAR -1
81 #define FEQUAL -2
108 goto out; in conf_getnum()
120 return -1; in conf_getnum()
123 return -1; in conf_getnum()
124 out: in conf_getnum()
127 return -1; in conf_getnum()
135 return conf_getnum(f, l, local, &c->c_nfail, "nfail", p); in conf_getnfail()
147 c->c_duration = FSTAR; in conf_getsecs()
152 goto out; in conf_getsecs()
153 c->c_duration = FEQUAL; in conf_getsecs()
183 c->c_duration = (int)tot; in conf_getsecs()
188 return -1; in conf_getsecs()
190 return -1; in conf_getsecs()
191 out: in conf_getsecs()
194 return -1; in conf_getsecs()
205 *(int *)r = ntohs(sv->s_port); in conf_getport()
209 *(int *)r = ntohs(sv->s_port); in conf_getport()
244 c->c_port = FSTAR; in conf_gethostport()
245 c->c_lmask = FSTAR; in conf_gethostport()
256 if (conf_getmask(f, l, local, &pstr, &c->c_lmask) == -1) in conf_gethostport()
257 goto out; in conf_gethostport()
260 struct sockaddr_in6 *sin6 = (void *)&c->c_ss; in conf_gethostport()
264 if (inet_pton(AF_INET6, p, &sin6->sin6_addr) == -1) in conf_gethostport()
265 goto out; in conf_gethostport()
266 sin6->sin6_family = AF_INET6; in conf_gethostport()
268 sin6->sin6_len = sizeof(*sin6); in conf_gethostport()
270 port = &sin6->sin6_port; in conf_gethostport()
275 struct sockaddr_in *sin = (void *)&c->c_ss; in conf_gethostport()
276 struct sockaddr_if *sif = (void *)&c->c_ss; in conf_gethostport()
286 if (c->c_lmask != FSTAR) in conf_gethostport()
288 sif->sif_family = AF_MAX; in conf_gethostport()
289 strlcpy(sif->sif_name, p, in conf_gethostport()
290 sizeof(sif->sif_name)); in conf_gethostport()
292 sif->sif_len = sizeof(*sif); in conf_gethostport()
294 port = &sif->sif_port; in conf_gethostport()
295 } else if (inet_pton(AF_INET, p, &sin->sin_addr) != -1) in conf_gethostport()
297 sin->sin_family = AF_INET; in conf_gethostport()
299 sin->sin_len = sizeof(*sin); in conf_gethostport()
301 port = &sin->sin_port; in conf_gethostport()
303 goto out; in conf_gethostport()
307 if (conf_getport(f, l, local, &c->c_port, pstr) == -1) in conf_gethostport()
308 return -1; in conf_gethostport()
310 if (port && c->c_port != FSTAR && c->c_port != FEQUAL) in conf_gethostport()
311 *port = htons((in_port_t)c->c_port); in conf_gethostport()
313 out: in conf_gethostport()
315 return -1; in conf_gethostport()
318 "interface [%s]", __func__, f, l, c->c_lmask, p); in conf_gethostport()
319 return -1; in conf_gethostport()
323 return -1; in conf_gethostport()
331 c->c_proto = IPPROTO_TCP; in conf_getproto()
335 c->c_proto = IPPROTO_UDP; in conf_getproto()
338 return conf_getnum(f, l, local, &c->c_proto, "protocol", p); in conf_getproto()
346 c->c_family = p[3] == '6' ? AF_INET6 : AF_INET; in conf_getfamily()
349 return conf_getnum(f, l, local, &c->c_family, "family", p); in conf_getfamily()
359 c->c_uid = (int)pw->pw_uid; in conf_getuid()
363 return conf_getnum(f, l, local, &c->c_uid, "user", p); in conf_getuid()
371 if (conf_getmask(f, l, local, &p, &c->c_rmask) == -1) in conf_getname()
372 return -1; in conf_getname()
375 strlcpy(c->c_name, rulename, CONFNAMESZ); in conf_getname()
381 goto out; in conf_getname()
382 c->c_name[0] = '\0'; in conf_getname()
386 snprintf(c->c_name, CONFNAMESZ, "%s%s", *p == '-' ? rulename : "", p); in conf_getname()
388 out: in conf_getname()
391 return -1; in conf_getname()
415 if (e) return -1; in conf_parseline()
417 if (e) return -1; in conf_parseline()
419 if (e) return -1; in conf_parseline()
421 if (e) return -1; in conf_parseline()
423 if (e) return -1; in conf_parseline()
425 if (e) return -1; in conf_parseline()
427 if (e) return -1; in conf_parseline()
439 if ((a)->f > (b)->f) return -1; \ in conf_sort()
440 else if ((a)->f < (b)->f) return 1 in conf_sort()
458 for (ifa = ifas; ifa; ifa = ifa->ifa_next) in conf_is_interface()
459 if (strcmp(ifa->ifa_name, name) == 0) in conf_is_interface()
464 #define MASK(m) ((uint32_t)~((1 << (32 - (m))) - 1))
479 goto out; in conf_amask_eq()
491 mask -= 32; in conf_amask_eq()
498 goto out; in conf_amask_eq()
501 out: in conf_amask_eq()
537 mask -= 32; in conf_apply_mask()
559 c->c_lmask = c->c_rmask; in conf_addr_set()
560 c->c_ss = *ss; in conf_addr_set()
562 if (c->c_ss.ss_family != c->c_family) { in conf_addr_set()
564 "%u != %u", __func__, c->c_ss.ss_family, c->c_family); in conf_addr_set()
568 switch (c->c_ss.ss_family) { in conf_addr_set()
570 sin = (void *)&c->c_ss; in conf_addr_set()
571 port = &sin->sin_port; in conf_addr_set()
572 addr = &sin->sin_addr; in conf_addr_set()
573 alen = sizeof(sin->sin_addr); in conf_addr_set()
576 sin6 = (void *)&c->c_ss; in conf_addr_set()
577 port = &sin6->sin6_port; in conf_addr_set()
578 addr = &sin6->sin6_addr; in conf_addr_set()
579 alen = sizeof(sin6->sin6_addr); in conf_addr_set()
583 __func__, c->c_ss.ss_family); in conf_addr_set()
587 *port = htons((in_port_t)c->c_port); in conf_addr_set()
588 conf_apply_mask(addr, alen, c->c_lmask); in conf_addr_set()
589 if (c->c_lmask == FSTAR) in conf_addr_set()
590 c->c_lmask = (int)(alen * 8); in conf_addr_set()
593 sockaddr_snprintf(buf, sizeof(buf), "%a:%p", (void *)&c->c_ss); in conf_addr_set()
608 if (sa1->sa_family != sa2->sa_family) in conf_inet_eq()
611 switch (sa1->sa_family) { in conf_inet_eq()
615 size = sizeof(s1->sin_addr); in conf_inet_eq()
616 v1 = &s1->sin_addr; in conf_inet_eq()
617 v2 = &s2->sin_addr; in conf_inet_eq()
624 size = sizeof(s1->sin6_addr); in conf_inet_eq()
625 v1 = &s1->sin6_addr; in conf_inet_eq()
626 v2 = &s2->sin6_addr; in conf_inet_eq()
632 __func__, sa1->sa_family); in conf_inet_eq()
646 for (ifa = ifas; ifa; ifa = ifa->ifa_next) { in conf_addr_in_interface()
647 if ((ifa->ifa_flags & IFF_UP) == 0) in conf_addr_in_interface()
650 if (strcmp(ifa->ifa_name, name) != 0) in conf_addr_in_interface()
653 if (s1->ss_family != ifa->ifa_addr->sa_family) in conf_addr_in_interface()
657 switch (s1->ss_family) { in conf_addr_in_interface()
660 eq = conf_inet_eq(ifa->ifa_addr, s1, mask); in conf_addr_in_interface()
663 (*lfun)(LOG_ERR, "Bad family %u", s1->ss_family); in conf_addr_in_interface()
676 switch (s2->ss_family) { in conf_addr_eq()
686 __func__, s1->ss_family); in conf_addr_eq()
695 if (!conf_addr_eq(&c1->c_ss, &c2->c_ss, c2->c_lmask)) in conf_eq()
699 if ((a)->f != (b)->f && (b)->f != FSTAR && (b)->f != FEQUAL) { \ in conf_eq()
702 __STRING(f), (a)->f, (b)->f); \ in conf_eq()
799 strlcpy(b, fmtname(c->c_name), l); in conf_namemask()
800 fmtmask(b, l, c->c_family, c->c_rmask); in conf_namemask()
813 switch (c->c_ss.ss_family) { in conf_print()
818 snprintf(ha, sizeof(ha), "%s", SIF_NAME(&c->c_ss)); in conf_print()
821 sockaddr_snprintf(ha, sizeof(ha), "%a", (const void *)&c->c_ss); in conf_print()
825 fmtmask(ha, sizeof(ha), c->c_family, c->c_lmask); in conf_print()
826 fmtport(ha, sizeof(ha), c->c_port); in conf_print()
828 sp = *delim == '\t' ? 20 : -1; in conf_print()
833 pref, sp, sp, ha, delim, N(0, c->c_proto), delim, in conf_print()
834 N(1, c->c_family), delim, N(2, c->c_uid), delim, in conf_print()
836 N(3, c->c_nfail), delim, N(4, c->c_duration)); in conf_print()
840 ha, N(0, c->c_proto), N(1, c->c_family), N(2, c->c_uid), in conf_print()
842 N(3, c->c_nfail), N(4, c->c_duration)); in conf_print()
860 memcpy(c->c_name, sc->c_name, CONFNAMESZ); in conf_apply()
861 c->c_uid = sc->c_uid; in conf_apply()
862 c->c_rmask = sc->c_rmask; in conf_apply()
863 c->c_nfail = sc->c_nfail; in conf_apply()
864 c->c_duration = sc->c_duration; in conf_apply()
886 if (sc->c_name[0]) in conf_merge()
887 memcpy(c->c_name, sc->c_name, CONFNAMESZ); in conf_merge()
888 if (sc->c_uid != FEQUAL) in conf_merge()
889 c->c_uid = sc->c_uid; in conf_merge()
890 if (sc->c_rmask != FEQUAL) in conf_merge()
891 c->c_lmask = c->c_rmask = sc->c_rmask; in conf_merge()
892 if (sc->c_nfail != FEQUAL) in conf_merge()
893 c->c_nfail = sc->c_nfail; in conf_merge()
894 if (sc->c_duration != FEQUAL) in conf_merge()
895 c->c_duration = sc->c_duration; in conf_merge()
902 confset_init(struct confset *cs) in confset_init() argument
904 cs->cs_c = NULL; in confset_init()
905 cs->cs_n = 0; in confset_init()
906 cs->cs_m = 0; in confset_init()
910 confset_grow(struct confset *cs) in confset_grow() argument
914 cs->cs_m += 10; in confset_grow()
915 tc = realloc(cs->cs_c, cs->cs_m * sizeof(*cs->cs_c)); in confset_grow()
918 return -1; in confset_grow()
920 cs->cs_c = tc; in confset_grow()
925 confset_get(struct confset *cs) in confset_get() argument
927 return &cs->cs_c[cs->cs_n]; in confset_get()
931 confset_full(const struct confset *cs) in confset_full() argument
933 return cs->cs_n == cs->cs_m; in confset_full()
937 confset_sort(struct confset *cs) in confset_sort() argument
939 qsort(cs->cs_c, cs->cs_n, sizeof(*cs->cs_c), conf_sort); in confset_sort()
943 confset_add(struct confset *cs) in confset_add() argument
945 cs->cs_n++; in confset_add()
949 confset_free(struct confset *cs) in confset_free() argument
951 free(cs->cs_c); in confset_free()
952 confset_init(cs); in confset_free()
966 confset_list(const struct confset *cs, const char *msg, const char *where) in confset_list() argument
973 for (size_t i = 0; i < cs->cs_n; i++) in confset_list()
975 &cs->cs_c[i])); in confset_list()
983 confset_match(const struct confset *cs, struct conf *c, in confset_match() argument
989 for (i = 0; i < cs->cs_n; i++) { in confset_match()
992 "check:\t", "", &cs->cs_c[i])); in confset_match()
993 if (conf_eq(c, &cs->cs_c[i])) { in confset_match()
997 "found:\t", "", &cs->cs_c[i])); in confset_match()
998 (*fun)(c, &cs->cs_c[i]); in confset_match()
1029 rtm->rtm_type = RTM_IFANNOUNCE; in conf_route_perm()
1030 rtm->rtm_flags = 0; in conf_route_perm()
1031 rtm->rtm_addrs = RTA_DST|RTA_GATEWAY; in conf_route_perm()
1032 rtm->rtm_version = RTM_VERSION; in conf_route_perm()
1033 rtm->rtm_seq = 666; in conf_route_perm()
1036 rtm->rtm_msglen = (u_short)((char *)cp - (char *)rtm); in conf_route_perm()
1037 if (write(fd, rtm, rtm->rtm_msglen) != -1) { in conf_route_perm()
1064 if (getsockopt(fd, SOL_SOCKET, SO_TYPE, &proto, &slen) == -1) { in conf_handle_inet()
1066 return -1; in conf_handle_inet()
1076 cr->c_proto = IPPROTO_TCP; in conf_handle_inet()
1079 cr->c_proto = IPPROTO_UDP; in conf_handle_inet()
1083 return -1; in conf_handle_inet()
1100 if (getsockname(fd, (void *)&lss, &slen) == -1) { in conf_find()
1107 cr->c_port = ntohs(((struct sockaddr_in *)&lss)->sin_port); in conf_find()
1108 if (conf_handle_inet(fd, &lss, cr) == -1) in conf_find()
1112 cr->c_port = ntohs(((struct sockaddr_in6 *)&lss)->sin6_port); in conf_find()
1113 if (conf_handle_inet(fd, &lss, cr) == -1) in conf_find()
1123 cr->c_proto = FSTAR; in conf_find()
1124 cr->c_port = FSTAR; in conf_find()
1133 cr->c_ss = lss; in conf_find()
1134 cr->c_lmask = FSTAR; in conf_find()
1135 cr->c_uid = (int)uid; in conf_find()
1136 cr->c_family = lss.ss_family; in conf_find()
1137 cr->c_name[0] = '\0'; in conf_find()
1138 cr->c_rmask = FSTAR; in conf_find()
1139 cr->c_nfail = FSTAR; in conf_find()
1140 cr->c_duration = FSTAR; in conf_find()
1158 conf_addr_set(cr, &cr->c_ss); in conf_find()
1170 struct confset lc, rc, *cs; in conf_parse() local
1181 cs = &lc; in conf_parse()
1188 cs = &lc; in conf_parse()
1192 cs = &rc; in conf_parse()
1196 if (confset_full(cs)) { in conf_parse()
1197 if (confset_grow(cs) == -1) { in conf_parse()
1205 if (conf_parseline(f, lineno, line, confset_get(cs), in conf_parse()
1206 cs == &lc) == -1) in conf_parse()
1208 confset_add(cs); in conf_parse()