63b4e9
diff --git a/config.c b/config.c
63b4e9
index b5cf397..747a735 100644
63b4e9
--- a/config.c
63b4e9
+++ b/config.c
63b4e9
@@ -451,8 +451,8 @@ static int config_switch_unicast_mtab(struct config *cfg, int idx, int line_num)
63b4e9
 	return 0;
63b4e9
 }
63b4e9
 
63b4e9
-static int config_unicast_mtab_address(enum transport_type type, char *address,
63b4e9
-				       int line_num)
63b4e9
+static int config_unicast_mtab_address_prio(enum transport_type type, char *address,
63b4e9
+				       int line_num, unsigned char prio)
63b4e9
 {
63b4e9
 	struct unicast_master_address *item;
63b4e9
 
63b4e9
@@ -472,6 +472,7 @@ static int config_unicast_mtab_address(enum transport_type type, char *address,
63b4e9
 	}
63b4e9
 	memset(&item->portIdentity, 0xff, sizeof(item->portIdentity));
63b4e9
 	item->type = type;
63b4e9
+	item->localPriority = prio;
63b4e9
 	STAILQ_INSERT_TAIL(&current_uc_mtab->addrs, item, list);
63b4e9
 	current_uc_mtab->count++;
63b4e9
 
63b4e9
@@ -662,7 +663,7 @@ static int parse_unicast_mtab_line(struct config *cfg, char *line, int line_num)
63b4e9
 	char address[64 + 1] = {0}, transport[16 + 1] = {0};
63b4e9
 	enum transport_type type = TRANS_UDS;
63b4e9
 	struct config_enum *cte;
63b4e9
-	int cnt, lqi, table_id;
63b4e9
+	int cnt, lqi, table_id, prio;
63b4e9
 
63b4e9
 	cnt = sscanf(line, " table_id %d", &table_id);
63b4e9
 	if (cnt == 1) {
63b4e9
@@ -676,18 +677,27 @@ static int parse_unicast_mtab_line(struct config *cfg, char *line, int line_num)
63b4e9
 	if (cnt == 1) {
63b4e9
 		return config_unicast_mtab_peer(address, line_num);
63b4e9
 	}
63b4e9
-	cnt = sscanf(line, " %16s %64s", transport, address);
63b4e9
-	if (cnt != 2) {
63b4e9
+	cnt = sscanf(line, " %16s %64s %d", transport, address, &prio;;
63b4e9
+	if (cnt < 2) {
63b4e9
 		fprintf(stderr, "bad master table at line %d\n", line_num);
63b4e9
 		return -1;
63b4e9
 	}
63b4e9
+	if (cnt == 3 && (prio < 0 || prio > 255)) {
63b4e9
+		fprintf(stderr, "bad address priority(%d) at line %d\n", prio, line_num);
63b4e9
+		prio = 0;
63b4e9
+	}
63b4e9
+	if (cnt == 2) {
63b4e9
+		fprintf(stderr, "address priority is not parsed at line %d\n", line_num);
63b4e9
+		prio = 0;
63b4e9
+	}
63b4e9
+
63b4e9
 	for (cte = nw_trans_enu; cte->label; cte++) {
63b4e9
 		if (!strcasecmp(cte->label, transport)) {
63b4e9
 			type = cte->value;
63b4e9
 			break;
63b4e9
 		}
63b4e9
 	}
63b4e9
-	return config_unicast_mtab_address(type, address, line_num);
63b4e9
+	return config_unicast_mtab_address_prio(type, address, line_num, prio);
63b4e9
 }
63b4e9
 
63b4e9
 static enum parser_result parse_setting_line(char *line,
63b4e9
diff --git a/mtab.h b/mtab.h
63b4e9
index 949929f..412bcc9 100644
63b4e9
--- a/mtab.h
63b4e9
+++ b/mtab.h
63b4e9
@@ -37,6 +37,7 @@ struct unicast_master_address {
63b4e9
 	unsigned int granted;
63b4e9
 	unsigned int sydymsk;
63b4e9
 	time_t renewal_tmo;
63b4e9
+	unsigned char localPriority;
63b4e9
 };
63b4e9
 
63b4e9
 struct unicast_master_table {
63b4e9
diff --git a/port.c b/port.c
63b4e9
index c3a06c8..eaf77e6 100644
63b4e9
--- a/port.c
63b4e9
+++ b/port.c
63b4e9
@@ -80,7 +80,8 @@ static void announce_to_dataset(struct ptp_message *m, struct port *p,
63b4e9
 	out->identity     = a->grandmasterIdentity;
63b4e9
 	out->quality      = a->grandmasterClockQuality;
63b4e9
 	out->priority2    = a->grandmasterPriority2;
63b4e9
-	out->localPriority = p->localPriority;
63b4e9
+	if (!out->localPriority)
63b4e9
+		out->localPriority = p->localPriority;
63b4e9
 	out->stepsRemoved = a->stepsRemoved;
63b4e9
 	out->sender       = m->header.sourcePortIdentity;
63b4e9
 	out->receiver     = p->portIdentity;
63b4e9
@@ -405,6 +406,9 @@ static int add_foreign_master(struct port *p, struct ptp_message *m)
63b4e9
 		LIST_INSERT_HEAD(&p->foreign_masters, fc, list);
63b4e9
 		fc->port = p;
63b4e9
 		fc->dataset.sender = m->header.sourcePortIdentity;
63b4e9
+		fc->dataset.localPriority = unicast_client_get_priority(p, m);
63b4e9
+		pr_notice("%s: new foreign master %s with prio %d", p->log_name,
63b4e9
+			pid2str(&fc->dataset.sender), fc->dataset.localPriority);
63b4e9
 		/* We do not count this first message, see 9.5.3(b) */
63b4e9
 		return 0;
63b4e9
 	}
63b4e9
diff --git a/unicast_client.c b/unicast_client.c
63b4e9
index 5bb383f..71dd18e 100644
63b4e9
--- a/unicast_client.c
63b4e9
+++ b/unicast_client.c
63b4e9
@@ -619,3 +619,14 @@ out:
63b4e9
 	msg_put(msg);
63b4e9
 	return err;
63b4e9
 }
63b4e9
+
63b4e9
+unsigned char unicast_client_get_priority(struct port *p, struct ptp_message *m)
63b4e9
+{
63b4e9
+	struct unicast_master_address *ucma;
63b4e9
+
63b4e9
+	ucma = unicast_client_ok(p, m);
63b4e9
+	if (!ucma) {
63b4e9
+		return 0;
63b4e9
+	}
63b4e9
+	return p->localPriority + ucma->localPriority;
63b4e9
+}
63b4e9
diff --git a/unicast_client.h b/unicast_client.h
63b4e9
index 18a12c8..9d21a8a 100644
63b4e9
--- a/unicast_client.h
63b4e9
+++ b/unicast_client.h
63b4e9
@@ -90,7 +90,7 @@ int unicast_client_timer(struct port *p);
63b4e9
  * @return       One (1) if the message is from an entry in the unicast
63b4e9
  *               master table, or zero otherwise.
63b4e9
  */
63b4e9
-int unicast_client_msg_is_from_master_table_entry(struct port *p, 
63b4e9
+int unicast_client_msg_is_from_master_table_entry(struct port *p,
63b4e9
 						  struct ptp_message *m);
63b4e9
 
63b4e9
 /**
63b4e9
@@ -101,4 +101,12 @@ int unicast_client_msg_is_from_master_table_entry(struct port *p,
63b4e9
  */
63b4e9
 int unicast_client_tx_cancel(struct port *p,
63b4e9
 			     struct unicast_master_address *dst);
63b4e9
+
63b4e9
+/**
63b4e9
+ * Return local priority configured for unicast client
63b4e9
+ * @param p      The port on which the signaling message was received.
63b4e9
+ * @param m      The signaling message containing the announce.
63b4e9
+ * @return		 Unicast client local priority if configured otherwise zero.
63b4e9
+ */
63b4e9
+unsigned char unicast_client_get_priority(struct port *p, struct ptp_message *m);
63b4e9
 #endif