uint16_t pack_hash_value(unsigned char *packet, uint32_t left, uint32_t right) {
    uint16_t bytes_packed = 0;
    pack_buffer(uint16_t, packet, bytes_packed, htons(HASH_HDR | HASH_LEN));
    bytes_packed += 2;

    /* copy the hash into the new packet */
    pack_buffer(uint32_t, packet, bytes_packed, htonl(left));
    bytes_packed += 4;
    pack_buffer(uint32_t, packet, bytes_packed, htonl(right));
    bytes_packed += 4;
    return bytes_packed;
}
Esempio n. 2
0
static errno_t
prepare_response(TALLOC_CTX *mem_ctx,
                 int sysvol_gpt_version,
                 int result,
                 struct response **rsp)
{
    int ret;
    struct response *r = NULL;

    r = talloc_zero(mem_ctx, struct response);
    if (r == NULL) {
        return ENOMEM;
    }

    r->buf = NULL;
    r->size = 0;

    ret = pack_buffer(r, sysvol_gpt_version, result);
    if (ret != EOK) {
        DEBUG(SSSDBG_CRIT_FAILURE, "pack_buffer failed\n");
        return ret;
    }

    *rsp = r;
    DEBUG(SSSDBG_TRACE_ALL, "r->size: %zu\n", r->size);
    return EOK;
}
Esempio n. 3
0
// verify the message received is correct
// construct a buffer based on iteration rank and compare with received buffer
bool check_buffer(char *buffer, int iteration, int datasize, int rank)
{
    char *tmp_buffer = (char *) malloc(datasize);
    pack_buffer(tmp_buffer, iteration, datasize, rank);
    assert(strncmp(buffer, tmp_buffer, datasize) == 0); // compare only upto datasize
    free(tmp_buffer);
    return true;
}
Esempio n. 4
0
static int prepare_response(TALLOC_CTX *mem_ctx,
                            const char *ccname,
                            time_t expire_time,
                            krb5_error_code kerr,
                            struct response **rsp)
{
    int ret;
    struct response *r = NULL;
    const char *krb5_msg = NULL;

    r = talloc_zero(mem_ctx, struct response);
    if (!r) return ENOMEM;

    r->buf = NULL;
    r->size = 0;

    DEBUG(SSSDBG_TRACE_FUNC, ("Building response for result [%d]\n", kerr));

    if (kerr == 0) {
        ret = pack_buffer(r, EOK, kerr, ccname, expire_time);
    } else {
        krb5_msg = sss_krb5_get_error_message(krb5_error_ctx, kerr);
        if (krb5_msg == NULL) {
            DEBUG(SSSDBG_CRIT_FAILURE,
                    ("sss_krb5_get_error_message failed.\n"));
            return ENOMEM;
        }

        ret = pack_buffer(r, EFAULT, kerr, krb5_msg, 0);
        sss_krb5_free_error_message(krb5_error_ctx, krb5_msg);
    }

    if (ret != EOK) {
        DEBUG(1, ("pack_buffer failed\n"));
        return ret;
    }

