------------------------------------------------------------ revno: 6368 committer: Diego Biurrun <diego@xxxxxxxxxx> branch nick: hipl timestamp: Mon 2012-04-16 16:55:53 +0200 message: hipfw: Eliminate particularly silly use of goto in fw_init_context(). modified: hipfw/hipfw.c -- lp:hipl https://code.launchpad.net/~hipl-core/hipl/trunk Your team HIPL core team is subscribed to branch lp:hipl. To unsubscribe from this branch go to https://code.launchpad.net/~hipl-core/hipl/trunk/+edit-subscription
=== modified file 'hipfw/hipfw.c' --- hipfw/hipfw.c 2012-04-16 14:54:37 +0000 +++ hipfw/hipfw.c 2012-04-16 14:55:53 +0000 @@ -1324,9 +1324,7 @@ // check if packet is to big for the buffer if (ctx->ipq_packet->data_len > HIP_MAX_PACKET) { HIP_ERROR("packet size greater than buffer\n"); - - err = 1; - goto end_init; + return 1; } ctx->ip_version = ip_version; @@ -1364,7 +1362,7 @@ ctx->transport_hdr.hip = (struct hip_common *) (((char *) iphdr) + ctx->ip_hdr_len); - goto end_init; + return err; } else if (iphdr->ip_p == IPPROTO_ESP) { // this is an ESP packet HIP_DEBUG("plain ESP packet\n"); @@ -1373,12 +1371,12 @@ ctx->transport_hdr.esp = (struct hip_esp *) (((char *) iphdr) + ctx->ip_hdr_len); - goto end_init; + return err; } else if (iphdr->ip_p != IPPROTO_UDP) { // if it's not UDP either, it's unsupported HIP_DEBUG("some other packet\n"); - goto end_init; + return err; } // need UDP header to look for encapsulated ESP @@ -1419,7 +1417,7 @@ ctx->transport_hdr.hip = (struct hip_common *) (((char *) ip6_hdr) + sizeof(struct ip6_hdr)); - goto end_init; + return err; } else if (ip6_hdr->ip6_nxt == IPPROTO_ESP) { // we have found a plain ESP packet HIP_DEBUG("plain ESP packet\n"); @@ -1428,12 +1426,12 @@ ctx->transport_hdr.esp = (struct hip_esp *) (((char *) ip6_hdr) + sizeof(struct ip6_hdr)); - goto end_init; + return err; } else if (ip6_hdr->ip6_nxt != IPPROTO_UDP) { // if it's not UDP either, it's unsupported HIP_DEBUG("some other packet\n"); - goto end_init; + return err; } /* for now these calculations are not necessary as UDP encapsulation @@ -1451,7 +1449,7 @@ ctx->udp_encap_hdr = udphdr; } else { HIP_DEBUG("neither ipv4 nor ipv6\n"); - goto end_init; + return err; } HIP_DEBUG("UDP header size is %d (in header: %u)\n", @@ -1484,7 +1482,7 @@ // only UDP header + payload < 32 bit -> neither HIP nor ESP HIP_DEBUG("UDP packet with < 32 bit payload\n"); - goto end_init; + return err; } } @@ -1507,7 +1505,7 @@ + sizeof(struct udphdr) + HIP_UDP_ZERO_BYTES_LEN); - goto end_init; + return err; } HIP_ERROR("communicating with BROKEN peer implementation of UDP encapsulation," " found zero bytes when receiving HIP control message\n"); @@ -1526,13 +1524,12 @@ ctx->transport_hdr.esp = (struct hip_esp *) (((char *) udphdr) + sizeof(struct udphdr)); - goto end_init; + return err; } else { /* normal UDP packet or UDP encapsulated IPv6 */ HIP_DEBUG("normal UDP packet\n"); } -end_init: return err; }