]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
debug: include verbose message in all BUG statements
authorroot <root@debian.localnet>
Sat, 8 Dec 2012 17:08:44 +0000 (18:08 +0100)
committerPatrick McHardy <kaber@trash.net>
Sat, 8 Dec 2012 17:11:20 +0000 (18:11 +0100)
Signed-off-by: Patrick McHardy <kaber@trash.net>
include/utils.h
src/datatype.c
src/erec.c
src/evaluate.c
src/netlink.c
src/netlink_delinearize.c
src/netlink_linearize.c
src/rule.c
src/segtree.c

index 15271e5b6d1fe70d918946befedbdc66e3c0025f..854986f2db45db206f604dfb2edd1d415fe2a807 100644 (file)
 #define __must_check           __attribute__((warn_unused_result))
 #define __noreturn             __attribute__((__noreturn__))
 
-#define BUG()                  assert(0)
+#ifdef DEBUG
+#define BUG(fmt, arg...)       ({ fprintf(stderr, "BUG: " fmt, ##arg); assert(0); })
+#else
+#define BUG(fmt, arg...)       assert(0)
+#endif
 
 #define BUILD_BUG_ON(condition)        ((void)sizeof(char[1 - 2*!!(condition)]))
 #define BUILD_BUG_ON_ZERO(e)   (sizeof(char[1 - 2 * !!(e)]) - 1)
index 70670e973b4b196d0086872609e625539d2ccbc9..f369d5f0e8f0ac68e280c0fa124ddd5d769b2985 100644 (file)
@@ -73,7 +73,7 @@ void datatype_print(const struct expr *expr)
                return dtype->print(expr);
        if (dtype->sym_tbl != NULL)
                return symbolic_constant_print(dtype->sym_tbl, expr);
-       BUG();
+       BUG("datatype has no print method or symbol table\n");
 }
 
 struct error_record *symbol_parse(const struct expr *sym,
@@ -184,7 +184,7 @@ static void verdict_type_print(const struct expr *expr)
                printf("return");
                break;
        default:
-               BUG();
+               BUG("invalid verdict value %u\n", expr->verdict);
        }
 }
 
index 554a406c0a9390e74694e11273a0785c1244803d..f2b0ce6622f484d7d3336d5e9812e6a916152278 100644 (file)
@@ -97,7 +97,7 @@ void erec_print(FILE *f, const struct error_record *erec)
        case INDESC_NETLINK:
                break;
        default:
-               BUG();
+               BUG("invalid input descriptor type %u\n", indesc->type);
        }
 
        if (indesc->type == INDESC_NETLINK) {
index ad3cefb9861fa8b6aeab7ddd3dc0ef3b0882ee2a..a2cc8e4576d07ad6b21e9449b1721a2bea16c054 100644 (file)
@@ -142,7 +142,8 @@ static enum ops byteorder_conversion_op(struct expr *expr,
        default:
                break;
        }
-       BUG();
+       BUG("invalid byte order conversion %u => %u\n",
+           expr->byteorder, byteorder);
 }
 
 static int byteorder_conversion(struct eval_ctx *ctx, struct expr **expr,
@@ -239,7 +240,7 @@ static int expr_evaluate_value(struct eval_ctx *ctx, struct expr **expr)
                }
                break;
        default:
-               BUG();
+               BUG("invalid basetype %s\n", expr_basetype(*expr)->name);
        }
        return 0;
 }
@@ -397,7 +398,7 @@ static int expr_evaluate_unary(struct eval_ctx *ctx, struct expr **expr)
                byteorder = BYTEORDER_HOST_ENDIAN;
                break;
        default:
-               BUG();
+               BUG("invalid unary operation %u\n", unary->op);
        }
 
        unary->dtype     = arg->dtype;
@@ -447,7 +448,7 @@ static int constant_binop_simplify(struct eval_ctx *ctx, struct expr **expr)
                mpz_rshift_ui(val, mpz_get_uint32(right->value));
                break;
        default:
-               BUG();
+               BUG("invalid binary operation %u\n", op->op);
        }
 
        new = constant_expr_alloc(&op->location, op->dtype, op->byteorder,
@@ -563,7 +564,7 @@ static int expr_evaluate_binop(struct eval_ctx *ctx, struct expr **expr)
        case OP_OR:
                return expr_evaluate_bitwise(ctx, expr);
        default:
-               BUG();
+               BUG("invalid binary operation %u\n", op->op);
        }
 }
 
@@ -687,7 +688,8 @@ static int expr_evaluate_map(struct eval_ctx *ctx, struct expr **expr)
                                          "Expression is not a map");
                break;
        default:
