libcoap 4.3.5-develop-4c7ce99
Loading...
Searching...
No Matches
coap_proxy.c
Go to the documentation of this file.
1/* coap_proxy.c -- helper functions for proxy handling
2 *
3 * Copyright (C) 2024-2025 Jon Shallow <supjps-libcoap@jpshallow.com>
4 *
5 * SPDX-License-Identifier: BSD-2-Clause
6 *
7 * This file is part of the CoAP library libcoap. Please see
8 * README for terms of use.
9 */
10
17
18#if COAP_PROXY_SUPPORT
19#include <stdio.h>
20
21#if COAP_CLIENT_SUPPORT == 0
22#error For Proxy support, COAP_CLIENT_SUPPORT must be set
23#endif
24#if COAP_SERVER_SUPPORT == 0
25#error For Proxy support, COAP_SERVER_SUPPORT must be set
26#endif
27
28#ifdef _WIN32
29#define strcasecmp _stricmp
30#define strncasecmp _strnicmp
31#endif
32
33int
35 return 1;
36}
37
38void
40 size_t i;
41 size_t j;
42
43 for (i = 0; i < context->proxy_list_count; i++) {
44 for (j = 0; j < context->proxy_list[i].req_count; j++) {
45 coap_delete_pdu_lkd(context->proxy_list[i].req_list[j].pdu);
46 coap_delete_cache_key(context->proxy_list[i].req_list[j].cache_key);
47 }
48 coap_free_type(COAP_STRING, context->proxy_list[i].req_list);
49 coap_free_type(COAP_STRING, context->proxy_list[i].uri_host_keep);
50 }
51 coap_free_type(COAP_STRING, context->proxy_list);
52}
53
54/*
55 * return 1 if there is a future expire time, else 0.
56 * update tim_rem with remaining value if return is 1.
57 */
58int
60 coap_tick_t *tim_rem) {
61 size_t i;
62 int ret = 0;
63
64 *tim_rem = -1;
65 for (i = 0; i < context->proxy_list_count; i++) {
66 coap_proxy_list_t *proxy_list = &context->proxy_list[i];
67
68 if (proxy_list->ongoing && proxy_list->idle_timeout_ticks) {
69 if (proxy_list->last_used + proxy_list->idle_timeout_ticks <= now) {
70 /* Drop session to upstream server */
72 proxy_list->ongoing = NULL;
73 } else {
74 if (*tim_rem > proxy_list->last_used + proxy_list->idle_timeout_ticks - now) {
75 *tim_rem = proxy_list->last_used + proxy_list->idle_timeout_ticks - now;
76 }
77 ret = 1;
78 }
79 }
80 }
81 return ret;
82}
83
84static int
85coap_get_uri_proxy_scheme_info(const coap_pdu_t *request,
86 coap_opt_t *opt,
87 coap_uri_t *uri) {
88 const char *opt_val = (const char *)coap_opt_value(opt);
89 int opt_len = coap_opt_length(opt);
90 coap_opt_iterator_t opt_iter;
91
92 if (opt_len == 9 &&
93 strncasecmp(opt_val, "coaps+tcp", 9) == 0) {
96 } else if (opt_len == 8 &&
97 strncasecmp(opt_val, "coap+tcp", 8) == 0) {
100 } else if (opt_len == 5 &&
101 strncasecmp(opt_val, "coaps", 5) == 0) {
104 } else if (opt_len == 4 &&
105 strncasecmp(opt_val, "coap", 4) == 0) {
107 uri->port = COAP_DEFAULT_PORT;
108 } else if (opt_len == 7 &&
109 strncasecmp(opt_val, "coap+ws", 7) == 0) {
111 uri->port = 80;
112 } else if (opt_len == 8 &&
113 strncasecmp(opt_val, "coaps+ws", 8) == 0) {
115 uri->port = 443;
116 } else {
117 coap_log_warn("Unsupported Proxy Scheme '%*.*s'\n",
118 opt_len, opt_len, opt_val);
119 return 0;
120 }
121
122 opt = coap_check_option(request, COAP_OPTION_URI_HOST, &opt_iter);
123 if (opt) {
124 uri->host.length = coap_opt_length(opt);
125 uri->host.s = coap_opt_value(opt);
126 } else {
127 uri->host.s = NULL;
128 uri->host.length = 0;
129 coap_log_warn("Proxy Scheme requires Uri-Host\n");
130 return 0;
131 }
132 opt = coap_check_option(request, COAP_OPTION_URI_PORT, &opt_iter);
133 if (opt) {
134 uri->port =
136 coap_opt_length(opt));
137 }
138 return 1;
139}
140
141int
143
144 /* Sanity check that the connection can be forwarded on */
145 switch (scheme) {
148 coap_log_warn("Proxy URI http or https not supported\n");
149 return 0;
151 break;
153 if (!coap_dtls_is_supported()) {
154 coap_log_warn("coaps URI scheme not supported for proxy\n");
155 return 0;
156 }
157 break;
159 if (!coap_tcp_is_supported()) {
160 coap_log_warn("coap+tcp URI scheme not supported for proxy\n");
161 return 0;
162 }
163 break;
165 if (!coap_tls_is_supported()) {
166 coap_log_warn("coaps+tcp URI scheme not supported for proxy\n");
167 return 0;
168 }
169 break;
171 if (!coap_ws_is_supported()) {
172 coap_log_warn("coap+ws URI scheme not supported for proxy\n");
173 return 0;
174 }
175 break;
177 if (!coap_wss_is_supported()) {
178 coap_log_warn("coaps+ws URI scheme not supported for proxy\n");
179 return 0;
180 }
181 break;
183 default:
184 coap_log_warn("%d URI scheme not supported\n", scheme);
185 return 0;
186 }
187 return 1;
188}
189
190static coap_proxy_list_t *
191coap_proxy_get_session(coap_session_t *session, const coap_pdu_t *request,
192 coap_pdu_t *response,
193 coap_proxy_server_list_t *server_list,
194 coap_proxy_server_t *server_use) {
195 size_t i;
196 coap_proxy_list_t *new_proxy_list;
197 coap_proxy_list_t *proxy_list = session->context->proxy_list;
198 size_t proxy_list_count = session->context->proxy_list_count;
199
200 coap_opt_iterator_t opt_iter;
201 coap_opt_t *proxy_scheme;
202 coap_opt_t *proxy_uri;
203
204 /* Round robin the defined next server list (which usually is just one */
205 server_list->next_entry++;
206 if (server_list->next_entry >= server_list->entry_count)
207 server_list->next_entry = 0;
208
209 if (server_list->entry_count) {
210 memcpy(server_use, &server_list->entry[server_list->next_entry], sizeof(*server_use));
211 } else {
212 memset(server_use, 0, sizeof(*server_use));
213 }
214
215 switch (server_list->type) {
220 /* Nothing else needs to be done here */
221 break;
224 /* Need to get actual server from CoAP Proxy-Uri or Proxy-Scheme options */
225 /*
226 * See if Proxy-Scheme
227 */
228 proxy_scheme = coap_check_option(request, COAP_OPTION_PROXY_SCHEME, &opt_iter);
229 if (proxy_scheme) {
230 if (!coap_get_uri_proxy_scheme_info(request, proxy_scheme, &server_use->uri)) {
231 response->code = COAP_RESPONSE_CODE(505);
232 return NULL;
233 }
234 }
235 /*
236 * See if Proxy-Uri
237 */
238 proxy_uri = coap_check_option(request, COAP_OPTION_PROXY_URI, &opt_iter);
239 if (proxy_uri) {
240 coap_log_info("Proxy URI '%.*s'\n",
241 (int)coap_opt_length(proxy_uri),
242 (const char *)coap_opt_value(proxy_uri));
244 coap_opt_length(proxy_uri),
245 &server_use->uri) < 0) {
246 /* Need to return a 5.05 RFC7252 Section 5.7.2 */
247 coap_log_warn("Proxy URI not decodable\n");
248 response->code = COAP_RESPONSE_CODE(505);
249 return NULL;
250 }
251 }
252
253 if (!(proxy_scheme || proxy_uri)) {
254 response->code = COAP_RESPONSE_CODE(404);
255 return NULL;
256 }
257 break;
258 default:
259 assert(0);
260 return NULL;
261 }
262
263 if (server_use->uri.host.length == 0) {
264 /* Ongoing connection not well formed */
265 response->code = COAP_RESPONSE_CODE(505);
266 return NULL;
267 }
268
270 response->code = COAP_RESPONSE_CODE(505);
271 return NULL;
272 }
273
274 /* See if we are already connected to the Server */
275 for (i = 0; i < proxy_list_count; i++) {
276 if (coap_string_equal(&proxy_list[i].uri.host, &server_use->uri.host) &&
277 proxy_list[i].uri.port == server_use->uri.port &&
278 proxy_list[i].uri.scheme == server_use->uri.scheme) {
279 if (!server_list->track_client_session) {
280 coap_ticks(&proxy_list[i].last_used);
281 return &proxy_list[i];
282 } else {
283 if (proxy_list[i].incoming == session) {
284 coap_ticks(&proxy_list[i].last_used);
285 return &proxy_list[i];
286 }
287 }
288 }
289 }
290
291 /* Need to create a new forwarding mapping */
292 new_proxy_list = coap_realloc_type(COAP_STRING, proxy_list, (i+1)*sizeof(proxy_list[0]));
293
294 if (new_proxy_list == NULL) {
295 response->code = COAP_RESPONSE_CODE(500);
296 return NULL;
297 }
298 session->context->proxy_list = proxy_list = new_proxy_list;
299 memset(&proxy_list[i], 0, sizeof(proxy_list[i]));
300
301 /* Keep a copy of the host as server_use->uri pointed to will be going away */
302 proxy_list[i].uri = server_use->uri;
304 server_use->uri.host.length);
305 if (!proxy_list[i].uri_host_keep) {
306 response->code = COAP_RESPONSE_CODE(500);
307 return NULL;
308 }
309 memcpy(proxy_list[i].uri_host_keep, server_use->uri.host.s,
310 server_use->uri.host.length);
311 proxy_list[i].uri.host.s = proxy_list[i].uri_host_keep;
312 /* Unset uri parts which point to going away information */
313 proxy_list[i].uri.path.s = NULL;
314 proxy_list[i].uri.path.length = 0;
315 proxy_list[i].uri.query.s = NULL;
316 proxy_list[i].uri.query.length = 0;
317
318 if (server_list->track_client_session) {
319 proxy_list[i].incoming = session;
320 }
321 session->context->proxy_list_count++;
322 proxy_list[i].idle_timeout_ticks = server_list->idle_timeout_secs * COAP_TICKS_PER_SECOND;
323 coap_ticks(&proxy_list[i].last_used);
324 return &proxy_list[i];
325}
326
327void
328coap_proxy_remove_association(coap_session_t *session, int send_failure) {
329
330 size_t i;
331 size_t j;
332 coap_proxy_list_t *proxy_list = session->context->proxy_list;
333 size_t proxy_list_count = session->context->proxy_list_count;
334
335 for (i = 0; i < proxy_list_count; i++) {
336 /* Check for incoming match */
337 for (j = 0; j < proxy_list[i].req_count; j++) {
338 if (proxy_list[i].req_list[j].incoming == session) {
339 coap_delete_pdu_lkd(proxy_list[i].req_list[j].pdu);
340 coap_delete_bin_const(proxy_list[i].req_list[j].token_used);
341 coap_delete_cache_key(proxy_list[i].req_list[j].cache_key);
342 if (proxy_list[i].req_count-j > 1) {
343 memmove(&proxy_list[i].req_list[j], &proxy_list[i].req_list[j+1],
344 (proxy_list[i].req_count-j-1) * sizeof(proxy_list[i].req_list[0]));
345 }
346 proxy_list[i].req_count--;
347 break;
348 }
349 }
350 if (proxy_list[i].incoming == session) {
351 /* Only if there is a one-to-one tracking */
352 coap_session_release_lkd(proxy_list[i].ongoing);
353 break;
354 }
355
356 /* Check for outgoing match */
357 if (proxy_list[i].ongoing == session) {
358 coap_session_t *ongoing;
359
360 for (j = 0; j < proxy_list[i].req_count; j++) {
361 if (send_failure) {
362 coap_pdu_t *response;
363 coap_bin_const_t l_token;
364
365 /* Need to send back a gateway failure */
366 response = coap_pdu_init(proxy_list[i].req_list[j].pdu->type,
368 coap_new_message_id_lkd(proxy_list[i].incoming),
369 coap_session_max_pdu_size_lkd(proxy_list[i].incoming));
370 if (!response) {
371 coap_log_info("PDU creation issue\n");
372 goto cleanup;
373 }
374
375 l_token = coap_pdu_get_token(proxy_list[i].req_list[j].pdu);
376 if (!coap_add_token(response, l_token.length,
377 l_token.s)) {
378 coap_log_debug("Cannot add token to incoming proxy response PDU\n");
379 }
380
381 if (coap_send_lkd(proxy_list[i].incoming, response) == COAP_INVALID_MID) {
382 coap_log_info("Failed to send PDU with 5.02 gateway issue\n");
383 }
384cleanup:
385 coap_delete_pdu_lkd(proxy_list[i].req_list[j].pdu);
386 coap_delete_bin_const(proxy_list[i].req_list[j].token_used);
387 coap_delete_cache_key(proxy_list[i].req_list[j].cache_key);
388 }
389 }
390 ongoing = proxy_list[i].ongoing;
391 coap_free_type(COAP_STRING, proxy_list[i].req_list);
392 if (proxy_list_count-i > 1) {
393 memmove(&proxy_list[i],
394 &proxy_list[i+1],
395 (proxy_list_count-i-1) * sizeof(proxy_list[0]));
396 }
397 session->context->proxy_list_count--;
399 break;
400 }
401 }
402}
403
404static coap_proxy_list_t *
405coap_proxy_get_ongoing_session(coap_session_t *session,
406 const coap_pdu_t *request,
407 coap_pdu_t *response,
408 coap_proxy_server_list_t *server_list) {
409
410 coap_address_t dst;
411 coap_proto_t proto;
412 coap_addr_info_t *info_list = NULL;
413 coap_proxy_list_t *proxy_entry;
414 coap_context_t *context = session->context;
415 static char client_sni[256];
416 coap_proxy_server_t server_use;
417
418 proxy_entry = coap_proxy_get_session(session, request, response, server_list,
419 &server_use);
420 if (!proxy_entry) {
421 /* Error response code already set */
422 return NULL;
423 }
424
425 if (!proxy_entry->ongoing) {
426 /* Need to create a new session */
427 coap_address_t *local_addr = NULL;
428
429 /* resolve destination address where data should be sent */
430 info_list = coap_resolve_address_info(&server_use.uri.host,
431 server_use.uri.port,
432 server_use.uri.port,
433 server_use.uri.port,
434 server_use.uri.port,
435 0,
436 1 << server_use.uri.scheme,
438
439 if (info_list == NULL) {
440 response->code = COAP_RESPONSE_CODE(502);
442 return NULL;
443 }
444 proto = info_list->proto;
445 memcpy(&dst, &info_list->addr, sizeof(dst));
446 coap_free_address_info(info_list);
447
448#if COAP_AF_UNIX_SUPPORT
449 coap_address_t bind_addr;
450 if (coap_is_af_unix(&dst)) {
451 char buf[COAP_UNIX_PATH_MAX];
452
453 /* Need a unique 'client' address */
454 snprintf(buf, COAP_UNIX_PATH_MAX,
455 "/tmp/coap-proxy-client");
456 if (!coap_address_set_unix_domain(&bind_addr, (const uint8_t *)buf,
457 strlen(buf))) {
458 fprintf(stderr, "coap_address_set_unix_domain: %s: failed\n",
459 buf);
460 remove(buf);
461 return NULL;
462 }
463 (void)remove(buf);
464 local_addr = &bind_addr;
465 }
466#endif /* COAP_AF_UNIX_SUPPORT */
467
468 snprintf(client_sni, sizeof(client_sni), "%*.*s", (int)server_use.uri.host.length,
469 (int)server_use.uri.host.length, server_use.uri.host.s);
470
471 switch (server_use.uri.scheme) {
475#if COAP_OSCORE_SUPPORT
476 if (server_use.oscore_conf) {
477 proxy_entry->ongoing =
478 coap_new_client_session_oscore_lkd(context, local_addr, &dst,
479 proto, server_use.oscore_conf);
480 } else {
481#endif /* COAP_OSCORE_SUPPORT */
482 proxy_entry->ongoing =
483 coap_new_client_session_lkd(context, local_addr, &dst, proto);
484#if COAP_OSCORE_SUPPORT
485 }
486#endif /* COAP_OSCORE_SUPPORT */
487 break;
491#if COAP_OSCORE_SUPPORT
492 if (server_use.oscore_conf) {
493 if (server_use.dtls_pki) {
494 server_use.dtls_pki->client_sni = client_sni;
495 proxy_entry->ongoing =
496 coap_new_client_session_oscore_pki_lkd(context, local_addr, &dst,
497 proto, server_use.dtls_pki, server_use.oscore_conf);
498 } else if (server_use.dtls_cpsk) {
499 server_use.dtls_cpsk->client_sni = client_sni;
500 proxy_entry->ongoing =
501 coap_new_client_session_oscore_psk_lkd(context, local_addr, &dst,
502 proto, server_use.dtls_cpsk, server_use.oscore_conf);
503 } else {
504 coap_log_warn("Proxy: (D)TLS not configured for secure session\n");
505 }
506 } else {
507#endif /* COAP_OSCORE_SUPPORT */
508 /* Not doing OSCORE */
509 if (server_use.dtls_pki) {
510 server_use.dtls_pki->client_sni = client_sni;
511 proxy_entry->ongoing =
512 coap_new_client_session_pki_lkd(context, local_addr, &dst,
513 proto, server_use.dtls_pki);
514 } else if (server_use.dtls_cpsk) {
515 server_use.dtls_cpsk->client_sni = client_sni;
516 proxy_entry->ongoing =
517 coap_new_client_session_psk2_lkd(context, local_addr, &dst,
518 proto, server_use.dtls_cpsk);
519 } else {
520 /* Using client anonymous PKI */
521 proxy_entry->ongoing =
522 coap_new_client_session_lkd(context, local_addr, &dst, proto);
523 }
524#if COAP_OSCORE_SUPPORT
525 }
526#endif /* COAP_OSCORE_SUPPORT */
527 break;
531 default:
532 assert(0);
533 break;
534 }
535 if (proxy_entry->ongoing == NULL) {
536 response->code = COAP_RESPONSE_CODE(505);
538 return NULL;
539 }
540 }
541
542 return proxy_entry;
543}
544
545static void
546coap_proxy_release_body_data(coap_session_t *session COAP_UNUSED,
547 void *app_ptr) {
548 coap_delete_binary(app_ptr);
549}
550
551int COAP_API
553 const coap_pdu_t *request,
554 coap_pdu_t *response,
555 coap_resource_t *resource,
556 coap_cache_key_t *cache_key,
557 coap_proxy_server_list_t *server_list) {
558 int ret;
559
560 coap_lock_lock(session->context, return 0);
561 ret = coap_proxy_forward_request_lkd(session,
562 request,
563 response,
564 resource,
565 cache_key,
566 server_list);
567 coap_lock_unlock(session->context);
568 return ret;
569}
570
571int
573 const coap_pdu_t *request,
574 coap_pdu_t *response,
575 coap_resource_t *resource,
576 coap_cache_key_t *cache_key,
577 coap_proxy_server_list_t *server_list) {
578 coap_proxy_list_t *proxy_entry;
579 size_t size;
580 size_t offset;
581 size_t total;
582 coap_binary_t *body_data = NULL;
583 const uint8_t *data;
584 coap_pdu_t *pdu = NULL;
585 coap_bin_const_t r_token = coap_pdu_get_token(request);
586 uint8_t token[8];
587 size_t token_len;
588 coap_proxy_req_t *new_req_list;
589 coap_optlist_t *optlist = NULL;
590 coap_opt_t *option;
591 coap_opt_iterator_t opt_iter;
592 coap_uri_t uri;
593
594 /* Set up ongoing session (if not already done) */
595
596 proxy_entry = coap_proxy_get_ongoing_session(session, request, response,
597 server_list);
598 if (!proxy_entry) {
599 /* Error response code already set */
600 return 0;
601 }
602
603 /* Need to save the request pdu entry */
604 new_req_list = coap_realloc_type(COAP_STRING, proxy_entry->req_list,
605 (proxy_entry->req_count + 1)*sizeof(coap_proxy_req_t));
606
607 if (new_req_list == NULL) {
608 goto failed;
609 }
610 proxy_entry->req_list = new_req_list;
611 /* Get a new token for ongoing session */
612 coap_session_new_token(proxy_entry->ongoing, &token_len, token);
613 new_req_list[proxy_entry->req_count].token_used = coap_new_bin_const(token, token_len);
614 if (new_req_list[proxy_entry->req_count].token_used == NULL) {
615 goto failed;
616 }
617 new_req_list[proxy_entry->req_count].pdu = coap_pdu_duplicate_lkd(request, session,
618 r_token.length, r_token.s, NULL);
619 if (new_req_list[proxy_entry->req_count].pdu == NULL) {
620 coap_delete_bin_const(new_req_list[proxy_entry->req_count].token_used);
621 new_req_list[proxy_entry->req_count].token_used = NULL;
622 goto failed;
623 }
624 new_req_list[proxy_entry->req_count].resource = resource;
625 new_req_list[proxy_entry->req_count].incoming = session;
626 new_req_list[proxy_entry->req_count].cache_key = cache_key;
627 proxy_entry->req_count++;
628
629 switch (server_list->type) {
633 /*
634 * Need to replace Proxy-Uri with Uri-Host (and Uri-Port)
635 * and strip out Proxy-Scheme.
636 */
637
638 /*
639 * Build up the ongoing PDU that we are going to send
640 */
641 pdu = coap_pdu_init(request->type, request->code,
642 coap_new_message_id_lkd(proxy_entry->ongoing),
644 if (!pdu) {
645 goto failed;
646 }
647
648 if (!coap_add_token(pdu, token_len, token)) {
649 goto failed;
650 }
651
652 /* Copy the remaining options across */
653 coap_option_iterator_init(request, &opt_iter, COAP_OPT_ALL);
654 while ((option = coap_option_next(&opt_iter))) {
655 switch (opt_iter.number) {
658 coap_opt_length(option),
659 &uri) < 0) {
660 /* Need to return a 5.05 RFC7252 Section 5.7.2 */
661 coap_log_warn("Proxy URI not decodable\n");
663 return 0;
664 }
665 if (!coap_uri_into_optlist(&uri, NULL, &optlist, 0)) {
666 coap_log_err("Failed to create options for URI\n");
667 goto failed;
668 }
669 break;
671 break;
676 /* These are not passed on */
677 break;
680 break;
681 default:
682 coap_insert_optlist(&optlist,
683 coap_new_optlist(opt_iter.number,
684 coap_opt_length(option),
685 coap_opt_value(option)));
686 break;
687 }
688 }
689
690 /* Update pdu with options */
691 coap_add_optlist_pdu(pdu, &optlist);
692 coap_delete_optlist(optlist);
693 break;
697 default:
698 /*
699 * Duplicate request PDU for onward transmission (with new token).
700 */
701 pdu = coap_pdu_duplicate_lkd(request, proxy_entry->ongoing, token_len, token, NULL);
702 if (!pdu) {
703 coap_log_debug("proxy: PDU generation error\n");
704 goto failed;
705 }
706 break;
707 }
708
709 if (coap_get_data_large(request, &size, &data, &offset, &total)) {
710 /* COAP_BLOCK_SINGLE_BODY is set, so single body should be given */
711 assert(size == total);
712 /*
713 * Need to take a copy of the data as request PDU may go away before
714 * all data is transmitted.
715 */
716 body_data = coap_new_binary(total);
717 if (!body_data) {
718 coap_log_debug("proxy: body build memory error\n");
719 goto failed;
720 }
721 memcpy(body_data->s, data, size);
722 if (!coap_add_data_large_request_lkd(proxy_entry->ongoing, pdu, total, data,
723 coap_proxy_release_body_data, body_data)) {
724 coap_log_debug("proxy: add data error\n");
725 goto failed;
726 }
727 }
728
729 if (coap_send_lkd(proxy_entry->ongoing, pdu) == COAP_INVALID_MID) {
730 pdu = NULL;
731 coap_log_debug("proxy: upstream PDU send error\n");
732 goto failed;
733 }
734
735 /*
736 * Do not update the response code (hence empty ACK) as will be sending
737 * separate response when response comes back from upstream server
738 */
739
740 return 1;
741
742failed:
743 response->code = COAP_RESPONSE_CODE(500);
745 return 0;
746}
747
750 const coap_pdu_t *received,
751 coap_cache_key_t **cache_key) {
752 int ret;
753
754 coap_lock_lock(session->context, return 0);
756 received,
757 cache_key);
758 coap_lock_unlock(session->context);
759 return ret;
760}
761
764 const coap_pdu_t *received,
765 coap_cache_key_t **cache_key) {
766 coap_pdu_t *pdu = NULL;
767 coap_session_t *incoming = NULL;
768 size_t i;
769 size_t j = 0;
770 size_t size;
771 const uint8_t *data;
772 coap_optlist_t *optlist = NULL;
773 coap_opt_t *option;
774 coap_opt_iterator_t opt_iter;
775 size_t offset;
776 size_t total;
777 coap_proxy_list_t *proxy_entry = NULL;
778 uint16_t media_type = COAP_MEDIATYPE_TEXT_PLAIN;
779 int maxage = -1;
780 uint64_t etag = 0;
781 coap_pdu_code_t rcv_code = coap_pdu_get_code(received);
782 coap_bin_const_t rcv_token = coap_pdu_get_token(received);
783 coap_bin_const_t req_token;
784 coap_binary_t *body_data = NULL;
785 coap_pdu_t *req_pdu;
786 coap_proxy_list_t *proxy_list = session->context->proxy_list;
787 size_t proxy_list_count = session->context->proxy_list_count;
788 coap_resource_t *resource;
789 struct coap_proxy_req_t *proxy_req = NULL;
790
791 for (i = 0; i < proxy_list_count; i++) {
792 proxy_entry = &proxy_list[i];
793 for (j = 0; j < proxy_entry->req_count; j++) {
794 if (coap_binary_equal(&rcv_token, proxy_entry->req_list[j].token_used)) {
795 proxy_req = &proxy_entry->req_list[j];
796 break;
797 }
798 }
799 if (j != proxy_entry->req_count) {
800 break;
801 }
802 }
803 if (i == proxy_list_count) {
804 coap_log_warn("Unknown proxy ongoing session response received\n");
805 return COAP_RESPONSE_OK;
806 }
807
808 req_pdu = proxy_req->pdu;
809 req_token = coap_pdu_get_token(req_pdu);
810 resource = proxy_req->resource;
811 incoming = proxy_req->incoming;
812
813 coap_log_debug("** process upstream incoming %d.%02d response:\n",
814 COAP_RESPONSE_CLASS(rcv_code), rcv_code & 0x1F);
815
816 if (coap_get_data_large(received, &size, &data, &offset, &total)) {
817 /* COAP_BLOCK_SINGLE_BODY is set, so single body should be given */
818 assert(size == total);
819 body_data = coap_new_binary(total);
820 if (!body_data) {
821 coap_log_debug("body build memory error\n");
822 goto remove_match;
823 }
824 memcpy(body_data->s, data, size);
825 data = body_data->s;
826 }
827
828 /*
829 * Build up the ongoing PDU that we are going to send to proxy originator
830 * as separate response
831 */
832 pdu = coap_pdu_init(req_pdu->type, rcv_code,
835 if (!pdu) {
836 coap_log_debug("Failed to create ongoing proxy response PDU\n");
837 goto remove_match;
838 }
839
840 if (!coap_add_token(pdu, req_token.length, req_token.s)) {
841 coap_log_debug("cannot add token to ongoing proxy response PDU\n");
842 }
843
844 /*
845 * Copy the options across, skipping those needed for
846 * coap_add_data_response_large()
847 */
848 coap_option_iterator_init(received, &opt_iter, COAP_OPT_ALL);
849 while ((option = coap_option_next(&opt_iter))) {
850 switch (opt_iter.number) {
852 media_type = coap_decode_var_bytes(coap_opt_value(option),
853 coap_opt_length(option));
854 break;
856 maxage = coap_decode_var_bytes(coap_opt_value(option),
857 coap_opt_length(option));
858 break;
859 case COAP_OPTION_ETAG:
861 coap_opt_length(option));
862 break;
866 break;
867 default:
868 coap_insert_optlist(&optlist,
869 coap_new_optlist(opt_iter.number,
870 coap_opt_length(option),
871 coap_opt_value(option)));
872 break;
873 }
874 }
875 coap_add_optlist_pdu(pdu, &optlist);
876 coap_delete_optlist(optlist);
877
878 if (size > 0) {
879 coap_string_t *l_query = coap_get_query(req_pdu);
880
882 l_query,
883 media_type, maxage, etag, size, data,
884 coap_proxy_release_body_data,
885 body_data);
886 body_data = NULL;
887 coap_delete_string(l_query);
888 }
889
890 if (cache_key)
891 *cache_key = proxy_req->cache_key;
892
894
895remove_match:
896 option = coap_check_option(received, COAP_OPTION_OBSERVE, &opt_iter);
897 /* Need to remove matching token entry (apart from an Observe response) */
898 if (option == NULL && proxy_entry->req_count) {
899 coap_delete_pdu_lkd(proxy_entry->req_list[j].pdu);
901 /* Do not delete cache key here - caller's responsibility */
902 proxy_entry->req_count--;
903 if (proxy_entry->req_count-j > 0) {
904 memmove(&proxy_entry->req_list[j], &proxy_entry->req_list[j+1],
905 (proxy_entry->req_count-j) * sizeof(proxy_entry->req_list[0]));
906 }
907 }
908 coap_delete_binary(body_data);
909 return COAP_RESPONSE_OK;
910}
911
912#else /* ! COAP_PROXY_SUPPORT */
913
914int
916 return 0;
917}
918
919COAP_API int
921 const coap_pdu_t *request,
922 coap_pdu_t *response,
925 coap_proxy_server_list_t *server_list) {
926 (void)session;
927 (void)request;
928 (void)resource;
929 (void)cache_key;
930 (void)server_list;
931 response->code = COAP_RESPONSE_CODE(500);
932 return 0;
933}
934
937 const coap_pdu_t *received,
939 (void)session;
940 (void)received;
941 (void)cache_key;
942 return COAP_RESPONSE_OK;
943}
944
945int
947 (void)scheme;
948 return 0;
949}
950#endif /* ! COAP_PROXY_SUPPORT */
int coap_address_set_unix_domain(coap_address_t *addr, const uint8_t *host, size_t host_len)
Copy the parsed unix domain host into coap_address_t structure translating %2F into / on the way.
void coap_free_address_info(coap_addr_info_t *info)
Free off the one or more linked sets of coap_addr_info_t returned from coap_resolve_address_info().
int coap_is_af_unix(const coap_address_t *a)
Checks if given address a denotes a AF_UNIX address.
coap_addr_info_t * coap_resolve_address_info(const coap_str_const_t *address, uint16_t port, uint16_t secure_port, uint16_t ws_port, uint16_t ws_secure_port, int ai_hints_flags, int scheme_hint_bits, coap_resolve_type_t type)
Resolve the specified address into a set of coap_address_t that can be used to bind() (local) or conn...
@ COAP_RESOLVE_TYPE_REMOTE
remote side of session
#define COAP_UNIX_PATH_MAX
Library specific build wrapper for coap_internal.h.
#define COAP_API
@ COAP_STRING
Definition coap_mem.h:39
void * coap_realloc_type(coap_memory_tag_t type, void *p, size_t size)
Reallocates a chunk p of bytes created by coap_malloc_type() or coap_realloc_type() and returns a poi...
void * coap_malloc_type(coap_memory_tag_t type, size_t size)
Allocates a chunk of size bytes and returns a pointer to the newly allocated memory.
void coap_free_type(coap_memory_tag_t type, void *p)
Releases the memory that was allocated by coap_malloc_type().
uint8_t coap_opt_t
Use byte-oriented access methods here because sliding a complex struct coap_opt_t over the data buffe...
Definition coap_option.h:26
coap_uri_scheme_t
The scheme specifiers.
Definition coap_uri.h:28
@ COAP_URI_SCHEME_COAPS_WS
Definition coap_uri.h:36
@ COAP_URI_SCHEME_COAPS_TCP
Definition coap_uri.h:32
@ COAP_URI_SCHEME_COAPS
Definition coap_uri.h:30
@ COAP_URI_SCHEME_COAP_TCP
Definition coap_uri.h:31
@ COAP_URI_SCHEME_COAP_WS
Definition coap_uri.h:35
@ COAP_URI_SCHEME_HTTPS
Definition coap_uri.h:34
@ COAP_URI_SCHEME_COAP
Definition coap_uri.h:29
@ COAP_URI_SCHEME_LAST
Definition coap_uri.h:37
@ COAP_URI_SCHEME_HTTP
Definition coap_uri.h:33
int coap_proxy_check_timeouts(coap_context_t *context, coap_tick_t now, coap_tick_t *tim_rem)
Idle timeout inactive proxy sessions as well as return in tim_rem the time to remaining to timeout th...
coap_response_t coap_proxy_forward_response_lkd(coap_session_t *session, const coap_pdu_t *received, coap_cache_key_t **cache_key)
Forward the returning response back to the appropriate client.
void coap_proxy_cleanup(coap_context_t *context)
Close down proxy tracking, releasing any memory used.
void coap_proxy_remove_association(coap_session_t *session, int send_failure)
int coap_proxy_forward_request_lkd(coap_session_t *session, const coap_pdu_t *request, coap_pdu_t *response, coap_resource_t *resource, coap_cache_key_t *cache_key, coap_proxy_server_list_t *server_list)
Forward incoming request upstream to the next proxy/server.
coap_mid_t coap_send_lkd(coap_session_t *session, coap_pdu_t *pdu)
Sends a CoAP message to given peer.
Definition coap_net.c:1355
int coap_add_data_large_response_lkd(coap_resource_t *resource, coap_session_t *session, const coap_pdu_t *request, coap_pdu_t *response, const coap_string_t *query, uint16_t media_type, int maxage, uint64_t etag, size_t length, const uint8_t *data, coap_release_large_data_t release_func, void *app_ptr)
Associates given data with the response pdu that is passed as fourth parameter.
int coap_add_data_large_request_lkd(coap_session_t *session, coap_pdu_t *pdu, size_t length, const uint8_t *data, coap_release_large_data_t release_func, void *app_ptr)
Associates given data with the pdu that is passed as second parameter.
void coap_delete_cache_key(coap_cache_key_t *cache_key)
Delete the cache-key.
uint64_t coap_tick_t
This data type represents internal timer ticks with COAP_TICKS_PER_SECOND resolution.
Definition coap_time.h:143
#define COAP_TICKS_PER_SECOND
Use ms resolution on POSIX systems.
Definition coap_time.h:158
uint16_t coap_new_message_id_lkd(coap_session_t *session)
Returns a new message id and updates session->tx_mid accordingly.
coap_response_t
Definition coap_net.h:48
void coap_ticks(coap_tick_t *)
Returns the current value of an internal tick counter.
@ COAP_RESPONSE_OK
Response is fine.
Definition coap_net.h:50
unsigned int coap_decode_var_bytes(const uint8_t *buf, size_t len)
Decodes multiple-length byte sequences.
Definition coap_encode.c:38
uint64_t coap_decode_var_bytes8(const uint8_t *buf, size_t len)
Decodes multiple-length byte sequences.
Definition coap_encode.c:67
#define coap_lock_unlock(c)
Dummy for no thread-safe code.
#define coap_lock_lock(c, failed)
Dummy for no thread-safe code.
#define coap_log_debug(...)
Definition coap_debug.h:120
#define coap_log_info(...)
Definition coap_debug.h:108
#define coap_log_warn(...)
Definition coap_debug.h:102
#define coap_log_err(...)
Definition coap_debug.h:96
coap_opt_t * coap_option_next(coap_opt_iterator_t *oi)
Updates the iterator oi to point to the next option.
coap_optlist_t * coap_new_optlist(uint16_t number, size_t length, const uint8_t *data)
Create a new optlist entry.
uint32_t coap_opt_length(const coap_opt_t *opt)
Returns the length of the given option.
coap_opt_iterator_t * coap_option_iterator_init(const coap_pdu_t *pdu, coap_opt_iterator_t *oi, const coap_opt_filter_t *filter)
Initializes the given option iterator oi to point to the beginning of the pdu's option list.
void coap_delete_optlist(coap_optlist_t *queue)
Removes all entries from the optlist_chain, freeing off their memory usage.
#define COAP_OPT_ALL
Pre-defined filter that includes all options.
int coap_add_optlist_pdu(coap_pdu_t *pdu, coap_optlist_t **options)
The current optlist of optlist_chain is first sorted (as per RFC7272 ordering requirements) and then ...
coap_opt_t * coap_check_option(const coap_pdu_t *pdu, coap_option_num_t number, coap_opt_iterator_t *oi)
Retrieves the first option of number number from pdu.
int coap_insert_optlist(coap_optlist_t **head, coap_optlist_t *node)
Adds optlist to the given optlist_chain.
const uint8_t * coap_opt_value(const coap_opt_t *opt)
Returns a pointer to the value of the given option.
coap_session_t * coap_new_client_session_oscore_psk_lkd(coap_context_t *ctx, const coap_address_t *local_if, const coap_address_t *server, coap_proto_t proto, coap_dtls_cpsk_t *psk_data, coap_oscore_conf_t *oscore_conf)
Creates a new client session to the designated server with PSK credentials as well as protecting the ...
coap_session_t * coap_new_client_session_oscore_lkd(coap_context_t *ctx, const coap_address_t *local_if, const coap_address_t *server, coap_proto_t proto, coap_oscore_conf_t *oscore_conf)
Creates a new client session to the designated server, protecting the data using OSCORE.
coap_session_t * coap_new_client_session_oscore_pki_lkd(coap_context_t *ctx, const coap_address_t *local_if, const coap_address_t *server, coap_proto_t proto, coap_dtls_pki_t *pki_data, coap_oscore_conf_t *oscore_conf)
Creates a new client session to the designated server with PKI credentials as well as protecting the ...
void coap_delete_pdu_lkd(coap_pdu_t *pdu)
Dispose of an CoAP PDU and free off associated storage.
Definition coap_pdu.c:190
coap_pdu_t * coap_pdu_duplicate_lkd(const coap_pdu_t *old_pdu, coap_session_t *session, size_t token_length, const uint8_t *token, coap_opt_filter_t *drop_options)
Duplicate an existing PDU.
Definition coap_pdu.c:230
#define COAP_OPTION_URI_HOST
Definition coap_pdu.h:120
coap_pdu_code_t coap_pdu_get_code(const coap_pdu_t *pdu)
Gets the PDU code associated with pdu.
Definition coap_pdu.c:1581
#define COAP_OPTION_BLOCK2
Definition coap_pdu.h:137
#define COAP_OPTION_CONTENT_FORMAT
Definition coap_pdu.h:128
#define COAP_OPTION_SIZE2
Definition coap_pdu.h:139
#define COAP_OPTION_BLOCK1
Definition coap_pdu.h:138
#define COAP_OPTION_Q_BLOCK1
Definition coap_pdu.h:135
#define COAP_OPTION_PROXY_SCHEME
Definition coap_pdu.h:142
#define COAP_DEFAULT_PORT
Definition coap_pdu.h:37
#define COAP_RESPONSE_CODE(N)
Definition coap_pdu.h:160
#define COAP_RESPONSE_CLASS(C)
Definition coap_pdu.h:163
coap_proto_t
CoAP protocol types.
Definition coap_pdu.h:312
coap_pdu_code_t
Set of codes available for a PDU.
Definition coap_pdu.h:326
#define COAP_MEDIATYPE_TEXT_PLAIN
Definition coap_pdu.h:213
int coap_add_token(coap_pdu_t *pdu, size_t len, const uint8_t *data)
Adds token of length len to pdu.
Definition coap_pdu.c:356
#define COAP_OPTION_Q_BLOCK2
Definition coap_pdu.h:140
#define COAPS_DEFAULT_PORT
Definition coap_pdu.h:38
#define COAP_OPTION_URI_PORT
Definition coap_pdu.h:124
coap_pdu_t * coap_pdu_init(coap_pdu_type_t type, coap_pdu_code_t code, coap_mid_t mid, size_t size)
Creates a new CoAP PDU with at least enough storage space for the given size maximum message size.
Definition coap_pdu.c:99
int coap_get_data_large(const coap_pdu_t *pdu, size_t *len, const uint8_t **data, size_t *offset, size_t *total)
Retrieves the data from a PDU, with support for large bodies of data that spans multiple PDUs.
Definition coap_pdu.c:880
#define COAP_INVALID_MID
Indicates an invalid message id.
Definition coap_pdu.h:266
#define COAP_OPTION_MAXAGE
Definition coap_pdu.h:131
#define COAP_OPTION_ETAG
Definition coap_pdu.h:121
#define COAP_OPTION_PROXY_URI
Definition coap_pdu.h:141
#define COAP_OPTION_OBSERVE
Definition coap_pdu.h:123
coap_bin_const_t coap_pdu_get_token(const coap_pdu_t *pdu)
Gets the token associated with pdu.
Definition coap_pdu.c:1605
int coap_verify_proxy_scheme_supported(coap_uri_scheme_t scheme)
Verify that the CoAP Scheme is supported for an ongoing proxy connection.
Definition coap_proxy.c:946
COAP_API coap_response_t coap_proxy_forward_response(coap_session_t *session, const coap_pdu_t *received, coap_cache_key_t **cache_key)
Forward the returning response back to the appropriate client.
Definition coap_proxy.c:936
COAP_API int coap_proxy_forward_request(coap_session_t *session, const coap_pdu_t *request, coap_pdu_t *response, coap_resource_t *resource, coap_cache_key_t *cache_key, coap_proxy_server_list_t *server_list)
Forward incoming request upstream to the next proxy/server.
Definition coap_proxy.c:920
@ COAP_PROXY_REVERSE_STRIP
Act as a reverse proxy, strip out proxy options.
Definition coap_proxy.h:29
@ COAP_PROXY_FORWARD_DYNAMIC
Act as a forward-dynamic proxy using the request's Proxy-Uri or Proxy-Scheme options to determine ser...
Definition coap_proxy.h:34
@ COAP_PROXY_REVERSE
Act as a reverse proxy.
Definition coap_proxy.h:28
@ COAP_PROXY_FORWARD_STATIC
Act as a forward-static proxy.
Definition coap_proxy.h:31
@ COAP_PROXY_FORWARD_DYNAMIC_STRIP
Act as a forward-dynamic proxy, strip out proxy options.
Definition coap_proxy.h:38
@ COAP_PROXY_FORWARD_STATIC_STRIP
Act as a forward-static proxy, strip out proxy options.
Definition coap_proxy.h:32
coap_session_t * coap_new_client_session_psk2_lkd(coap_context_t *ctx, const coap_address_t *local_if, const coap_address_t *server, coap_proto_t proto, coap_dtls_cpsk_t *setup_data)
Creates a new client session to the designated server with PSK credentials.
coap_session_t * coap_new_client_session_pki_lkd(coap_context_t *ctx, const coap_address_t *local_if, const coap_address_t *server, coap_proto_t proto, coap_dtls_pki_t *setup_data)
Creates a new client session to the designated server with PKI credentials.
coap_session_t * coap_new_client_session_lkd(coap_context_t *ctx, const coap_address_t *local_if, const coap_address_t *server, coap_proto_t proto)
Creates a new client session to the designated server.
size_t coap_session_max_pdu_size_lkd(const coap_session_t *session)
Get maximum acceptable PDU size.
void coap_session_release_lkd(coap_session_t *session)
Decrement reference counter on a session.
void coap_session_new_token(coap_session_t *session, size_t *len, uint8_t *data)
Creates a new token for use.
void coap_delete_bin_const(coap_bin_const_t *s)
Deletes the given const binary data and releases any memory allocated.
Definition coap_str.c:120
coap_binary_t * coap_new_binary(size_t size)
Returns a new binary object with at least size bytes storage allocated.
Definition coap_str.c:77
coap_bin_const_t * coap_new_bin_const(const uint8_t *data, size_t size)
Take the specified byte array (text) and create a coap_bin_const_t * Returns a new const binary objec...
Definition coap_str.c:110
void coap_delete_binary(coap_binary_t *s)
Deletes the given coap_binary_t object and releases any memory allocated.
Definition coap_str.c:105
#define coap_binary_equal(binary1, binary2)
Compares the two binary data for equality.
Definition coap_str.h:211
#define coap_string_equal(string1, string2)
Compares the two strings for equality.
Definition coap_str.h:197
void coap_delete_string(coap_string_t *s)
Deletes the given string and releases any memory allocated.
Definition coap_str.c:46
int coap_tcp_is_supported(void)
Check whether TCP is available.
Definition coap_tcp.c:20
int coap_tls_is_supported(void)
Check whether TLS is available.
Definition coap_notls.c:41
int coap_ws_is_supported(void)
Check whether WebSockets is available.
Definition coap_ws.c:933
int coap_dtls_is_supported(void)
Check whether DTLS is available.
Definition coap_notls.c:36
int coap_proxy_is_supported(void)
Check whether Proxy code is available.
Definition coap_proxy.c:915
int coap_wss_is_supported(void)
Check whether Secure WebSockets is available.
Definition coap_ws.c:938
int coap_split_proxy_uri(const uint8_t *str_var, size_t len, coap_uri_t *uri)
Parses a given string into URI components.
Definition coap_uri.c:281
int coap_uri_into_optlist(const coap_uri_t *uri, const coap_address_t *dst, coap_optlist_t **optlist_chain, int create_port_host_opt)
Takes a coap_uri_t and then adds CoAP options into the optlist_chain.
Definition coap_uri.c:304
coap_string_t * coap_get_query(const coap_pdu_t *request)
Extract query string from request PDU according to escape rules in 6.5.8.
Definition coap_uri.c:939
#define COAP_UNUSED
Definition libcoap.h:70
Resolved addresses information.
coap_proto_t proto
CoAP protocol to use.
coap_address_t addr
The address to connect / bind to.
Multi-purpose address abstraction.
CoAP binary data definition with const data.
Definition coap_str.h:64
size_t length
length of binary data
Definition coap_str.h:65
const uint8_t * s
read-only binary data
Definition coap_str.h:66
CoAP binary data definition.
Definition coap_str.h:56
uint8_t * s
binary data
Definition coap_str.h:58
The CoAP stack's global state is stored in a coap_context_t object.
char * client_sni
If not NULL, SNI to use in client TLS setup.
Definition coap_dtls.h:437
char * client_sni
If not NULL, SNI to use in client TLS setup.
Definition coap_dtls.h:368
Iterator to run through PDU options.
coap_option_num_t number
decoded option number
Representation of chained list of CoAP options to install.
structure for CoAP PDUs
coap_pdu_code_t code
request method (value 1–31) or response code (value 64-255)
coap_pdu_type_t type
message type
coap_tick_t idle_timeout_ticks
Idle timeout (0 == no timeout)
coap_session_t * incoming
Incoming session (used if client tracking(.
uint8_t * uri_host_keep
memory for uri.host
coap_proxy_req_t * req_list
Incoming list of request info.
coap_tick_t last_used
Last time entry was used.
coap_uri_t uri
URI info for connection.
coap_session_t * ongoing
Ongoing session.
size_t req_count
Count of incoming request info.
coap_bin_const_t * token_used
coap_cache_key_t * cache_key
coap_session_t * incoming
coap_resource_t * resource
int track_client_session
If 1, track individual connections to upstream server, else 0 for all clients to share the same ongoi...
Definition coap_proxy.h:59
coap_proxy_server_t * entry
Set of servers to connect to.
Definition coap_proxy.h:55
coap_proxy_t type
The proxy type.
Definition coap_proxy.h:58
unsigned int idle_timeout_secs
Proxy upstream session idle timeout (0 is no timeout)
Definition coap_proxy.h:62
size_t next_entry
Next server to use (% entry_count)
Definition coap_proxy.h:57
size_t entry_count
The number of servers in entry list.
Definition coap_proxy.h:56
coap_dtls_pki_t * dtls_pki
PKI configuration to use if not NULL.
Definition coap_proxy.h:49
coap_oscore_conf_t * oscore_conf
OSCORE configuration if not NULL.
Definition coap_proxy.h:51
coap_uri_t uri
host and port define the server, scheme method
Definition coap_proxy.h:48
coap_dtls_cpsk_t * dtls_cpsk
PSK configuration to use if not NULL.
Definition coap_proxy.h:50
Abstraction of resource that can be attached to coap_context_t.
Abstraction of virtual session that can be attached to coap_context_t (client) or coap_endpoint_t (se...
coap_context_t * context
session's context
const uint8_t * s
read-only string data
Definition coap_str.h:48
size_t length
length of string
Definition coap_str.h:47
CoAP string data definition.
Definition coap_str.h:38
Representation of parsed URI.
Definition coap_uri.h:68
enum coap_uri_scheme_t scheme
The parsed scheme specifier.
Definition coap_uri.h:80
coap_str_const_t path
The complete path if present or {0, NULL}.
Definition coap_uri.h:71
uint16_t port
The port in host byte order.
Definition coap_uri.h:70
coap_str_const_t query
The complete query if present or {0, NULL}.
Definition coap_uri.h:75
coap_str_const_t host
The host part of the URI.
Definition coap_uri.h:69