Exemple #1
0
/**
 * Build ce->resp and ce->resp->msg that it can be sent via TCP socket.
 *
 * Cache entry data is set as paged fragments of skb.
 * See do_tcp_sendpages() as reference.
 *
 * We return skbs in the cache entry response w/o setting any
 * network headers - tcp_transmit_skb() will do it for us.
 */
static int
tfw_cache_build_resp(TfwCacheEntry *ce)
{
	int f = 0;
	TdbVRec *trec = &ce->trec;
	char *data;
	struct sk_buff *skb = NULL;

	/*
	 * Allocated response won't be checked by any filters and
	 * is used for sending response data only, so don't initialize
	 * connection and GFSM fields.
	 */
	ce->resp = (TfwHttpResp *)tfw_http_msg_alloc(Conn_Srv);
	if (!ce->resp)
		return -ENOMEM;

	/* Deserialize offsets to pointers. */
	ce->key = TDB_PTR(db->hdr, (unsigned long)ce->key);
	ce->hdr_lens = TDB_PTR(db->hdr, (unsigned long)ce->hdr_lens);
	ce->hdrs = TDB_PTR(db->hdr, (unsigned long)ce->hdrs);
	ce->body = TDB_PTR(db->hdr, (unsigned long)ce->body);

	/* See tfw_cache_copy_resp(). */
	BUG_ON((char *)(trec + 1) + trec->len <= ce->hdrs);

	trec = TDB_PTR(db->hdr, TDB_DI2O(trec->chunk_next));
	for (data = ce->hdrs;
	     (long)trec != (long)db->hdr;
	     trec = TDB_PTR(db->hdr, TDB_DI2O(trec->chunk_next)),
		data = trec->data)
	{
		int off, size = trec->len;

		if (!skb || f == MAX_SKB_FRAGS) {
			/* Protocol headers are placed in linear data only. */
			skb = alloc_skb(SKB_HDR_SZ, GFP_ATOMIC);
			if (!skb)
				goto err_skb;
			skb_reserve(skb, SKB_HDR_SZ);
			ss_skb_queue_tail(&ce->resp->msg.skb_list, skb);
			f = 0;
		}

		off = (unsigned long)data & ~PAGE_MASK;
		size = (char *)(trec + 1) + trec->len - data;

		skb_fill_page_desc(skb, f, virt_to_page(data), off, size);

		++f;
	}

	return 0;
err_skb:
	tfw_http_msg_free((TfwHttpMsg *)ce->resp);
	return -ENOMEM;
}
Exemple #2
0
TfwHttpReq *
test_req_alloc(void)
{
	TfwHttpReq *req;

	/* Actually there were more code here, mostly it was copy-paste from
	 * tfw_http_msg_alloc(). It is removed because we need to test how it
	 * initializes the message and we would not like to test the copy-paste.
	 */
	req = (TfwHttpReq *)tfw_http_msg_alloc(Conn_HttpClnt, 0);
	BUG_ON(!req);

	return req;
}