Browse code

core: fix selects in optimized rvalue expressions

- do not attempt to resolve_select() twice the same select. This
happened when a rve containing only a select was optimized,
the select moved out of the rve and fix_expr() tried to "fix"
the already resolved select later.
- changed BUG() messages for failed resolve_select() into ERR().

Andrei Pelinescu-Onciul authored on 18/06/2010 20:22:59
Showing 3 changed files
... ...
@@ -588,7 +588,9 @@ int fix_expr(struct expr* exp)
588 588
 					exp->r.re=re;
589 589
 					exp->r_type=RE_ST;
590 590
 				}else if (exp->r_type!=RE_ST && exp->r_type != AVP_ST
591
-						&& exp->r_type != SELECT_ST && exp->r_type!= RVE_ST
591
+						&& exp->r_type != SELECT_ST &&
592
+						exp->r_type != SELECT_UNFIXED_ST &&
593
+						exp->r_type!= RVE_ST
592 594
 						&& exp->r_type != PVAR_ST){
593 595
 					LOG(L_CRIT, "BUG: fix_expr : invalid type for match\n");
594 596
 					return E_BUG;
... ...
@@ -601,19 +603,21 @@ int fix_expr(struct expr* exp)
601 601
 					return ret;
602 602
 				}
603 603
 			}
604
-			if (exp->l_type==SELECT_O) {
604
+			if (exp->l_type==SELECT_UNFIXED_O) {
605 605
 				if ((ret=resolve_select(exp->l.select)) < 0) {
606
-					BUG("Unable to resolve select\n");
606
+					ERR("Unable to resolve select\n");
607 607
 					print_select(exp->l.select);
608 608
 					return ret;
609 609
 				}
610
+				exp->l_type=SELECT_O;
610 611
 			}
611
-			if ((exp->r_type==SELECT_O)||(exp->r_type==SELECT_ST)) {
612
+			if (exp->r_type==SELECT_UNFIXED_ST) {
612 613
 				if ((ret=resolve_select(exp->r.select)) < 0) {
613
-					BUG("Unable to resolve select\n");
614
-					print_select(exp->l.select);
614
+					ERR("Unable to resolve select\n");
615
+					print_select(exp->r.select);
615 616
 					return ret;
616 617
 				}
618
+				exp->r_type=SELECT_ST;
617 619
 			}
618 620
 			/* PVAR don't need fixing */
619 621
 			ret=0;
... ...
@@ -1895,6 +1899,10 @@ inline static int eval_elem(struct run_act_ctx* h, struct expr* e,
1895 1895
 	case PVAR_O:
1896 1896
 		ret=comp_pvar(e->op, e->l.param, e->r_type, &e->r, msg, h);
1897 1897
 		break;
1898
+
1899
+	case SELECT_UNFIXED_O:
1900
+		BUG("unexpected unfixed select operand %d\n", e->l_type);
1901
+		break;
1898 1902
 /*
1899 1903
 	default:
1900 1904
 		LOG(L_CRIT, "BUG: eval_elem: invalid operand %d\n",
... ...
@@ -76,7 +76,7 @@ enum _expr_l_type{
76 76
 	   METHOD_O=51, URI_O, FROM_URI_O, TO_URI_O, SRCIP_O, SRCPORT_O,
77 77
 	   DSTIP_O, DSTPORT_O, PROTO_O, AF_O, MSGLEN_O, ACTION_O,
78 78
 	   NUMBER_O, AVP_O, SNDIP_O, SNDPORT_O, TOIP_O, TOPORT_O, SNDPROTO_O,
79
-	   SNDAF_O, RETCODE_O, SELECT_O, PVAR_O, RVEXP_O};
79
+	   SNDAF_O, RETCODE_O, SELECT_O, PVAR_O, RVEXP_O, SELECT_UNFIXED_O};
80 80
 /* action types */
81 81
 enum action_type{
82 82
 		FORWARD_T=1, SEND_T, DROP_T, LOG_T, ERROR_T, ROUTE_T, EXEC_T,
... ...
@@ -121,7 +121,8 @@ enum _operand_subtype{
121 121
 		SELECT_ST, PVAR_ST,
122 122
 		LVAL_ST,  RVE_ST,
123 123
 		RETCODE_ST, CASE_ST,
124
-		BLOCK_ST, JUMPTABLE_ST, CONDTABLE_ST, MATCH_CONDTABLE_ST
124
+		BLOCK_ST, JUMPTABLE_ST, CONDTABLE_ST, MATCH_CONDTABLE_ST,
125
+		SELECT_UNFIXED_ST
125 126
 };
126 127
 
127 128
 typedef enum _expr_l_type expr_l_type;
... ...
@@ -2768,7 +2768,7 @@ static int fix_rval(struct rvalue* rv)
2768 2768
 			return fix_actions(rv->v.action);
2769 2769
 		case RV_SEL:
2770 2770
 			if (resolve_select(&rv->v.sel)<0){
2771
-				BUG("Unable to resolve select\n");
2771
+				ERR("Unable to resolve select\n");
2772 2772
 				print_select(&rv->v.sel);
2773 2773
 			}
2774 2774
 			return 0;