| 1050 | } |
| 1051 | |
| 1052 | static struct tcp_fastopen_ccache_entry * |
| 1053 | tcp_fastopen_ccache_create(struct tcp_fastopen_ccache_bucket *ccb, |
| 1054 | struct in_conninfo *inc, uint16_t mss, uint8_t cookie_len, uint8_t *cookie) |
| 1055 | { |
| 1056 | struct tcp_fastopen_ccache_entry *cce; |
| 1057 | |
| 1058 | /* |
| 1059 | * 1. Create a new entry, or |
| 1060 | * 2. Reclaim an existing entry, or |
| 1061 | * 3. Fail |
| 1062 | */ |
| 1063 | |
| 1064 | CCB_LOCK_ASSERT(ccb); |
| 1065 | |
| 1066 | cce = NULL; |
| 1067 | if (ccb->ccb_num_entries < V_tcp_fastopen_ccache.bucket_limit) |
| 1068 | cce = uma_zalloc(V_tcp_fastopen_ccache.zone, M_NOWAIT); |
| 1069 | |
| 1070 | if (cce == NULL) { |
| 1071 | /* |
| 1072 | * At bucket limit, or out of memory - reclaim last |
| 1073 | * entry in bucket. |
| 1074 | */ |
| 1075 | cce = TAILQ_LAST(&ccb->ccb_entries, bucket_entries); |
| 1076 | if (cce == NULL) { |
| 1077 | /* XXX count this event */ |
| 1078 | return (NULL); |
| 1079 | } |
| 1080 | |
| 1081 | TAILQ_REMOVE(&ccb->ccb_entries, cce, cce_link); |
| 1082 | } else |
| 1083 | ccb->ccb_num_entries++; |
| 1084 | |
| 1085 | TAILQ_INSERT_HEAD(&ccb->ccb_entries, cce, cce_link); |
| 1086 | cce->af = (inc->inc_flags & INC_ISIPV6) ? AF_INET6 : AF_INET; |
| 1087 | if (cce->af == AF_INET) { |
| 1088 | cce->cce_client_ip.v4 = inc->inc_laddr; |
| 1089 | cce->cce_server_ip.v4 = inc->inc_faddr; |
| 1090 | } else { |
| 1091 | cce->cce_client_ip.v6 = inc->inc6_laddr; |
| 1092 | cce->cce_server_ip.v6 = inc->inc6_faddr; |
| 1093 | } |
| 1094 | cce->server_port = inc->inc_fport; |
| 1095 | if ((cookie_len >= TCP_FASTOPEN_MIN_COOKIE_LEN) && |
| 1096 | (cookie_len <= TCP_FASTOPEN_MAX_COOKIE_LEN) && |
| 1097 | ((cookie_len & 0x1) == 0)) { |
| 1098 | cce->server_mss = mss; |
| 1099 | cce->cookie_len = cookie_len; |
| 1100 | memcpy(cce->cookie, cookie, cookie_len); |
| 1101 | cce->disable_time = 0; |
| 1102 | } else { |
| 1103 | /* invalid cookie length, disable cce */ |
| 1104 | cce->server_mss = 0; |
| 1105 | cce->cookie_len = 0; |
| 1106 | cce->disable_time = getsbinuptime(); |
| 1107 | } |
| 1108 | |
| 1109 | return (cce); |
no test coverage detected