+static struct xtables_match *prepare_matches(struct connman_iptables *table,
+ char *match_name)
+{
+ struct xtables_match *xt_m;
+ size_t match_size;
+
+ if (match_name == NULL)
+ return NULL;
+
+ xt_m = xtables_find_match(match_name, XTF_LOAD_MUST_SUCCEED, NULL);
+ match_size = ALIGN(sizeof(struct ipt_entry_match)) + xt_m->size;
+
+ xt_m->m = g_try_malloc0(match_size);
+ if (xt_m->m == NULL)
+ return NULL;
+
+ xt_m->m->u.match_size = match_size;
+ strcpy(xt_m->m->u.user.name, xt_m->name);
+ xt_m->m->u.user.revision = xt_m->revision;
+
+ if (xt_m->init != NULL)
+ xt_m->init(xt_m->m);
+
+ if (xt_m != xt_m->next) {
+ connman_iptables_globals.opts =
+ xtables_merge_options(
+#if XTABLES_VERSION_CODE > 5
+ connman_iptables_globals.orig_opts,
+#endif
+ connman_iptables_globals.opts,
+ xt_m->extra_opts,
+ &xt_m->option_offset);
+
+ if (connman_iptables_globals.opts == NULL) {
+ g_free(xt_m->m);
+ xt_m = NULL;
+ }
+ }
+
+ return xt_m;
+}
+