-               BUG();
+               BUG("invalid mapping expression %s\n",
+                   map->mappings->ops->name);
        }
 
        map->dtype = ctx->ectx.dtype;
@@ -766,7 +768,7 @@ static int binop_transfer_one(struct eval_ctx *ctx,
                                            *right, expr_get(left->right));
                break;
        default:
-               BUG();
+               BUG("invalid binary operation %u\n", left->op);
        }
 
        return expr_evaluate(ctx, right);
@@ -916,7 +918,7 @@ static int expr_evaluate_relational(struct eval_ctx *ctx, struct expr **expr)
                                return -1;
                        break;
                default:
-                       BUG();
+                       BUG("invalid expression type %s\n", right->ops->name);
                }
                break;
        case OP_LT:
@@ -981,7 +983,7 @@ range:
                        return -1;
                break;
        default:
-               BUG();
+               BUG("invalid relational operation %u\n", rel->op);
        }
 
        if (binop_transfer(ctx, expr) < 0)
@@ -1035,7 +1037,7 @@ static int expr_evaluate(struct eval_ctx *ctx, struct expr **expr)
        case EXPR_RELATIONAL:
                return expr_evaluate_relational(ctx, expr);
        default:
-               BUG();
+               BUG("unknown expression type %s\n", (*expr)->ops->name);
        }
 }
 
@@ -1059,7 +1061,7 @@ static int stmt_evaluate_verdict(struct eval_ctx *ctx, struct stmt *stmt)
        case EXPR_MAP:
                break;
        default:
-               BUG();
+               BUG("invalid verdict expression %s\n", stmt->expr->ops->name);
        }
        return 0;
 }
@@ -1135,7 +1137,7 @@ static int stmt_evaluate(struct eval_ctx *ctx, struct stmt *stmt)
        case STMT_NAT:
                return stmt_evaluate_nat(ctx, stmt);
        default:
-               BUG();
+               BUG("unknown statement type %s\n", stmt->ops->name);
        }
 }
 
@@ -1259,7 +1261,7 @@ static int cmd_evaluate_add(struct eval_ctx *ctx, struct cmd *cmd)
                        return 0;
                return table_evaluate(ctx, cmd->table);
        default:
-               BUG();
+               BUG("invalid command object type %u\n", cmd->obj);
        }
 }
 
@@ -1274,7 +1276,7 @@ static int cmd_evaluate_delete(struct eval_ctx *ctx, struct cmd *cmd)
        case CMD_OBJ_TABLE:
                return 0;
        default:
-               BUG();
+               BUG("invalid command object type %u\n", cmd->obj);
        }
 }
 
@@ -1298,7 +1300,7 @@ static int cmd_evaluate(struct eval_ctx *ctx, struct cmd *cmd)
        case CMD_FLUSH:
                return 0;
        default:
-               BUG();
+               BUG("invalid command operation %u\n", cmd->op);
        };
 }
 
index 764d9fad2bfeca9dc26e83ba95c6917fc51c07cf..912dfd5baecb3576b6af7fc0da9ed4f4fd8e4b07 100644 (file)
@@ -246,7 +246,7 @@ struct nfnl_nft_data *netlink_gen_data(const struct expr *expr)
        case EXPR_VERDICT:
                return netlink_gen_verdict(expr);
        default:
-               BUG();
+               BUG("invalid data expression type %s\n", expr->ops->name);
        }
 }
 
index 1963966cbaaf6155c2369eebd49ff035a77094e2..4e267b87dcbff70cd70a0a2f874269227b9982e5 100644 (file)
@@ -250,7 +250,8 @@ static void netlink_parse_byteorder(struct netlink_parse_ctx *ctx,
                op = OP_HTON;
                break;
        default:
-               BUG();
+               BUG("invalid byteorder operation %u\n",
+                   nfnl_nft_byteorder_get_op(nle));
        }
 
        expr = unary_expr_alloc(loc, op, arg);
@@ -639,8 +640,7 @@ static void expr_postprocess(struct rule_pp_ctx *ctx,
        case EXPR_VERDICT:
                break;
        default:
-               printf("%s\n", expr->ops->name);
-               BUG();
+               BUG("unknown expression type %s\n", expr->ops->name);
        }
 }
 
index 18315bdf708b69011a8c6a45a9476b191593ca5d..cfd669157768aca61099f2b7d3042f46a79626fa 100644 (file)
@@ -25,7 +25,7 @@ struct netlink_linearize_ctx {
 static enum nft_registers get_register(struct netlink_linearize_ctx *ctx)
 {
        if (ctx->reg_low > NFT_REG_MAX)
-               BUG();
+               BUG("register reg_low %u invalid\n", ctx->reg_low);
        return ctx->reg_low++;
 }
 
@@ -164,7 +164,7 @@ static enum nft_cmp_ops netlink_gen_cmp_op(enum ops op)
        case OP_GTE:
                return NFT_CMP_GTE;
        default:
-               BUG();
+               BUG("invalid comparison operation %u\n", op);
        }
 }
 
