+flow_divert_find_proc_by_uuid_callout(proc_t p, void *arg)
+{
+ struct uuid_search_info *info = (struct uuid_search_info *)arg;
+ int result = PROC_RETURNED_DONE; /* By default, we didn't find the process */
+
+ if (info->found_signing_id != NULL) {
+ if (!info->found_multiple_signing_ids) {
+ /* All processes that were found had the same signing identifier, so just claim this first one and be done. */
+ info->found_proc = p;
+ result = PROC_CLAIMED_DONE;
+ } else {
+ uuid_string_t uuid_str;
+ uuid_unparse(info->target_uuid, uuid_str);
+ FDLOG(LOG_WARNING, &nil_pcb, "Found multiple processes with UUID %s with different signing identifiers", uuid_str);
+ }
+ FREE(info->found_signing_id, M_TEMP);
+ info->found_signing_id = NULL;
+ }
+
+ if (result == PROC_RETURNED_DONE) {
+ uuid_string_t uuid_str;
+ uuid_unparse(info->target_uuid, uuid_str);
+ FDLOG(LOG_WARNING, &nil_pcb, "Failed to find a process with UUID %s", uuid_str);
+ }
+
+ return result;
+}
+
+static int
+flow_divert_find_proc_by_uuid_filter(proc_t p, void *arg)
+{
+ struct uuid_search_info *info = (struct uuid_search_info *)arg;
+ int include = 0;
+
+ if (info->found_multiple_signing_ids) {
+ return include;
+ }
+
+ include = (uuid_compare(p->p_uuid, info->target_uuid) == 0);
+ if (include) {
+ const char *signing_id = cs_identity_get(p);
+ if (signing_id != NULL) {
+ FDLOG(LOG_INFO, &nil_pcb, "Found process %d with signing identifier %s", p->p_pid, signing_id);
+ size_t signing_id_size = strlen(signing_id) + 1;
+ if (info->found_signing_id == NULL) {
+ MALLOC(info->found_signing_id, char *, signing_id_size, M_TEMP, M_WAITOK);
+ memcpy(info->found_signing_id, signing_id, signing_id_size);
+ } else if (memcmp(signing_id, info->found_signing_id, signing_id_size)) {
+ info->found_multiple_signing_ids = TRUE;
+ }
+ } else {
+ info->found_multiple_signing_ids = TRUE;
+ }
+ include = !info->found_multiple_signing_ids;
+ }
+
+ return include;
+}
+
+static proc_t
+flow_divert_find_proc_by_uuid(uuid_t uuid)
+{
+ struct uuid_search_info info;
+
+ if (LOG_INFO <= nil_pcb.log_level) {
+ uuid_string_t uuid_str;
+ uuid_unparse(uuid, uuid_str);
+ FDLOG(LOG_INFO, &nil_pcb, "Looking for process with UUID %s", uuid_str);
+ }
+
+ memset(&info, 0, sizeof(info));
+ info.found_proc = PROC_NULL;
+ uuid_copy(info.target_uuid, uuid);
+
+ proc_iterate(PROC_ALLPROCLIST, flow_divert_find_proc_by_uuid_callout, &info, flow_divert_find_proc_by_uuid_filter, &info);
+
+ return info.found_proc;
+}
+
+static int
+flow_divert_get_src_proc(struct socket *so, proc_t *proc)