| 
									
										
										
										
											1999-01-15 16:49:17 +00:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  *	Filters: utility functions | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  *	Copyright 1998 Pavel Machek <pavel@ucw.cz> | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  *	Can be freely distributed and used under the terms of the GNU GPL. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "nest/bird.h"
 | 
					
						
							|  |  |  | #include "conf/conf.h"
 | 
					
						
							|  |  |  | #include "filter/filter.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-04-20 10:25:51 +00:00
										 |  |  | #define P(a,b) ((a<<8) | b)
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1999-03-08 20:30:06 +00:00
										 |  |  | struct f_inst * | 
					
						
							| 
									
										
										
										
											1999-03-02 19:49:28 +00:00
										 |  |  | f_new_inst(void) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											1999-03-08 20:30:06 +00:00
										 |  |  |   struct f_inst * ret; | 
					
						
							|  |  |  |   ret = cfg_alloc(sizeof(struct f_inst)); | 
					
						
							| 
									
										
										
										
											1999-11-18 14:01:36 +00:00
										 |  |  |   ret->code = ret->aux = 0; | 
					
						
							| 
									
										
										
										
											1999-03-02 19:49:28 +00:00
										 |  |  |   ret->arg1 = ret->arg2 = ret->next = NULL; | 
					
						
							| 
									
										
										
										
											2012-07-18 19:29:33 +02:00
										 |  |  |   ret->lineno = ifs->lino; | 
					
						
							| 
									
										
										
										
											1999-03-02 19:49:28 +00:00
										 |  |  |   return ret; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-03-01 11:32:23 +00:00
										 |  |  | struct f_inst * | 
					
						
							| 
									
										
										
										
											2004-06-05 09:26:55 +00:00
										 |  |  | f_new_dynamic_attr(int type, int f_type UNUSED, int code) | 
					
						
							| 
									
										
										
										
											2000-03-01 11:32:23 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2004-06-05 09:26:55 +00:00
										 |  |  |   /* FIXME: Remove the f_type parameter? */ | 
					
						
							| 
									
										
										
										
											2000-03-01 11:32:23 +00:00
										 |  |  |   struct f_inst *f = f_new_inst(); | 
					
						
							| 
									
										
										
										
											2000-04-17 14:12:02 +00:00
										 |  |  |   f->aux = type; | 
					
						
							| 
									
										
										
										
											2000-03-01 11:32:23 +00:00
										 |  |  |   f->a2.i = code; | 
					
						
							|  |  |  |   return f; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-04-20 10:25:51 +00:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * Generate set_dynamic( operation( get_dynamic(), argument ) ) | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | struct f_inst * | 
					
						
							|  |  |  | f_generate_complex(int operation, int operation_aux, struct f_inst *dyn, struct f_inst *argument) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   struct f_inst *set_dyn = f_new_inst(), | 
					
						
							|  |  |  |                 *oper = f_new_inst(), | 
					
						
							|  |  |  |                 *get_dyn = dyn; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   *set_dyn = *get_dyn; | 
					
						
							|  |  |  |   get_dyn->code = P('e','a'); | 
					
						
							|  |  |  |   oper->code = operation; | 
					
						
							|  |  |  |   oper->aux = operation_aux; | 
					
						
							|  |  |  |   oper->a1.p = get_dyn; | 
					
						
							|  |  |  |   oper->a2.p = argument; | 
					
						
							|  |  |  |   set_dyn->code = P('e','S'); | 
					
						
							|  |  |  |   set_dyn->a1.p = oper; | 
					
						
							|  |  |  |   return set_dyn; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-18 17:32:30 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | struct f_inst * | 
					
						
							|  |  |  | f_generate_roa_check(struct symbol *sym, struct f_inst *prefix, struct f_inst *asn) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   struct f_inst_roa_check *ret = cfg_allocz(sizeof(struct f_inst_roa_check)); | 
					
						
							|  |  |  |   ret->i.code = P('R','C'); | 
					
						
							| 
									
										
										
										
											2012-07-18 19:29:33 +02:00
										 |  |  |   ret->i.lineno = ifs->lino; | 
					
						
							| 
									
										
										
										
											2012-03-18 17:32:30 +01:00
										 |  |  |   ret->i.arg1 = prefix; | 
					
						
							|  |  |  |   ret->i.arg2 = asn; | 
					
						
							|  |  |  |   /* prefix == NULL <-> asn == NULL */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if ((sym->class != SYM_ROA) || ! sym->def) | 
					
						
							|  |  |  |     cf_error("%s is not a ROA table", sym->name); | 
					
						
							|  |  |  |   ret->rtc = sym->def; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return &ret->i; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1999-04-05 20:10:31 +00:00
										 |  |  | char * | 
					
						
							|  |  |  | filter_name(struct filter *filter) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   if (!filter) | 
					
						
							|  |  |  |     return "ACCEPT"; | 
					
						
							|  |  |  |   else if (filter == FILTER_REJECT) | 
					
						
							|  |  |  |     return "REJECT"; | 
					
						
							| 
									
										
										
										
											2012-03-15 12:50:49 +01:00
										 |  |  |   else if (!filter->name) | 
					
						
							|  |  |  |     return "(unnamed)"; | 
					
						
							| 
									
										
										
										
											1999-04-05 20:10:31 +00:00
										 |  |  |   else | 
					
						
							|  |  |  |     return filter->name; | 
					
						
							|  |  |  | } |