@@ -274,7 +274,7 @@ static void netlink_gen_relational(struct netlink_linearize_ctx *ctx,
        case OP_LOOKUP:
                return netlink_gen_lookup(ctx, expr, dreg);
        default:
-               BUG();
+               BUG("invalid relational operation %u\n", expr->op);
        }
 }
 
@@ -331,7 +331,7 @@ static void netlink_gen_binop(struct netlink_linearize_ctx *ctx,
                        combine_binop(mask, xor, tmp, val);
                        break;
                default:
-                       BUG();
+                       BUG("invalid binary operation %u\n", i->op);
                }
        }
 
@@ -364,7 +364,7 @@ static enum nft_byteorder_ops netlink_gen_unary_op(enum ops op)
        case OP_NTOH:
                return NFT_BYTEORDER_HTON;
        default:
-               BUG();
+               BUG("invalid unary operation %u\n", op);
        }
 }
 
@@ -424,7 +424,7 @@ static void netlink_gen_expr(struct netlink_linearize_ctx *ctx,
        case EXPR_CT:
                return netlink_gen_ct(ctx, expr, dreg);
        default:
-               BUG();
+               BUG("unknown expression type %s\n", expr->ops->name);
        }
 }
 
@@ -571,7 +571,7 @@ static void netlink_gen_stmt(struct netlink_linearize_ctx *ctx,
        case STMT_NAT:
                return netlink_gen_nat_stmt(ctx, stmt);
        default:
-               BUG();
+               BUG("unknown statement type %s\n", stmt->ops->name);
        }
 }
 
index 3bf48aac72ff058935ffc8c6bab5514d75303a88..e90e6179fbc7ec0e0839052db3c9ae91e3e057db 100644 (file)
@@ -329,7 +329,7 @@ void cmd_free(struct cmd *cmd)
                        table_free(cmd->table);
                        break;
                default:
-                       BUG();
+                       BUG("invalid command object type %u\n", cmd->obj);
                }
        }
        xfree(cmd);
@@ -411,7 +411,7 @@ static int do_command_add(struct netlink_ctx *ctx, struct cmd *cmd)
        case CMD_OBJ_SETELEM:
                return do_add_setelems(ctx, &cmd->handle, cmd->expr);
        default:
-               BUG();
+               BUG("invalid command object type %u\n", cmd->obj);
        }
        return 0;
 }
@@ -430,7 +430,7 @@ static int do_command_delete(struct netlink_ctx *ctx, struct cmd *cmd)
        case CMD_OBJ_SETELEM:
                return netlink_delete_setelems(ctx, &cmd->handle, cmd->expr);
        default:
-               BUG();
+               BUG("invalid command object type %u\n", cmd->obj);
        }
 }
 
@@ -493,7 +493,7 @@ static int do_command_list(struct netlink_ctx *ctx, struct cmd *cmd)
                }
                return 0;
        default:
-               BUG();
+               BUG("invalid command object type %u\n", cmd->obj);
        }
 
        list_for_each_entry_safe(rule, nrule, &ctx->list, list) {
@@ -519,7 +519,7 @@ static int do_command_flush(struct netlink_ctx *ctx, struct cmd *cmd)
        case CMD_OBJ_CHAIN:
                return netlink_flush_chain(ctx, &cmd->handle);
        default:
-               BUG();
+               BUG("invalid command object type %u\n", cmd->obj);
        }
        return 0;
 }
@@ -536,7 +536,7 @@ int do_command(struct netlink_ctx *ctx, struct cmd *cmd)
        case CMD_FLUSH:
                return do_command_flush(ctx, cmd);
        default:
-               BUG();
+               BUG("invalid command object type %u\n", cmd->obj);
        }
 }
 
index fb404a431f7db5dd125752ffa5eb60a041c6eeae..216e4588e047a498d34a64d60618638afe049ba6 100644 (file)
@@ -246,7 +246,7 @@ static void range_low(mpz_t rop, struct expr *expr)
        case EXPR_MAPPING:
                return range_low(rop, expr->left);
        default:
-               BUG();
+               BUG("invalid range expression type %s\n", expr->ops->name);
        }
 }
 
@@ -268,7 +268,7 @@ static void range_high(mpz_t rop, const struct expr *expr)
        case EXPR_MAPPING:
                return range_high(rop, expr->left);
        default:
-               BUG();
+               BUG("invalid range expression type %s\n", expr->ops->name);
        }
 }