Exit if too big
This commit is contained in:
parent
504fa7f2df
commit
5d8bd6b435
2 changed files with 18 additions and 3 deletions
|
@ -205,6 +205,8 @@ int algo_rr_on_datagram(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo
|
||||||
struct evt_core_fdinfo *to_fdinfo = NULL;
|
struct evt_core_fdinfo *to_fdinfo = NULL;
|
||||||
uint16_t min_pkt;
|
uint16_t min_pkt;
|
||||||
char url[255];
|
char url[255];
|
||||||
|
size_t health_packet_size = sizeof(bp->ip.ap.fmt.headers) - sizeof(bp->ip.ap.fmt.content.health);
|
||||||
|
size_t max_size = sizeof(struct internet_packet) - health_packet_size;
|
||||||
|
|
||||||
if (ctx->verbose > 1) fprintf(stderr, " [algo/rr] Read a UDP packet on URL %s\n", fdinfo->url);
|
if (ctx->verbose > 1) fprintf(stderr, " [algo/rr] Read a UDP packet on URL %s\n", fdinfo->url);
|
||||||
|
|
||||||
|
@ -230,13 +232,24 @@ int algo_rr_on_datagram(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo
|
||||||
bp->ip.ap.fmt.content.clear.id = rr->sent_content_id;
|
bp->ip.ap.fmt.content.clear.id = rr->sent_content_id;
|
||||||
min_pkt = rr->sent_content_id;
|
min_pkt = rr->sent_content_id;
|
||||||
rr->sent_content_id++;
|
rr->sent_content_id++;
|
||||||
|
if (bp->ip.ap.fmt.headers.size > max_size) {
|
||||||
|
fprintf(stderr, "Packet is too big to be relayed. Oops...\n");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
// 4. Append redundancy if needed
|
// 4. Append redundancy if needed
|
||||||
if (app_ctx->ap.redundant_data == 1) {
|
if (app_ctx->ap.redundant_data == 1) {
|
||||||
|
size_t current_size = get_full_size (bp);
|
||||||
|
size_t final_size = current_size + rr->prev_packet.ap.fmt.headers.size;
|
||||||
|
if (final_size <= max_size) {
|
||||||
min_pkt = rr->prev_packet.ap.fmt.content.clear.id;
|
min_pkt = rr->prev_packet.ap.fmt.content.clear.id;
|
||||||
append_buffer(&bp->ip.ap, bp->ap_count, &rr->prev_packet.ap); // We append previous packet
|
append_buffer(&bp->ip.ap, bp->ap_count, &rr->prev_packet.ap); // We append previous packet
|
||||||
append_buffer(&rr->prev_packet.ap, 0, &bp->ip.ap); // We store current packet for next time
|
|
||||||
bp->ap_count++;
|
bp->ap_count++;
|
||||||
|
} else if (ctx->verbose) {
|
||||||
|
fprintf(stderr, " [algo/rr] Can't append redundancy (current=%ld, after=%ld, max=%ld)\n", current_size, final_size, max_size);
|
||||||
|
}
|
||||||
|
|
||||||
|
append_buffer(&rr->prev_packet.ap, 0, &bp->ip.ap); // We store current packet for next time
|
||||||
}
|
}
|
||||||
|
|
||||||
// 5. Append health packet
|
// 5. Append health packet
|
||||||
|
|
|
@ -80,6 +80,8 @@ struct udp_target {
|
||||||
int ref_count;
|
int ref_count;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
size_t get_full_size(struct buffer_packet* bp);
|
||||||
|
|
||||||
enum FD_STATE read_packet_from_tcp(int fd, struct buffer_packet* bp);
|
enum FD_STATE read_packet_from_tcp(int fd, struct buffer_packet* bp);
|
||||||
enum FD_STATE write_packet_to_tcp(int fd, struct buffer_packet* bp);
|
enum FD_STATE write_packet_to_tcp(int fd, struct buffer_packet* bp);
|
||||||
enum FD_STATE write_packet_to_udp(int fd, struct buffer_packet* bp, struct udp_target* udp_t);
|
enum FD_STATE write_packet_to_udp(int fd, struct buffer_packet* bp, struct udp_target* udp_t);
|
||||||
|
|
Loading…
Reference in a new issue