1 |
|
|
/* $OpenBSD: irrfilter.c,v 1.6 2015/11/01 21:20:46 benno Exp $ */ |
2 |
|
|
|
3 |
|
|
/* |
4 |
|
|
* Copyright (c) 2007 Henning Brauer <henning@openbsd.org> |
5 |
|
|
* |
6 |
|
|
* Permission to use, copy, modify, and distribute this software for any |
7 |
|
|
* purpose with or without fee is hereby granted, provided that the above |
8 |
|
|
* copyright notice and this permission notice appear in all copies. |
9 |
|
|
* |
10 |
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
11 |
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
12 |
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
13 |
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
14 |
|
|
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER IN |
15 |
|
|
* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT |
16 |
|
|
* OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
17 |
|
|
*/ |
18 |
|
|
|
19 |
|
|
#include <sys/types.h> |
20 |
|
|
#include <err.h> |
21 |
|
|
#include <stdio.h> |
22 |
|
|
#include <stdlib.h> |
23 |
|
|
#include <string.h> |
24 |
|
|
#include <unistd.h> |
25 |
|
|
|
26 |
|
|
#include "irrfilter.h" |
27 |
|
|
|
28 |
|
|
__dead void |
29 |
|
|
irr_main(u_int32_t AS, int flags, char *outdir) |
30 |
|
|
{ |
31 |
|
|
char *query; |
32 |
|
|
int r; |
33 |
|
|
|
34 |
|
|
if (pledge("stdio rpath wpath cpath inet dns flock", NULL) == -1) |
35 |
|
|
err(1, "pledge"); |
36 |
|
|
|
37 |
|
|
fprintf(stderr, "irrfilter for: %u, writing to %s\n", AS, outdir); |
38 |
|
|
|
39 |
|
|
irrflags = flags; |
40 |
|
|
irrverbose = 0; |
41 |
|
|
TAILQ_INIT(&router_head); |
42 |
|
|
|
43 |
|
|
/* send query for own AS, parse policy */ |
44 |
|
|
if (asprintf(&query, "AS%u", AS) == -1) |
45 |
|
|
err(1, "parse_policy asprintf"); |
46 |
|
|
if ((r = whois(query, QTYPE_OWNAS)) == -1) |
47 |
|
|
exit(1); |
48 |
|
|
if (r == 0) |
49 |
|
|
errx(1, "aut-num object %s not found", query); |
50 |
|
|
free(query); |
51 |
|
|
|
52 |
|
|
write_filters(outdir); |
53 |
|
|
|
54 |
|
|
exit(0); |
55 |
|
|
} |