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().
(cherry picked from commit a7fa13ed757d74cfd4486f3c282ec50259929edc)

Andrei Pelinescu-Onciul authored on 18/06/2010 20:22:59
Showing 3 changed files
... ...
@@ -580,7 +580,9 @@ int fix_expr(struct expr* exp)
580 580
 					exp->r.re=re;
581 581
 					exp->r_type=RE_ST;
582 582
 				}else if (exp->r_type!=RE_ST && exp->r_type != AVP_ST
583
-						&& exp->r_type != SELECT_ST && exp->r_type!= RVE_ST
583
+						&& exp->r_type != SELECT_ST &&
584
+						exp->r_type != SELECT_UNFIXED_ST &&
585
+						exp->r_type!= RVE_ST
584 586
 						&& exp->r_type != PVAR_ST){
585 587
 					LOG(L_CRIT, "BUG: fix_expr : invalid type for match\n");
586 588
 					return E_BUG;
... ...
@@ -593,19 +595,21 @@ int fix_expr(struct expr* exp)
593 593
 					return ret;
594 594
 				}
595 595
 			}
596
-			if (exp->l_type==SELECT_O) {
596
+			if (exp->l_type==SELECT_UNFIXED_O) {
597 597
 				if ((ret=resolve_select(exp->l.select)) < 0) {
598
-					BUG("Unable to resolve select\n");
598
+					ERR("Unable to resolve select\n");
599 599
 					print_select(exp->l.select);
600 600
 					return ret;
601 601
 				}
602
+				exp->l_type=SELECT_O;
602 603
 			}
603
-			if ((exp->r_type==SELECT_O)||(exp->r_type==SELECT_ST)) {
604
+			if (exp->r_type==SELECT_UNFIXED_ST) {
604 605
 				if ((ret=resolve_select(exp->r.select)) < 0) {
605
-					BUG("Unable to resolve select\n");
606
-					print_select(exp->l.select);
606
+					ERR("Unable to resolve select\n");
607
+					print_select(exp->r.select);
607 608
 					return ret;
608 609
 				}
610
+				exp->r_type=SELECT_ST;
609 611
 			}
610 612
 			/* PVAR don't need fixing */
611 613
 			ret=0;
... ...
@@ -1745,6 +1749,10 @@ inline static int eval_elem(struct run_act_ctx* h, struct expr* e,
1745 1745
 	case PVAR_O:
1746 1746
 		ret=comp_pvar(e->op, e->l.param, e->r_type, &e->r, msg, h);
1747 1747
 		break;
1748
+
1749
+	case SELECT_UNFIXED_O:
1750
+		BUG("unexpected unfixed select operand %d\n", e->l_type);
1751
+		break;
1748 1752
 /*
1749 1753
 	default:
1750 1754
 		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;
... ...
@@ -2761,7 +2761,7 @@ static int fix_rval(struct rvalue* rv)
2761 2761
 			return fix_actions(rv->v.action);
2762 2762
 		case RV_SEL:
2763 2763
 			if (resolve_select(&rv->v.sel)<0){
2764
-				BUG("Unable to resolve select\n");
2764
+				ERR("Unable to resolve select\n");
2765 2765
 				print_select(&rv->v.sel);
2766 2766
 			}
2767 2767
 			return 0;