    *rsp = r;
    return EOK;
}
Esempio n. 5
0
int main(int argc, char** argv) {

    MPI_Init(&argc, &argv);
    // TEST_INIT("goal transform test\n");

    GOAL_Init();

    const int datasize = 8;
    char* send_buffer = (char*) malloc(datasize);
    char* recv_buffer = (char*) malloc(datasize);
    init_buffer(recv_buffer, datasize);

    int rank = GOAL_MyRank();
    int group_size = GOAL_GroupSize();

    // transformation code
    GOAL_Handle hndl;
    GOAL_Graph g = GOAL_Create_graph();

    // inspector code
    // builds the schedule to be executed by GOAL
    GOAL_Send(g, send_buffer, datasize, left_neighbor(rank, group_size));
    GOAL_Recv(g, recv_buffer, datasize, right_neighbor(rank, group_size));
    GOAL_Schedule sched = GOAL_Compile(g);
    GOAL_FreeGraph(g);

     // executor code
     // executes the earlier schedule built by the inspector
     for (int i=0; i<T; i++) {
     	 // contents of the buffer can change
         pack_buffer(send_buffer, i, datasize, rank);
         hndl = GOAL_Run(sched);
         GOAL_ReuseSchedule(sched);
         GOAL_Wait(hndl);
         // verify the contents received
         check_buffer(recv_buffer, i, datasize, right_neighbor(rank, group_size));
         // std::string recv_buff(recv_buffer);
         // std::cout << "rank: " << rank << ", " << recv_buff.substr(0, datasize) << std::endl;
    }

     // std::string recv_buff(recv_buffer);
     // std::cout << "rank: " << rank << ", " << recv_buff.substr(0, datasize) << std::endl;

    GOAL_Finalize();
    MPI_Finalize();

    return 0;
}
int build_advertisement(struct nfq_data* buf, int *size) {
    printlog(logfile, system_loglevel, LOG_DEBUG, "******* Building"
            " advertisement**********\n");
    // extract the headers of the packet
    struct nfqnl_msg_packet_hdr *ph;
    ph = nfq_get_msg_packet_hdr(buf);
    int id = ntohl(ph->packet_id);

    unsigned char *pkt_ptr = NULL;
    /* get the packet from ip header onwards */
    if(nfq_get_payload(buf, (char **)&pkt_ptr) == -1) {
        printlog(logfile, system_loglevel, LOG_CRITICAL,
        "Deduplication code invoked without the packet\n");
    }
    
    struct ip *ip_hdr = (struct ip *)pkt_ptr;
    uint32_t size_ip = 4 * ip_hdr->ip_hl;

    if (size_ip < 20) {
        printlog(logfile, system_loglevel, LOG_CRITICAL, "* Invalid "
                "IP header length: %u bytes\n", size_ip);
        *size = ntohs(ip_hdr->ip_len);
        return id;
    }

    if(ip_hdr->ip_p != IP_PROTO_TCP) {
        printlog(logfile, system_loglevel, LOG_WARN, "Received a "
                "non TCP packet\n");
        *size = ntohs(ip_hdr->ip_len);
        return id;
    }

    /* get to the IP payload */
    struct tcphdr *tcp_hdr = (struct tcphdr *)(pkt_ptr + size_ip);
    int size_tcp = 4 * tcp_hdr->doff;

    /* get to the TCP payload */
    unsigned char *payload = (unsigned char *)(pkt_ptr + size_ip +
            size_tcp);
    uint16_t payload_len = ntohs(ip_hdr->ip_len) - size_ip - size_tcp;
    if(payload_len != 0) {
        *size = ntohs(ip_hdr->ip_len);
        return id;
    }

    printlog(logfile, system_loglevel, LOG_DEBUG, "Length parameters,"
            "ip_len: %d, size_ip: %d, size_tcp: %d, payload_len:"
            "%d\n", ntohs(ip_hdr->ip_len), size_ip, size_tcp, payload_len);
    uint64_t hash_value = 0;
    uint32_t left = 0, right = 0;
    uint16_t new_payload_len = 0;
    for(set<uint64_t>::iterator it = advertise_hashes.begin(); it !=
        advertise_hashes.end(); it++) {
        hash_value = (*it);
        printlog(logfile, system_loglevel, LOG_DEBUG, 
                "Advertising %llx\n", hash_value);
        right = (uint32_t)(hash_value & 0x00000000ffffffff);
        left = (uint32_t)(hash_value >> 32);
        assert(hash_value == (right + (((uint64_t)left)<<32)));
        pack_buffer(uint32_t, payload, new_payload_len, htonl(left));
        new_payload_len += 4;
        pack_buffer(uint32_t, payload, new_payload_len, htonl(right));
        new_payload_len += 4;
    }

    ip_hdr->ip_p = ADVERT_PROT;
    *size = new_payload_len + size_ip + size_tcp;
    ip_hdr->ip_len = htons(*size);
    ip_hdr->ip_sum = ip_header_checksum((uint16_t *)ip_hdr, sizeof(struct ip));
    return id;
}